]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Make fork process clearer.
authorRoy Marples <roy@marples.name>
Sun, 10 Apr 2016 18:46:12 +0000 (18:46 +0000)
committerRoy Marples <roy@marples.name>
Sun, 10 Apr 2016 18:46:12 +0000 (18:46 +0000)
dhcpcd.c

index 31dc60c8dea45dba7f3967db2d5b8f08ff3ce365..ad4b1b5d78d76298b777d4693aa1d1f066f8f846 100644 (file)
--- a/dhcpcd.c
+++ b/dhcpcd.c
@@ -345,24 +345,19 @@ dhcpcd_daemonise(struct dhcpcd_ctx *ctx)
                        dup2(fd, STDERR_FILENO);
                        close(fd);
                }
-               break;
+               ctx->options |= DHCPCD_DAEMONISED;
+               return 0;
        default:
                /* Wait for child to detach */
                close(sidpipe[1]);
                if (read(sidpipe[0], &buf, 1) == -1)
                        logger(ctx, LOG_ERR, "failed to read child: %m");
                close(sidpipe[0]);
-               break;
-       }
-       /* Done with the fd now */
-       if (pid != 0) {
                logger(ctx, LOG_INFO, "forked to background, child pid %d", pid);
                ctx->options |= DHCPCD_FORKED;
                eloop_exit(ctx->eloop, EXIT_SUCCESS);
                return pid;
        }
-       ctx->options |= DHCPCD_DAEMONISED;
-       return pid;
 #endif
 }
 
@@ -1800,7 +1795,7 @@ printpidfile:
                        if (pid == -1)
                                logger(&ctx, LOG_ERR, "%s: pidfile_lock: %m",
                                    __func__);
-                       else    
+                       else
                                logger(&ctx, LOG_ERR, ""PACKAGE
                                    " already running on pid %d (%s)",
                                    pid, ctx.pidfile);