summaryrefslogtreecommitdiffabout
path: root/src/preproc.c
authorSergey Poznyakoff <gray@gnu.org.ua>2012-12-30 12:55:29 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2012-12-30 12:55:29 (GMT)
commit5596f7cdcdc1983021185c5e0900d5fcba7f3282 (patch) (side-by-side diff)
treea5ce48b053981cf5d25d862037ddde0b40791e72 /src/preproc.c
parent61cb995c7548bc5b0b00c06db5628b177f7231b0 (diff)
downloadgrecs-5596f7cdcdc1983021185c5e0900d5fcba7f3282.tar.gz
grecs-5596f7cdcdc1983021185c5e0900d5fcba7f3282.tar.bz2
Check returns from pipe and dup2.
Diffstat (limited to 'src/preproc.c') (more/less context) (ignore whitespace changes)
-rw-r--r--src/preproc.c22
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
@@ -664,13 +664,18 @@ grecs_preproc_extrn_start(const char *file_name, pid_t *ppid)
/*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 */
@@ -684,13 +689,16 @@ grecs_preproc_extrn_start(const char *file_name, pid_t *ppid)
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]);

Return to:

Send suggestions and report system problems to the System administrator.