Răsfoiți Sursa

system: BProcess: just use open_standard_streams()

ambrop7 14 ani în urmă
părinte
comite
dee8079e9d
1 a modificat fișierele cu 2 adăugiri și 35 ștergeri
  1. 2 35
      system/BProcess.c

+ 2 - 35
system/BProcess.c

@@ -35,6 +35,7 @@
 #include <fcntl.h>
 
 #include <misc/offset.h>
+#include <misc/open_standard_streams.h>
 #include <base/BLog.h>
 
 #include "BProcess.h"
@@ -177,32 +178,6 @@ static int fds_contains (const int *fds, int fd, size_t *pos)
     return 0;
 }
 
-static int ensure_standard_stream (const int *fds_map, size_t fds_map_size, int fd)
-{
-    // if some file descriptor from parent is being used for this standard stream, keep it
-    for (size_t i = 0; i < fds_map_size; i++) {
-        if (fds_map[i] == fd) {
-            return 1;
-        }
-    }
-    
-    // open /dev/null
-    int ofd = open("/dev/null", O_RDWR);
-    if (ofd < 0) {
-        return 0;
-    }
-    
-    // map the new fd to the standard stream
-    if (ofd != fd) {
-        if (dup2(ofd, fd) < 0) {
-            return 0;
-        }
-        close(ofd);
-    }
-    
-    return 1;
-}
-
 int BProcess_InitWithFds (BProcess *o, BProcessManager *m, BProcess_handler handler, void *user, const char *file, char *const argv[], const char *username, const int *fds, const int *fds_map)
 {
     // init arguments
@@ -299,15 +274,7 @@ int BProcess_InitWithFds (BProcess *o, BProcessManager *m, BProcess_handler hand
         }
         
         // make sure standard streams are open
-        if (!ensure_standard_stream(orig_fds_map, num_fds, 0)) {
-            abort();
-        }
-        if (!ensure_standard_stream(orig_fds_map, num_fds, 1)) {
-            abort();
-        }
-        if (!ensure_standard_stream(orig_fds_map, num_fds, 2)) {
-            abort();
-        }
+        open_standard_streams();
         
         // assume identity of username, if requested
         if (username) {