aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-09-27 14:14:51 +0000
committervda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-09-27 14:14:51 +0000
commit093e184365e9e352bb08038450499cc14de7a492 (patch)
tree947a71112272e8254f38aa534eee6d1bece0f2db
parent1da94fe670ac0195845f70edc67b7f7493442d7f (diff)
downloadbusybox-w32-093e184365e9e352bb08038450499cc14de7a492.tar.gz
busybox-w32-093e184365e9e352bb08038450499cc14de7a492.tar.bz2
busybox-w32-093e184365e9e352bb08038450499cc14de7a492.zip
ifupdown: fix for standalone shell; removed hardcoded PATH
git-svn-id: svn://busybox.net/trunk/busybox@16232 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r--networking/ifupdown.c64
1 files changed, 23 insertions, 41 deletions
diff --git a/networking/ifupdown.c b/networking/ifupdown.c
index 9841b5903..99b1c59d9 100644
--- a/networking/ifupdown.c
+++ b/networking/ifupdown.c
@@ -106,6 +106,8 @@ enum {
106 106
107static char **__myenviron; 107static char **__myenviron;
108 108
109static char *startup_PATH;
110
109#if ENABLE_FEATURE_IFUPDOWN_IPV4 || ENABLE_FEATURE_IFUPDOWN_IPV6 111#if ENABLE_FEATURE_IFUPDOWN_IPV4 || ENABLE_FEATURE_IFUPDOWN_IPV6
110 112
111#ifdef CONFIG_FEATURE_IFUPDOWN_IP 113#ifdef CONFIG_FEATURE_IFUPDOWN_IP
@@ -448,50 +450,29 @@ static int static_down(struct interface_defn_t *ifd, execfn *exec)
448 return ((result == 2) ? 2 : 0); 450 return ((result == 2) ? 2 : 0);
449} 451}
450 452
451static int execable(char *program)
452{
453 struct stat buf;
454 if (0 == stat(program, &buf)) {
455 if (S_ISREG(buf.st_mode) && (S_IXUSR & buf.st_mode)) {
456 return(1);
457 }
458 }
459 return(0);
460}
461
462static int dhcp_up(struct interface_defn_t *ifd, execfn *exec) 453static int dhcp_up(struct interface_defn_t *ifd, execfn *exec)
463{ 454{
464 if (execable("/sbin/udhcpc")) { 455 if (execute("udhcpc -n -p /var/run/udhcpc.%iface%.pid -i "
465 return( execute("udhcpc -n -p /var/run/udhcpc.%iface%.pid -i " 456 "%iface% [[-H %hostname%]] [[-c %clientid%]]", ifd, exec)) return 1;
466 "%iface% [[-H %hostname%]] [[-c %clientid%]]", ifd, exec)); 457 if (execute("pump -i %iface% [[-h %hostname%]] [[-l %leasehours%]]", ifd, exec)) return 1;
467 } else if (execable("/sbin/pump")) { 458 if (execute("dhclient -pf /var/run/dhclient.%iface%.pid %iface%", ifd, exec)) return 1;
468 return( execute("pump -i %iface% [[-h %hostname%]] [[-l %leasehours%]]", ifd, exec)); 459 if (execute("dhcpcd [[-h %hostname%]] [[-i %vendor%]] [[-I %clientid%]] "
469 } else if (execable("/sbin/dhclient")) { 460 "[[-l %leasetime%]] %iface%", ifd, exec)) return 1;
470 return( execute("dhclient -pf /var/run/dhclient.%iface%.pid %iface%", ifd, exec)); 461 return 0;
471 } else if (execable("/sbin/dhcpcd")) {
472 return( execute("dhcpcd [[-h %hostname%]] [[-i %vendor%]] [[-I %clientid%]] "
473 "[[-l %leasetime%]] %iface%", ifd, exec));
474 }
475 return(0);
476} 462}
477 463
478static int dhcp_down(struct interface_defn_t *ifd, execfn *exec) 464static int dhcp_down(struct interface_defn_t *ifd, execfn *exec)
479{ 465{
480 int result = 0; 466 /* SIGUSR2 forces udhcpc to release the current lease and go inactive,
481 if (execable("/sbin/udhcpc")) { 467 * and SIGTERM causes udhcpc to exit. Signals are queued and processed
482 /* SIGUSR2 forces udhcpc to release the current lease and go inactive, 468 * sequentially so we don't need to sleep */
483 * and SIGTERM causes udhcpc to exit. Signals are queued and processed 469 if (execute("kill -USR2 `cat /var/run/udhcpc.%iface%.pid` 2>/dev/null", ifd, exec)
484 * sequentially so we don't need to sleep */ 470 || execute("kill -TERM `cat /var/run/udhcpc.%iface%.pid` 2>/dev/null", ifd, exec))
485 result = execute("kill -USR2 `cat /var/run/udhcpc.%iface%.pid` 2>/dev/null", ifd, exec); 471 return 1;
486 result += execute("kill -TERM `cat /var/run/udhcpc.%iface%.pid` 2>/dev/null", ifd, exec); 472 if (execute("pump -i %iface% -k", ifd, exec)) return 1;
487 } else if (execable("/sbin/pump")) { 473 if (execute("kill -9 `cat /var/run/dhclient.%iface%.pid` 2>/dev/null", ifd, exec)) return 1;
488 result = execute("pump -i %iface% -k", ifd, exec); 474 if (execute("dhcpcd -k %iface%", ifd, exec)) return 1;
489 } else if (execable("/sbin/dhclient")) { 475 return static_down(ifd, exec);
490 result = execute("kill -9 `cat /var/run/dhclient.%iface%.pid` 2>/dev/null", ifd, exec);
491 } else if (execable("/sbin/dhcpcd")) {
492 result = execute("dhcpcd -k %iface%", ifd, exec);
493 }
494 return (result || static_down(ifd, exec));
495} 476}
496 477
497static int bootp_up(struct interface_defn_t *ifd, execfn *exec) 478static int bootp_up(struct interface_defn_t *ifd, execfn *exec)
@@ -875,9 +856,7 @@ static void set_environ(struct interface_defn_t *iface, const char *mode)
875 *(environend++) = setlocalenv("%s=%s", "ADDRFAM", iface->address_family->name); 856 *(environend++) = setlocalenv("%s=%s", "ADDRFAM", iface->address_family->name);
876 *(environend++) = setlocalenv("%s=%s", "METHOD", iface->method->name); 857 *(environend++) = setlocalenv("%s=%s", "METHOD", iface->method->name);
877 *(environend++) = setlocalenv("%s=%s", "MODE", mode); 858 *(environend++) = setlocalenv("%s=%s", "MODE", mode);
878 /* FIXME: we must not impose our own PATH, it is admin's job! 859 *(environend++) = setlocalenv("%s=%s", "PATH", startup_PATH);
879 Use PATH from parent env */
880 *(environend++) = setlocalenv("%s=%s", "PATH", "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin");
881} 860}
882 861
883static int doit(char *str) 862static int doit(char *str)
@@ -1103,6 +1082,9 @@ int ifupdown_main(int argc, char **argv)
1103 exit(EXIT_FAILURE); 1082 exit(EXIT_FAILURE);
1104 } 1083 }
1105 1084
1085 startup_PATH = getenv("PATH");
1086 if (!startup_PATH) startup_PATH = "";
1087
1106 /* Create a list of interfaces to work on */ 1088 /* Create a list of interfaces to work on */
1107 if (DO_ALL) { 1089 if (DO_ALL) {
1108 if (cmds == iface_up) { 1090 if (cmds == iface_up) {