diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-09-27 14:14:51 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-09-27 14:14:51 +0000 |
commit | 2f4399c6cc966d39ba74fc4727a0493b3b52ffd8 (patch) | |
tree | 947a71112272e8254f38aa534eee6d1bece0f2db | |
parent | 0534125ccc727ce3e44ea10619f8c4ab1f1a96d8 (diff) | |
download | busybox-w32-2f4399c6cc966d39ba74fc4727a0493b3b52ffd8.tar.gz busybox-w32-2f4399c6cc966d39ba74fc4727a0493b3b52ffd8.tar.bz2 busybox-w32-2f4399c6cc966d39ba74fc4727a0493b3b52ffd8.zip |
ifupdown: fix for standalone shell; removed hardcoded PATH
-rw-r--r-- | networking/ifupdown.c | 64 |
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 | ||
107 | static char **__myenviron; | 107 | static char **__myenviron; |
108 | 108 | ||
109 | static 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 | ||
451 | static 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 | |||
462 | static int dhcp_up(struct interface_defn_t *ifd, execfn *exec) | 453 | static 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 | ||
478 | static int dhcp_down(struct interface_defn_t *ifd, execfn *exec) | 464 | static 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 | ||
497 | static int bootp_up(struct interface_defn_t *ifd, execfn *exec) | 478 | static 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 | ||
883 | static int doit(char *str) | 862 | static 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) { |