]> diplodocus.org Git - nmh/blob - sbr/push.c
new.c: Order two return statements to match comment.
[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 <h/signals.h>
10 #include "m_mktemp.h"
11
12
13 void
14 push(void)
15 {
16 pid_t pid;
17
18 pid = fork();
19 switch (pid) {
20 case -1:
21 /* fork error */
22 inform("unable to fork, so can't push...");
23 break;
24
25 case 0:
26 /* child, block a few signals and continue */
27 SIGNAL (SIGHUP, SIG_IGN);
28 SIGNAL (SIGINT, SIG_IGN);
29 SIGNAL (SIGQUIT, SIG_IGN);
30 SIGNAL (SIGTERM, SIG_IGN);
31 #ifdef SIGTSTP
32 SIGNAL (SIGTSTP, SIG_IGN);
33 SIGNAL (SIGTTIN, SIG_IGN);
34 SIGNAL (SIGTTOU, SIG_IGN);
35 #endif
36
37 unregister_for_removal(0);
38
39 if (freopen ("/dev/null", "r", stdin) == NULL) {
40 advise ("stdin", "freopen");
41 }
42 if (freopen ("/dev/null", "w", stdout) == NULL) {
43 advise ("stdout", "freopen");
44 }
45 break;
46
47 default:
48 /* parent, just exit */
49 done (0);
50 }
51 }