On today's systems fork() will hardly fail, thus removed the fork retry loops.
[mmh] / sbr / push.c
1 /*
2 ** push.c -- push a fork into the background
3 **
4 ** This code is Copyright (c) 2002, by the authors of nmh.  See the
5 ** COPYRIGHT file in the root directory of the nmh distribution for
6 ** complete copyright information.
7 */
8
9 #include <h/mh.h>
10 #include <h/signals.h>
11 #include <signal.h>
12
13
14 void
15 push(void)
16 {
17         pid_t pid;
18
19         switch (pid = fork()) {
20         case -1:
21                 /* fork error */
22                 advise(NULL, "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                 freopen("/dev/null", "r", stdin);
37                 freopen("/dev/null", "w", stdout);
38                 break;
39
40         default:
41                 /* parent, just exit */
42                 done(0);
43         }
44 }