]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/commitdiff
misc-progs: setuid: Return exit code from called process
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 24 May 2023 09:08:41 +0000 (09:08 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 15 Jun 2023 09:39:28 +0000 (09:39 +0000)
This patch will return the exit code from the called process which has
not been done before. This made it more difficult to catch any
unsuccessful calls from the web UI.

Partly Fixes: #12863
Tested-by: Jon Murphy <jon.murphy@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/misc-progs/setuid.c

index 17b0e70667540407dcb30bf9084f0641919d743f..9dc0a767b6df083df1ff27cf230504da01e3199a 100644 (file)
@@ -104,16 +104,20 @@ static int system_core(char* command, char** args, uid_t uid, gid_t gid, char *e
                }
 
                default: /* parent */
-                       do {
-                               if (waitpid(pid, &status, 0) == -1) {
-                                       if (errno != EINTR)
-                                               return -1;
-                                       } else {
-                                               return status;
-                                       }
-                       } while (1);
-       }
+                       // Wait until the child process has finished
+                       waitpid(pid, &status, 0);
+
+                       // The child was terminated by a signal
+                       if (WIFSIGNALED(status))
+                                return 128 + WTERMSIG(status);
 
+                       // Return the exit code if available
+                       if (WIFEXITED(status))
+                               return WEXITSTATUS(status);
+
+                       // Something unexpected happened, exiting with error
+                       return EXIT_FAILURE;
+       }
 }
 
 int run(char* command, char** argv) {