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