tests: Expand 'bundle with many ports' test.
[cascardo/ovs.git] / lib / process.c
index b479d00..e89f9ca 100644 (file)
@@ -21,6 +21,7 @@
 #include <signal.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/resource.h>
 #include <sys/stat.h>
 #include <sys/wait.h>
 #include <unistd.h>
 #include "signals.h"
 #include "socket-util.h"
 #include "util.h"
-#include "vlog.h"
+#include "openvswitch/vlog.h"
 
 VLOG_DEFINE_THIS_MODULE(process);
 
 COVERAGE_DEFINE(process_start);
 
 struct process {
-    struct list node;
+    struct ovs_list node;
     char *name;
     pid_t pid;
 
@@ -53,7 +54,7 @@ struct process {
 static int fds[2];
 
 /* All processes. */
-static struct list all_processes = LIST_INITIALIZER(&all_processes);
+static struct ovs_list all_processes = OVS_LIST_INITIALIZER(&all_processes);
 
 static void sigchld_handler(int signr OVS_UNUSED);
 
@@ -226,6 +227,7 @@ process_start(char **argv, struct process **pp)
 #ifndef _WIN32
     pid_t pid;
     int error;
+    sigset_t prev_mask;
 
     assert_single_threaded();
 
@@ -236,14 +238,15 @@ process_start(char **argv, struct process **pp)
         return error;
     }
 
+    fatal_signal_block(&prev_mask);
     pid = fork();
     if (pid < 0) {
         VLOG_WARN("fork failed: %s", ovs_strerror(errno));
-        return errno;
+        error = errno;
     } else if (pid) {
         /* Running in parent process. */
         *pp = process_register(argv[0], pid);
-        return 0;
+        error = 0;
     } else {
         /* Running in child process. */
         int fd_max = get_max_fds();
@@ -253,11 +256,14 @@ process_start(char **argv, struct process **pp)
         for (fd = 3; fd < fd_max; fd++) {
             close(fd);
         }
+        xpthread_sigmask(SIG_SETMASK, &prev_mask, NULL);
         execvp(argv[0], argv);
         fprintf(stderr, "execvp(\"%s\") failed: %s\n",
                 argv[0], ovs_strerror(errno));
         _exit(1);
     }
+    xpthread_sigmask(SIG_SETMASK, &prev_mask, NULL);
+    return error;
 #else
     *pp = NULL;
     return ENOSYS;