lpr: add more accurate comments
[oweals/busybox.git] / networking / ifupdown.c
index 58e69530c439f2f2e2a17f01f5c1aad8f812aad8..29738c6d0bc20514284ab31bf9407c29fcee5775 100644 (file)
@@ -19,7 +19,6 @@
 
 #include <sys/utsname.h>
 #include <fnmatch.h>
-#include <getopt.h>
 
 #include "libbb.h"
 
@@ -483,9 +482,9 @@ static const struct dhcp_client_t ext_dhcp_clients[] = {
 };
 #endif /* ENABLE_FEATURE_IFUPDOWN_EXTERNAL_DHCPC */
 
+#if ENABLE_FEATURE_IFUPDOWN_EXTERNAL_DHCP
 static int dhcp_up(struct interface_defn_t *ifd, execfn *exec)
 {
-#if ENABLE_FEATURE_IFUPDOWN_EXTERNAL_DHCP
        int i;
 #if ENABLE_FEATURE_IFUPDOWN_IP
        /* ip doesn't up iface when it configures it (unlike ifconfig) */
@@ -498,7 +497,10 @@ static int dhcp_up(struct interface_defn_t *ifd, execfn *exec)
        }
        bb_error_msg("no dhcp clients found");
        return 0;
+}
 #elif ENABLE_APP_UDHCPC
+static int dhcp_up(struct interface_defn_t *ifd, execfn *exec)
+{
 #if ENABLE_FEATURE_IFUPDOWN_IP
        /* ip doesn't up iface when it configures it (unlike ifconfig) */
        if (!execute("ip link set %iface% up", ifd, exec))
@@ -507,14 +509,18 @@ static int dhcp_up(struct interface_defn_t *ifd, execfn *exec)
        return execute("udhcpc -R -n -p /var/run/udhcpc.%iface%.pid "
                        "-i %iface%[[ -H %hostname%]][[ -c %clientid%]][[ -s %script%]]",
                        ifd, exec);
+}
 #else
+static int dhcp_up(struct interface_defn_t *ifd ATTRIBUTE_UNUSED,
+               execfn *exec ATTRIBUTE_UNUSED)
+{
        return 0; /* no dhcp support */
-#endif
 }
+#endif
 
+#if ENABLE_FEATURE_IFUPDOWN_EXTERNAL_DHCP
 static int dhcp_down(struct interface_defn_t *ifd, execfn *exec)
 {
-#if ENABLE_FEATURE_IFUPDOWN_EXTERNAL_DHCP
        int i;
        for (i = 0; i < ARRAY_SIZE(ext_dhcp_clients); i++) {
                if (exists_execable(ext_dhcp_clients[i].name))
@@ -522,15 +528,22 @@ static int dhcp_down(struct interface_defn_t *ifd, execfn *exec)
        }
        bb_error_msg("no dhcp clients found, using static interface shutdown");
        return static_down(ifd, exec);
+}
 #elif ENABLE_APP_UDHCPC
+static int dhcp_down(struct interface_defn_t *ifd, execfn *exec)
+{
        return execute("kill "
                       "`cat /var/run/udhcpc.%iface%.pid` 2>/dev/null", ifd, exec);
+}
 #else
+static int dhcp_down(struct interface_defn_t *ifd ATTRIBUTE_UNUSED,
+               execfn *exec ATTRIBUTE_UNUSED)
+{
        return 0; /* no dhcp support */
-#endif
 }
+#endif
 
-static int manual_up_down(struct interface_defn_t *ifd, execfn *exec)
+static int manual_up_down(struct interface_defn_t *ifd ATTRIBUTE_UNUSED, execfn *exec ATTRIBUTE_UNUSED)
 {
        return 1;
 }
@@ -925,13 +938,13 @@ static int doit(char *str)
                int status;
 
                fflush(NULL);
-               child = fork();
+               child = vfork();
                switch (child) {
                case -1: /* failure */
                        return 0;
                case 0: /* child */
                        execle(DEFAULT_SHELL, DEFAULT_SHELL, "-c", str, NULL, my_environ);
-                       exit(127);
+                       _exit(127);
                }
                safe_waitpid(child, &status, 0);
                if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
@@ -994,11 +1007,11 @@ static int popen2(FILE **in, FILE **out, char *command, char *param)
        xpiped_pair(outfd);
 
        fflush(NULL);
-       pid = fork();
+       pid = vfork();
 
        switch (pid) {
        case -1:  /* failure */
-               bb_perror_msg_and_die("fork");
+               bb_perror_msg_and_die("vfork");
        case 0:  /* child */
                /* NB: close _first_, then move fds! */
                close(infd.wr);