[PATCH] Further improve child exit reaping
[fio.git] / fio.c
diff --git a/fio.c b/fio.c
index e8a86585d4bd5d4ee83cff9202eca1ef8a3a58a9..e386f53c0259726cabfb388909d0e85c6e6a8a49 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -761,28 +761,30 @@ err:
        close_ioengine(td);
        cleanup_io_u(td);
        td_set_runstate(td, TD_EXITED);
        close_ioengine(td);
        cleanup_io_u(td);
        td_set_runstate(td, TD_EXITED);
-       return NULL;
+       return (void *) td->error;
 }
 
 /*
  * We cannot pass the td data into a forked process, so attach the td and
  * pass it to the thread worker.
  */
 }
 
 /*
  * We cannot pass the td data into a forked process, so attach the td and
  * pass it to the thread worker.
  */
-static void *fork_main(int shmid, int offset)
+static int fork_main(int shmid, int offset)
 {
        struct thread_data *td;
 {
        struct thread_data *td;
-       void *data;
+       void *data, *ret;
 
        data = shmat(shmid, NULL, 0);
        if (data == (void *) -1) {
 
        data = shmat(shmid, NULL, 0);
        if (data == (void *) -1) {
+               int __err = errno;
+
                perror("shmat");
                perror("shmat");
-               return NULL;
+               return __err;
        }
 
        td = data + offset * sizeof(struct thread_data);
        }
 
        td = data + offset * sizeof(struct thread_data);
-       thread_main(td);
+       ret = thread_main(td);
        shmdt(data);
        shmdt(data);
-       return NULL;
+       return (int) ret;
 }
 
 /*
 }
 
 /*
@@ -822,8 +824,15 @@ static void reap_threads(int *nr_running, int *t_rate, int *m_rate)
 
                        if (pthread_join(td->thread, (void *) &ret))
                                perror("thread_join");
 
                        if (pthread_join(td->thread, (void *) &ret))
                                perror("thread_join");
-               } else
-                       waitpid(td->pid, NULL, 0);
+               } else {
+                       int status;
+
+                       waitpid(td->pid, &status, 0);
+                       if (WIFEXITED(status) && WEXITSTATUS(status)) {
+                               if (!exit_value)
+                                       exit_value++;
+                       }
+               }
 
                (*nr_running)--;
                (*m_rate) -= td->ratemin;
 
                (*nr_running)--;
                (*m_rate) -= td->ratemin;
@@ -932,8 +941,9 @@ static void run_threads(void)
                                if (fork())
                                        fio_sem_down(&startup_sem);
                                else {
                                if (fork())
                                        fio_sem_down(&startup_sem);
                                else {
-                                       fork_main(shm_id, i);
-                                       exit(0);
+                                       int ret = fork_main(shm_id, i);
+
+                                       exit(ret);
                                }
                        }
                }
                                }
                        }
                }