+\f
+/* Asserts that the process has not yet created any threads (beyond the initial
+ * thread). */
+void
+(assert_single_threaded)(const char *where)
+{
+ if (multithreaded) {
+ VLOG_FATAL("%s: attempted operation not allowed when multithreaded",
+ where);
+ }
+}
+
+/* Forks the current process (checking that this is allowed). Aborts with
+ * VLOG_FATAL if fork() returns an error, and otherwise returns the value
+ * returned by fork(). */
+pid_t
+(xfork)(const char *where)
+{
+ pid_t pid;
+
+ if (must_not_fork) {
+ VLOG_FATAL("%s: attempted to fork but forking not allowed (%s)",
+ where, must_not_fork);
+ }
+
+ pid = fork();
+ if (pid < 0) {
+ VLOG_FATAL("fork failed (%s)", strerror(errno));
+ }
+ return pid;
+}
+
+/* Notes that the process must not call fork() from now on, for the specified
+ * 'reason'. (The process may still fork() if it execs itself immediately
+ * afterward.) */
+void
+forbid_forking(const char *reason)
+{
+ ovs_assert(reason != NULL);
+ must_not_fork = reason;
+}
+
+/* Returns true if the process is allowed to fork, false otherwise. */
+bool
+may_fork(void)
+{
+ return !must_not_fork;
+}