X-Git-Url: http://git.ozlabs.org/?p=petitboot;a=blobdiff_plain;f=lib%2Fprocess%2Fprocess.c;h=6e143e0e4784e086b9f171bdb61d670e31efe523;hp=3c81b29340f8ae69ccd99f4ebe10133eb408e47d;hb=2a44f3c936f948d6fedc4729dbf2216da558e490;hpb=33527e065d9506e05f61c020a473544123c0601b diff --git a/lib/process/process.c b/lib/process/process.c index 3c81b29..6e143e0 100644 --- a/lib/process/process.c +++ b/lib/process/process.c @@ -61,7 +61,13 @@ static struct process_info *get_info(struct process *process) } /* Read as much as possible into the currently-allocated stdout buffer, and - * possibly realloc it for the next read */ + * possibly realloc it for the next read + * + * Returns: + * > 0 on success (even though no bytes may have been read) + * 0 on EOF (no error, but no more reads can be performed) + * < 0 on error + **/ static int process_read_stdout_once(struct process_info *procinfo) { struct process *process = &procinfo->process; @@ -74,8 +80,14 @@ static int process_read_stdout_once(struct process_info *procinfo) max_len = procinfo->stdout_buf_len - process->stdout_len - 1; rc = read(fd, process->stdout_buf + process->stdout_len, max_len); - if (rc <= 0) + if (rc == 0) + return 0; + if (rc < 0) { + if (errno == EINTR) + return 1; + pb_log("%s: read failed: %s\n", __func__, strerror(errno)); return rc; + } process->stdout_len += rc; if (process->stdout_len == procinfo->stdout_buf_len - 1) { @@ -85,7 +97,7 @@ static int process_read_stdout_once(struct process_info *procinfo) procinfo->stdout_buf_len); } - return rc; + return 1; } static int process_setup_stdout_pipe(struct process_info *procinfo) @@ -397,6 +409,7 @@ int process_run_async(struct process *process) void process_stop_async(struct process *process) { + pb_debug("process: sending SIGTERM to pid %d\n", process->pid); kill(process->pid, SIGTERM); } @@ -447,3 +460,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; +}