accidentally applied wrong (old) patch, fixing up...
[oweals/busybox.git] / networking / ifupdown.c
index 90c05444b486ca3cae151edb106d93b2cd41d3fe..adbc37e43e4daad06541ff63cf03ef13ad90f218 100644 (file)
@@ -291,9 +291,11 @@ static int execute(const char *command, struct interface_defn_t *ifd, execfn *ex
 
        out = parse(command, ifd);
        if (!out) {
+               /* parse error? */
                return 0;
        }
-       ret = (*exec)(out);
+       /* out == "": parsed ok but not all needed variables known, skip */
+       ret = out[0] ? (*exec)(out) : 1;
 
        free(out);
        if (ret != 1) {
@@ -903,15 +905,13 @@ static int doit(char *str)
        if (option_mask32 & (OPT_no_act|OPT_verbose)) {
                puts(str);
        }
-       /* FIXME: is it true that we can reach this place with str = ""? */
-       /* how? in execute() parse() may return "", then we do (*exec)(""); */
-       /* Please add a comment... */
        if (!(option_mask32 & OPT_no_act)) {
                pid_t child;
                int status;
 
                fflush(NULL);
-               switch (child = fork()) {
+               child = fork();
+               switch (child) {
                case -1: /* failure */
                        return 0;
                case 0: /* child */
@@ -939,10 +939,8 @@ static int execute_all(struct interface_defn_t *ifd, const char *opt)
        }
 
        buf = xasprintf("run-parts /etc/network/if-%s.d", opt);
-       if (doit(buf) != 1) {
-               return 0;
-       }
-       return 1;
+       /* heh, we don't bother free'ing it */
+       return doit(buf);
 }
 
 static int check(char *str)
@@ -1050,7 +1048,7 @@ static char *run_mapping(char *physical, struct mapping_defn_t * map)
                /* If the mapping script exited successfully, try to
                 * grab a line of output and use that as the name of the
                 * logical interface. */
-               char *new_logical = (char *)xmalloc(MAX_INTERFACE_LENGTH);
+               char *new_logical = xmalloc(MAX_INTERFACE_LENGTH);
 
                if (fgets(new_logical, MAX_INTERFACE_LENGTH, out)) {
                        /* If we are able to read a line of output from the script,
@@ -1141,7 +1139,6 @@ int ifupdown_main(int argc, char **argv)
                llist_add_to_end(&target_list, argv[optind]);
        }
 
-
        /* Update the interfaces */
        while (target_list) {
                llist_t *iface_list;
@@ -1257,8 +1254,7 @@ int ifupdown_main(int argc, char **argv)
                state_fp = xfopen("/var/run/ifstate", "w");
                while (state_list) {
                        if (state_list->data) {
-                               fputs(state_list->data, state_fp);
-                               fputc('\n', state_fp);
+                               fprintf(state_fp, "%s\n", state_list->data);
                        }
                        state_list = state_list->link;
                }