Try to make indent formatting less horrible
[oweals/busybox.git] / libbb / run_parts.c
index 1cd13f218ba3511b57144424e0ab0e8bd1e32f29..0eb766086bc77a54154a810c43214d6a5c15837c 100644 (file)
@@ -47,7 +47,7 @@ static int valid_name(const struct dirent *d)
  * test_mode = 2 means to fail siliently on missing directories
  */
 
-extern int run_parts(char **args, const unsigned char test_mode)
+extern int run_parts(char **args, const unsigned char test_mode, char **env)
 {
        struct dirent **namelist = 0;
        struct stat st;
@@ -80,40 +80,35 @@ extern int run_parts(char **args, const unsigned char test_mode)
                        bb_perror_msg_and_die("failed to stat component %s", filename);
                }
                if (S_ISREG(st.st_mode) && !access(filename, X_OK)) {
-                       if (test_mode & 1) {
+                       if (test_mode) {
                                puts(filename);
                        } else {
-                               pid_t pid, wpid;
+                               /* exec_errno is common vfork variable */
+                               volatile int exec_errno = 0;
                                int result;
+                               int pid;
 
                                if ((pid = vfork()) < 0) {
                                        bb_perror_msg_and_die("failed to fork");
-                               } else if (pid==0) {
-                                       execv(filename, args);
+                               } else if (!pid) {
+                                       args[0] = filename;
+                                       execve(filename, args, env);
+                                       exec_errno = errno;
                                        _exit(1);
                                }
 
-                               /* Wait for the child process to exit.  Since we use vfork
-                                * we shouldn't actually have to do any waiting... */
-                               wpid = wait(&result);
-                               while (wpid > 0) {
-                                       /* Find out who died, make sure it is the right process */
-                                       if (pid == wpid) {
-                                               if (WIFEXITED(result) && WEXITSTATUS(result)) {
-                                                       bb_perror_msg("%s exited with return code %d", filename, WEXITSTATUS(result));
-                                                       exitstatus = 1;
-                                               } else if (WIFSIGNALED(result) && WIFSIGNALED(result)) {
-                                                       int sig;
-                                                       sig = WTERMSIG(result);
-                                                       bb_perror_msg("%s exited because of uncaught signal %d (%s)", 
-                                                                       filename, sig, u_signal_names(0, &sig, 1));
-                                                       exitstatus = 1;
-                                               }
-                                               break;
-                                       } else {
-                                               /* Just in case some _other_ random child process exits */
-                                               wpid = wait(&result);
-                                       }
+                               waitpid(pid, &result, 0);
+                               if(exec_errno) {
+                                       errno = exec_errno;
+                                       bb_perror_msg("failed to exec %s", filename);
+                                       exitstatus = 1;
+                               }
+                               if (WIFEXITED(result) && WEXITSTATUS(result)) {
+                                       bb_perror_msg("%s exited with return code %d", filename, WEXITSTATUS(result));
+                                       exitstatus = 1;
+                               } else if (WIFSIGNALED(result)) {
+                                       bb_perror_msg("%s exited because of uncaught signal %d", filename, WTERMSIG(result));
+                                       exitstatus = 1;
                                }
                        }
                }