aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2012-12-30 14:55:29 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2012-12-30 14:55:29 +0200
commit5596f7cdcdc1983021185c5e0900d5fcba7f3282 (patch)
treea5ce48b053981cf5d25d862037ddde0b40791e72
parent61cb995c7548bc5b0b00c06db5628b177f7231b0 (diff)
downloadgrecs-5596f7cdcdc1983021185c5e0900d5fcba7f3282.tar.gz
grecs-5596f7cdcdc1983021185c5e0900d5fcba7f3282.tar.bz2
Check returns from pipe and dup2.
-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)
664 664
665 /*FIXME_DEBUG_F1 (2, "Running preprocessor: `%s'", ppcmd);*/ 665 /*FIXME_DEBUG_F1 (2, "Running preprocessor: `%s'", ppcmd);*/
666 666
667 pipe(pout); 667 if (pipe(pout)) {
668 grecs_error(NULL, errno, "pipe");
669 return NULL;
670 }
668 switch (pid = fork()) { 671 switch (pid = fork()) {
669 /* The child branch. */ 672 /* The child branch. */
670 case 0: 673 case 0:
671 if (pout[1] != 1) { 674 if (pout[1] != 1) {
672 close(1); 675 if (dup2(pout[1], 1) == -1) {
673 dup2(pout[1], 1); 676 grecs_error(NULL, errno, "dup2");
677 exit(127);
678 }
674 } 679 }
675 680
676 /* Close unneeded descripitors */ 681 /* Close unneeded descripitors */
@@ -684,13 +689,16 @@ grecs_preproc_extrn_start(const char *file_name, pid_t *ppid)
684 FILE *fp; 689 FILE *fp;
685 690
686 signal(SIGCHLD, SIG_DFL); 691 signal(SIGCHLD, SIG_DFL);
687 pipe(p); 692 if (pipe(p)) {
693 grecs_error(NULL, errno, "pipe");
694 exit(127);
695 }
688 switch (pid = fork()) { 696 switch (pid = fork()) {
689 /* Grandchild */ 697 /* Grandchild */
690 case 0: 698 case 0:
691 if (p[1] != 2) { 699 if (p[1] != 2 && dup2(p[1], 2) == -1) {
692 close(2); 700 grecs_error(NULL, errno, "dup2");
693 dup2(p[1], 2); 701 exit(127);
694 } 702 }
695 close(p[0]); 703 close(p[0]);
696 704

Return to:

Send suggestions and report system problems to the System administrator.