start_stop_daemon: NOMMU fixes, round 2 by Alex Landau <landau_alex@yahoo.com>
[oweals/busybox.git] / networking / ifupdown.c
index e9f0a646c903cb3b5110113109f2fd779b46be6f..040bbe38965cbee39050ac3a3df736aae0475d5b 100644 (file)
@@ -10,7 +10,9 @@
  *  Changes to upstream version
  *  Remove checks for kernel version, assume kernel version 2.2.0 or better.
  *  Lines in the interfaces file cannot wrap.
- *  To adhere to the FHS, the default state file is /var/run/ifstate.
+ *  To adhere to the FHS, the default state file is /var/run/ifstate
+ *  (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.
  */
@@ -482,7 +484,12 @@ static const struct dhcp_client_t ext_dhcp_clients[] = {
 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) */
+       if (!execute("ip link set %iface% up", ifd, exec))
+               return 0;
+#endif
+       int i;
        for (i = 0; i < ARRAY_SIZE(ext_dhcp_clients); i++) {
                if (exists_execable(ext_dhcp_clients[i].name))
                        return execute(ext_dhcp_clients[i].startcmd, ifd, exec);
@@ -490,6 +497,11 @@ static int dhcp_up(struct interface_defn_t *ifd, execfn *exec)
        bb_error_msg("no dhcp clients found");
        return 0;
 #elif ENABLE_APP_UDHCPC
+#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))
+               return 0;
+#endif
        return execute("udhcpc -R -n -p /var/run/udhcpc.%iface%.pid "
                        "-i %iface%[[ -H %hostname%]][[ -c %clientid%]][[ -s %script%]]",
                        ifd, exec);
@@ -501,7 +513,7 @@ static int dhcp_up(struct interface_defn_t *ifd, execfn *exec)
 static int dhcp_down(struct interface_defn_t *ifd, execfn *exec)
 {
 #if ENABLE_FEATURE_IFUPDOWN_EXTERNAL_DHCP
-       int i ;
+       int i;
        for (i = 0; i < ARRAY_SIZE(ext_dhcp_clients); i++) {
                if (exists_execable(ext_dhcp_clients[i].name))
                        return execute(ext_dhcp_clients[i].stopcmd, ifd, exec);
@@ -524,8 +536,8 @@ static int manual_up_down(struct interface_defn_t *ifd, execfn *exec)
 static int bootp_up(struct interface_defn_t *ifd, execfn *exec)
 {
        return execute("bootpc[[ --bootfile %bootfile%]] --dev %iface%"
-                       "[[ --server %server%]][[ --hwaddr %hwaddr%]] "
-                       "--returniffail --serverbcast", ifd, exec);
+                       "[[ --server %server%]][[ --hwaddr %hwaddr%]]"
+                       " --returniffail --serverbcast", ifd, exec);
 }
 
 static int ppp_up(struct interface_defn_t *ifd, execfn *exec)
@@ -1105,7 +1117,7 @@ static llist_t *find_iface_state(llist_t *state_list, const char *iface)
 static llist_t *read_iface_state(void)
 {
        llist_t *state_list = NULL;
-       FILE *state_fp = fopen("/var/run/ifstate", "r");
+       FILE *state_fp = fopen(CONFIG_IFUPDOWN_IFSTATE_PATH, "r");
 
        if (state_fp) {
                char *start, *end_ptr;
@@ -1275,7 +1287,7 @@ int ifupdown_main(int argc, char **argv)
                        }
 
                        /* Actually write the new state */
-                       state_fp = xfopen("/var/run/ifstate", "w");
+                       state_fp = xfopen(CONFIG_IFUPDOWN_IFSTATE_PATH, "w");
                        state = state_list;
                        while (state) {
                                if (state->data) {