diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2012-12-30 14:55:29 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2012-12-30 14:55:29 +0200 |
commit | 5596f7cdcdc1983021185c5e0900d5fcba7f3282 (patch) | |
tree | a5ce48b053981cf5d25d862037ddde0b40791e72 /src/preproc.c | |
parent | 61cb995c7548bc5b0b00c06db5628b177f7231b0 (diff) | |
download | grecs-5596f7cdcdc1983021185c5e0900d5fcba7f3282.tar.gz grecs-5596f7cdcdc1983021185c5e0900d5fcba7f3282.tar.bz2 |
Check returns from pipe and dup2.
Diffstat (limited to 'src/preproc.c')
-rw-r--r-- | src/preproc.c | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/src/preproc.c b/src/preproc.c index f1d5227..ce32a29 100644 --- a/src/preproc.c +++ b/src/preproc.c @@ -661,19 +661,24 @@ grecs_preproc_extrn_start(const char *file_name, pid_t *ppid) pid_t pid; int i; FILE *fp = NULL; /*FIXME_DEBUG_F1 (2, "Running preprocessor: `%s'", ppcmd);*/ - pipe(pout); + if (pipe(pout)) { + grecs_error(NULL, errno, "pipe"); + return NULL; + } switch (pid = fork()) { /* The child branch. */ case 0: if (pout[1] != 1) { - close(1); - dup2(pout[1], 1); + if (dup2(pout[1], 1) == -1) { + grecs_error(NULL, errno, "dup2"); + exit(127); + } } /* Close unneeded descripitors */ for (i = getdtablesize(); i > 2; i--) close(i); @@ -681,19 +686,22 @@ grecs_preproc_extrn_start(const char *file_name, pid_t *ppid) int p[2]; char *buf = NULL; size_t size = 0; FILE *fp; signal(SIGCHLD, SIG_DFL); - pipe(p); + if (pipe(p)) { + grecs_error(NULL, errno, "pipe"); + exit(127); + } switch (pid = fork()) { /* Grandchild */ case 0: - if (p[1] != 2) { - close(2); - dup2(p[1], 2); + if (p[1] != 2 && dup2(p[1], 2) == -1) { + grecs_error(NULL, errno, "dup2"); + exit(127); } close(p[0]); if (grecs_preproc_run(file_name, grecs_preprocessor)) exit(127); |