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