lib: check the return of calls to pipe(), report errors and abort on fail
authorAlexis Laferrière <alexis.laf@xymus.net>
Wed, 30 Jan 2013 21:10:41 +0000 (16:10 -0500)
committerAlexis Laferrière <alexis.laf@xymus.net>
Fri, 1 Feb 2013 20:54:51 +0000 (15:54 -0500)
This commits prevents compilation warnings and allows easier debugging.

Better solutions are still possible but will require to modifiy the API.

Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

lib/standard/exec_nit.c

index d66f5fe..9b6a5e4 100644 (file)
@@ -14,6 +14,7 @@
 #include "exec_nit.h"
 #include <stdlib.h>
 #include <string.h>
+#include <errno.h>
 
 se_exec_data_t* exec_Process_Process_basic_exec_execute_4(void *s, char *prog, char *args, int len, int pipeflag) {
        se_exec_data_t* result = NULL;
@@ -21,12 +22,27 @@ se_exec_data_t* exec_Process_Process_basic_exec_execute_4(void *s, char *prog, c
        int in_fd[2];
        int out_fd[2];
        int err_fd[2];
-       if (pipeflag & 1)
-               pipe(in_fd);
-       if (pipeflag & 2)
-               pipe(out_fd);
-       if (pipeflag & 4)
-               pipe(err_fd);
+       if (pipeflag & 1) {
+               int res = pipe(in_fd);
+               if ( res == -1 ) {
+                       fprintf( stderr, "Pipe init failed in Process:basic_exec_execute: %s\n", strerror( errno ) );
+                       exit(1);
+               }
+       }
+       if (pipeflag & 2) {
+               int res = pipe(out_fd);
+               if ( res == -1 ) {
+                       fprintf( stderr, "Pipe init failed in Process:basic_exec_execute: %s\n", strerror( errno ) );
+                       exit(1);
+               }
+       }
+       if (pipeflag & 4) {
+               int res = pipe(err_fd);
+               if ( res == -1 ) {
+                       fprintf( stderr, "Pipe init failed in Process:basic_exec_execute: %s\n", strerror( errno ) );
+                       exit(1);
+               }
+       }
                                        
        id = fork();
        if (id == 0)
@@ -96,6 +112,7 @@ se_exec_data_t* exec_Process_Process_basic_exec_execute_4(void *s, char *prog, c
                } else
                        result->err_fd = -1;
        }
+
        return result;
 }