@@ -71,10 +71,7 @@ struct executer {
7171};
7272
7373/* File descriptors for waking up when a child dies. */
74- static int signal_fds [2 ];
75-
76- /* File descriptor for /dev/null. */
77- static int null_fd = -1 ;
74+ static int signal_fds [2 ] = {-1 , -1 };
7875
7976static void send_child_status (struct rconn * , uint32_t xid , uint32_t status ,
8077 const void * data , size_t size );
@@ -205,9 +202,9 @@ executer_handle_request(struct executer *e, struct rconn *rconn,
205202 * subprocesses at once? Would also want to catch fatal signals and
206203 * kill them at the same time though. */
207204 fatal_signal_fork ();
208- dup2 (null_fd , 0 );
205+ dup2 (get_null_fd () , 0 );
209206 dup2 (output_fds [1 ], 1 );
210- dup2 (null_fd , 2 );
207+ dup2 (get_null_fd () , 2 );
211208 max_fds = get_max_fds ();
212209 for (i = 3 ; i < max_fds ; i ++ ) {
213210 close (i );
@@ -448,24 +445,20 @@ executer_create(const char *command_acl, const char *command_dir,
448445 struct sigaction sa ;
449446
450447 * executerp = NULL ;
451- if (null_fd == -1 ) {
448+ if (signal_fds [0 ] == -1 ) {
449+ /* Make sure we can get a fd for /dev/null. */
450+ int null_fd = get_null_fd ();
451+ if (null_fd < 0 ) {
452+ return - null_fd ;
453+ }
454+
452455 /* Create pipe for notifying us that SIGCHLD was invoked. */
453456 if (pipe (signal_fds )) {
454457 VLOG_ERR ("pipe failed: %s" , strerror (errno ));
455458 return errno ;
456459 }
457460 set_nonblocking (signal_fds [0 ]);
458461 set_nonblocking (signal_fds [1 ]);
459-
460- /* Open /dev/null. */
461- null_fd = open ("/dev/null" , O_RDWR );
462- if (null_fd < 0 ) {
463- int error = errno ;
464- VLOG_ERR ("could not open /dev/null: %s" , strerror (error ));
465- close (signal_fds [0 ]);
466- close (signal_fds [1 ]);
467- return error ;
468- }
469462 }
470463
471464 /* Set up signal handler. */
0 commit comments