Merge branch 'mainstream'
[sliver-openvswitch.git] / lib / process.c
index 520502a..143347c 100644 (file)
@@ -28,6 +28,7 @@
 #include "dynamic-string.h"
 #include "fatal-signal.h"
 #include "list.h"
+#include "ovs-thread.h"
 #include "poll-loop.h"
 #include "signals.h"
 #include "socket-util.h"
@@ -60,6 +61,8 @@ static void sigchld_handler(int signr OVS_UNUSED);
 /* Initializes the process subsystem (if it is not already initialized).  Calls
  * exit() if initialization fails.
  *
+ * This function may not be called after creating any additional threads.
+ *
  * Calling this function is optional; it will be called automatically by
  * process_start() if necessary.  Calling it explicitly allows the client to
  * prevent the process from exiting at an unexpected time. */
@@ -69,6 +72,7 @@ process_init(void)
     static bool inited;
     struct sigaction sa;
 
+    assert_single_threaded();
     if (inited) {
         return;
     }
@@ -164,6 +168,8 @@ process_register(const char *name, pid_t pid)
  * argv[0] is used as the name of the process.  Searches the PATH environment
  * variable to find the program to execute.
  *
+ * This function may not be called after creating any additional threads.
+ *
  * All file descriptors are closed before executing the subprocess, except for
  * fds 0, 1, and 2.
  *
@@ -176,6 +182,8 @@ process_start(char **argv, struct process **pp)
     pid_t pid;
     int error;
 
+    assert_single_threaded();
+
     *pp = NULL;
     COVERAGE_INC(process_start);
     error = process_prestart(argv);
@@ -185,7 +193,7 @@ process_start(char **argv, struct process **pp)
 
     pid = fork();
     if (pid < 0) {
-        VLOG_WARN("fork failed: %s", strerror(errno));
+        VLOG_WARN("fork failed: %s", ovs_strerror(errno));
         return errno;
     } else if (pid) {
         /* Running in parent process. */
@@ -202,7 +210,7 @@ process_start(char **argv, struct process **pp)
         }
         execvp(argv[0], argv);
         fprintf(stderr, "execvp(\"%s\") failed: %s\n",
-                argv[0], strerror(errno));
+                argv[0], ovs_strerror(errno));
         _exit(1);
     }
 }
@@ -308,7 +316,7 @@ process_run(void)
                     p->exited = true;
                     p->status = status;
                 } else if (retval < 0) {
-                    VLOG_WARN("waitpid: %s", strerror(errno));
+                    VLOG_WARN("waitpid: %s", ovs_strerror(errno));
                     p->exited = true;
                     p->status = -1;
                 }