Make WvStreams compile with gcc 4.4.
[wvstreams.git] / include / wvfork.h
blob90da1e1ceeb287a7c7515225f43920002ca8ec94
1 /* -*- Mode: C++ -*-
2 * Worldvisions Weaver Software:
3 * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
4 */
5 /** \file
6 * Provides support for forking processes.
7 */
9 #ifndef __WVFORK_H
10 #define __WVFORK_H
12 #ifndef _WIN32
13 #include <unistd.h>
14 #else
15 typedef int pid_t;
16 #endif
18 #include "wvscatterhash.h"
19 #include "wvtr1.h"
21 DeclareWvScatterTable(int);
22 typedef wv::function<void(pid_t)> WvForkCallback;
24 /**
25 * Register a callback to be called during wvfork.
26 * It will be called (in both parent and child process) after the fork has
27 * happened but before wvfork returns. It is passed the return value of the
28 * fork.
30 * NOTE: There is no way to undo this operation!
32 extern void add_wvfork_callback(WvForkCallback cb);
34 /**
35 * wvfork_start is just like fork, except that it will block the
36 * parent until the child process closes the waitfd, to avoid race
37 * conditions.
39 * For example, wvfork uses it, closing the waitfd only when it is
40 * done closing the close-on-exec file descriptors.
42 extern pid_t wvfork_start(int *waitfd);
44 /**
45 * wvfork() just runs fork(), but it closes all file descriptors that
46 * are flagged close-on-exec, since we don't necessarily always run
47 * exec() after we fork()...
49 * This fixes the year-old mystery bug where WvTapeBackup caused
50 * watchdog reboots because the CHILD process wasn't touching it, and
51 * it was already open before the fork()...
53 extern pid_t wvfork(int dontclose1 = -1, int dontclose2 = -1);
54 extern pid_t wvfork(intTable &dontclose );
56 #endif