lib/process: Add helper for check process clean exit
authorJeremy Kerr <jk@ozlabs.org>
Tue, 21 Jan 2014 02:00:49 +0000 (10:00 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Tue, 21 Jan 2014 05:36:01 +0000 (13:36 +0800)
We have a few incorrect checks for the exit status of a process; this
change adds a helper with the correct WIFEXITED && WEXITSTATUS==0 logic.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
discover/paths.c
lib/pb-config/storage-powerpc-nvram.c
lib/process/process.c
lib/process/process.h

index 58fbffdc3e58f7aaa3a6f534a2f8dbeb003eeb73..54774cf3b6135cb9ffdac41b0f3f731e7699d1b0 100644 (file)
@@ -86,7 +86,7 @@ static void load_url_process_exit(struct process *process)
 
        if (result->status == LOAD_CANCELLED) {
                load_url_result_cleanup_local(result);
-       } else if (process->exit_status == 0) {
+       } else if (process_exit_ok(process)) {
                result->status = LOAD_OK;
        } else {
                result->status = LOAD_ERROR;
@@ -131,7 +131,7 @@ static void load_process_to_local_file(struct load_task *task,
                task->result->status = rc ? LOAD_ERROR : LOAD_ASYNC;
        } else {
                rc = process_run_sync(task->process);
-               if (rc || WEXITSTATUS(task->process->exit_status))
+               if (rc || !process_exit_ok(task->process))
                        task->result->status = LOAD_ERROR;
                else
                        task->result->status = LOAD_OK;
index 42de5984f02cc0e53537f864b8f3c067c2f0db03..4b4b87830ebee29428b85d875770f5fb2b4d3f02 100644 (file)
@@ -137,8 +137,7 @@ static int parse_nvram(struct powerpc_nvram_storage *nv)
 
        rc = process_run_sync(process);
 
-       if (rc || !WIFEXITED(process->exit_status)
-                       || WEXITSTATUS(process->exit_status)) {
+       if (rc || !process_exit_ok(process)) {
                fprintf(stderr, "nvram process returned "
                                "non-zero exit status\n");
                rc = -1;
@@ -183,8 +182,7 @@ static int write_nvram(struct powerpc_nvram_storage *nv)
 
                talloc_free(paramstr);
 
-               if (rc || !WIFEXITED(process->exit_status)
-                               || WEXITSTATUS(process->exit_status)) {
+               if (rc || !process_exit_ok(process)) {
                        rc = -1;
                        pb_log("nvram update process returned "
                                        "non-zero exit status\n");
index 3c81b29340f8ae69ccd99f4ebe10133eb408e47d..86c7fbbf246c374d50f1c23a637118079817a27c 100644 (file)
@@ -447,3 +447,9 @@ int process_run_simple(void *ctx, const char *name, ...)
 
        return rc;
 }
+
+bool process_exit_ok(struct process *process)
+{
+       return WIFEXITED(process->exit_status) &&
+               WEXITSTATUS(process->exit_status) == 0;
+}
index ae7fe32d06350679660ac21473b8cd45fa6fc986..f75f1976c718df3970930c88be9bf1de2bde299f 100644 (file)
@@ -74,4 +74,9 @@ int process_run_simple(void *ctx, const char *name, ...)
 int process_run_async(struct process *process);
 
 void process_stop_async(struct process *process);
+
+/* helper function to determine if a process exited cleanly, with a non-zero
+ * exit status */
+bool process_exit_ok(struct process *process);
+
 #endif /* PROCESS_H */