]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
dhcpcd: Improve script status handling
authorRoy Marples <roy@marples.name>
Thu, 19 Oct 2023 11:06:22 +0000 (12:06 +0100)
committerRoy Marples <roy@marples.name>
Thu, 19 Oct 2023 11:06:33 +0000 (12:06 +0100)
src/script.c

index 69297a466eb3a9c1260d5a62c33877de33c4fb3b..1a61f29dd10bed6f75913ac27c468be7c69f6478 100644 (file)
@@ -700,24 +700,24 @@ static int
 script_run(struct dhcpcd_ctx *ctx, char **argv)
 {
        pid_t pid;
-       int status = 0;
+       int status;
 
        pid = script_exec(argv, ctx->script_env);
-       if (pid == -1)
+       if (pid == -1) {
                logerr("%s: %s", __func__, argv[0]);
-       else if (pid != 0) {
-               /* Wait for the script to finish */
-               while (waitpid(pid, &status, 0) == -1) {
-                       if (errno != EINTR) {
-                               logerr("%s: waitpid", __func__);
-                               status = 0;
-                               break;
-                       }
+               return -1;
+       } else if (pid == 0)
+               return 0;
+
+       /* Wait for the script to finish */
+       while (waitpid(pid, &status, 0) == -1) {
+               if (errno != EINTR) {
+                       logerr("%s: waitpid", __func__);
+                       status = 0;
+                       break;
                }
-               status = script_status(argv[0], status);
        }
-
-       return WEXITSTATUS(status);
+       return script_status(argv[0], status);
 }
 
 int
@@ -771,7 +771,7 @@ script_runreason(const struct interface *ifp, const char *reason)
        logdebugx("%s: executing: %s %s", ifp->name, argv[0], reason);
 
 #ifdef PRIVSEP
-       if (ctx->options & DHCPCD_PRIVSEP) {
+       if (IN_PRIVSEP(ctx)) {
                ssize_t err;
 
                err = ps_root_script(ctx, ctx->script_buf, (size_t)buflen);