nc: show help text on bad parameters
[oweals/busybox.git] / networking / ifupdown.c
index b16186ec728b2edc121afb7e2369af83142d7dea..864fc2acd0da48e09ede3d0e98f68e26d039cc09 100644 (file)
@@ -14,7 +14,7 @@
  *  (defined via CONFIG_IFUPDOWN_IFSTATE_PATH) and can be overridden by build
  *  configuration.
  *
- * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
+ * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  */
 
 #include "libbb.h"
@@ -106,7 +106,7 @@ enum {
 struct globals {
        char **my_environ;
        const char *startup_PATH;
-};
+} FIX_ALIASING;
 #define G (*(struct globals*)&bb_common_bufsiz1)
 #define INIT_G() do { } while (0)
 
@@ -483,7 +483,7 @@ struct dhcp_client_t {
 
 static const struct dhcp_client_t ext_dhcp_clients[] = {
        { "dhcpcd",
-               "dhcpcd[[ -h %hostname%]][[ -i %vendor%]][[ -I %clientid%]][[ -l %leasetime%]] %iface%",
+               "dhcpcd[[ -h %hostname%]][[ -i %vendor%]][[ -I %client%]][[ -l %leasetime%]] %iface%",
                "dhcpcd -k %iface%",
        },
        { "dhclient",
@@ -495,7 +495,7 @@ static const struct dhcp_client_t ext_dhcp_clients[] = {
                "pump -i %iface% -k",
        },
        { "udhcpc",
-               "udhcpc " UDHCPC_CMD_OPTIONS " -p /var/run/udhcpc.%iface%.pid -i %iface%[[ -H %hostname%]][[ -c %clientid%]]"
+               "udhcpc " UDHCPC_CMD_OPTIONS " -p /var/run/udhcpc.%iface%.pid -i %iface%[[ -H %hostname%]][[ -c %client%]]"
                                "[[ -s %script%]][[ %udhcpc_opts%]]",
                "kill `cat /var/run/udhcpc.%iface%.pid` 2>/dev/null",
        },
@@ -522,7 +522,7 @@ static int FAST_FUNC dhcp_up(struct interface_defn_t *ifd, execfn *exec)
        bb_error_msg("no dhcp clients found");
        return 0;
 }
-#elif ENABLE_APP_UDHCPC
+#elif ENABLE_UDHCPC
 static int FAST_FUNC dhcp_up(struct interface_defn_t *ifd, execfn *exec)
 {
 #if ENABLE_FEATURE_IFUPDOWN_IP
@@ -535,7 +535,7 @@ static int FAST_FUNC dhcp_up(struct interface_defn_t *ifd, execfn *exec)
                return 0;
 #endif
        return execute("udhcpc " UDHCPC_CMD_OPTIONS " -p /var/run/udhcpc.%iface%.pid "
-                       "-i %iface%[[ -H %hostname%]][[ -c %clientid%]][[ -s %script%]][[ %udhcpc_opts%]]",
+                       "-i %iface%[[ -H %hostname%]][[ -c %client%]][[ -s %script%]][[ %udhcpc_opts%]]",
                        ifd, exec);
 }
 #else
@@ -569,12 +569,14 @@ static int FAST_FUNC dhcp_down(struct interface_defn_t *ifd, execfn *exec)
        result += static_down(ifd, exec);
        return ((result == 3) ? 3 : 0);
 }
-#elif ENABLE_APP_UDHCPC
+#elif ENABLE_UDHCPC
 static int FAST_FUNC dhcp_down(struct interface_defn_t *ifd, execfn *exec)
 {
        int result;
-       result = execute("kill "
-                      "`cat /var/run/udhcpc.%iface%.pid` 2>/dev/null", ifd, exec);
+       result = execute(
+               "test -f /var/run/udhcpc.%iface%.pid && "
+               "kill `cat /var/run/udhcpc.%iface%.pid` 2>/dev/null",
+               ifd, exec);
        /* Also bring the hardware interface down since
           killing the dhcp client alone doesn't do it.
           This enables consecutive ifup->ifdown->ifup */
@@ -1039,19 +1041,16 @@ static int popen2(FILE **in, FILE **out, char *command, char *param)
        xpiped_pair(outfd);
 
        fflush_all();
-       pid = vfork();
+       pid = xvfork();
 
-       switch (pid) {
-       case -1:  /* failure */
-               bb_perror_msg_and_die("vfork");
-       case 0:  /* child */
+       if (pid == 0) {
+               /* Child */
                /* NB: close _first_, then move fds! */
                close(infd.wr);
                close(outfd.rd);
                xmove_fd(infd.rd, 0);
                xmove_fd(outfd.wr, 1);
-               BB_EXECVP(command, argv);
-               _exit(127);
+               BB_EXECVP_or_die(argv);
        }
        /* parent */
        close(infd.rd);
@@ -1142,7 +1141,7 @@ static llist_t *read_iface_state(void)
 
 
 int ifupdown_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
-int ifupdown_main(int argc, char **argv)
+int ifupdown_main(int argc UNUSED_PARAM, char **argv)
 {
        int (*cmds)(struct interface_defn_t *);
        struct interfaces_file_t *defn;
@@ -1161,7 +1160,8 @@ int ifupdown_main(int argc, char **argv)
        }
 
        getopt32(argv, OPTION_STR, &interfaces);
-       if (argc - optind > 0) {
+       argv += optind;
+       if (argv[0]) {
                if (DO_ALL) bb_show_usage();
        } else {
                if (!DO_ALL) bb_show_usage();
@@ -1175,7 +1175,7 @@ int ifupdown_main(int argc, char **argv)
        if (DO_ALL) {
                target_list = defn->autointerfaces;
        } else {
-               llist_add_to_end(&target_list, argv[optind]);
+               llist_add_to_end(&target_list, argv[0]);
        }
 
        /* Update the interfaces */