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