summaryrefslogtreecommitdiffstats
path: root/lib/process
diff options
context:
space:
mode:
authorJeremy Kerr <jk@ozlabs.org>2014-02-20 09:22:58 +0800
committerJeremy Kerr <jk@ozlabs.org>2014-02-20 10:11:52 +0800
commitffb84fc1bf1d138d1ac1bb8ece0b7d625f288d97 (patch)
treefcb5a469816b4b929686f343735a2b2942cf7cf1 /lib/process
parent0b3bfb90a292ceba33b649681876ec1ed50c8447 (diff)
downloadtalos-petitboot-ffb84fc1bf1d138d1ac1bb8ece0b7d625f288d97.tar.gz
talos-petitboot-ffb84fc1bf1d138d1ac1bb8ece0b7d625f288d97.zip
lib/process: Don't abort stdout reads on EINTR
If our read() of the process stdout pipe fails with EINTR (eg, if we receive a SIGCHLD because the process exited), then process_read_stdout_once will return a non-zero exit code, and we'll abort any further stdout collection. Instead, we should check for EINTR, and allow the reads to continue. This change normalises the return value from process_read_stdout_once to return positive on success, negative on failure, and zero on competion. We use a positive return value for the non-error EINTR case. Also, add a pb_log if the read fails for non-EINTR reasons. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Diffstat (limited to 'lib/process')
-rw-r--r--lib/process/process.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/lib/process/process.c b/lib/process/process.c
index 86c7fbb..081a48c 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)
OpenPOWER on IntegriCloud