Added support for optional Content_Disposition header in mhbuild directive.s
[mmh] / sbr / push.c
1
2 /*
3  * push.c -- push a fork into the background
4  *
5  * $Id$
6  *
7  * This code is Copyright (c) 2002, by the authors of nmh.  See the
8  * COPYRIGHT file in the root directory of the nmh distribution for
9  * complete copyright information.
10  */
11
12 #include <h/mh.h>
13 #include <h/signals.h>
14 #include <signal.h>
15
16
17 void
18 push(void)
19 {
20     pid_t pid;
21     int i;
22
23     for (i = 0; (pid = fork()) == -1 && i < 5; i++)
24         sleep (5);
25
26     switch (pid) {
27         case -1:
28             /* fork error */
29             advise (NULL, "unable to fork, so can't push...");
30             break;
31
32         case 0:
33             /* child, block a few signals and continue */
34             SIGNAL (SIGHUP, SIG_IGN);
35             SIGNAL (SIGINT, SIG_IGN);
36             SIGNAL (SIGQUIT, SIG_IGN);
37             SIGNAL (SIGTERM, SIG_IGN);
38 #ifdef SIGTSTP
39             SIGNAL (SIGTSTP, SIG_IGN);
40             SIGNAL (SIGTTIN, SIG_IGN);
41             SIGNAL (SIGTTOU, SIG_IGN);
42 #endif
43             freopen ("/dev/null", "r", stdin);
44             freopen ("/dev/null", "w", stdout);
45             break;
46
47         default:
48             /* parent, just exit */
49             done (0);
50     }
51 }
52