summaryrefslogtreecommitdiff
path: root/gnu/libexec/uucp/libunix/run.c
diff options
context:
space:
mode:
Diffstat (limited to 'gnu/libexec/uucp/libunix/run.c')
-rw-r--r--gnu/libexec/uucp/libunix/run.c52
1 files changed, 45 insertions, 7 deletions
diff --git a/gnu/libexec/uucp/libunix/run.c b/gnu/libexec/uucp/libunix/run.c
index e219196283722..af9b078d3bd93 100644
--- a/gnu/libexec/uucp/libunix/run.c
+++ b/gnu/libexec/uucp/libunix/run.c
@@ -1,7 +1,7 @@
/* run.c
Run a program.
- Copyright (C) 1992 Ian Lance Taylor
+ Copyright (C) 1992, 1993, 1994 Ian Lance Taylor
This file is part of the Taylor UUCP package.
@@ -20,7 +20,7 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
The author of the program may be contacted at ian@airs.com or
- c/o Infinity Development Systems, P.O. Box 520, Waltham, MA 02254.
+ c/o Cygnus Support, Building 200, 1 Kendall Square, Cambridge, MA 02139.
*/
#include "uucp.h"
@@ -31,13 +31,11 @@
#include <errno.h>
-/* Start up a new program and end the current one. We don't have to
- worry about SIGHUP because the current process is either not a
- process group leader (uucp, uux) or it does not have a controlling
- terminal (uucico). */
+/* Start up a new program. */
boolean
-fsysdep_run (zprogram, zarg1, zarg2)
+fsysdep_run (ffork, zprogram, zarg1, zarg2)
+ boolean ffork;
const char *zprogram;
const char *zarg1;
const char *zarg2;
@@ -47,6 +45,40 @@ fsysdep_run (zprogram, zarg1, zarg2)
int aidescs[3];
pid_t ipid;
+ /* If we are supposed to fork, fork and then spawn so that we don't
+ have to worry about zombie processes. */
+ if (ffork)
+ {
+ ipid = ixsfork ();
+ if (ipid < 0)
+ {
+ ulog (LOG_ERROR, "fork: %s", strerror (errno));
+ return FALSE;
+ }
+
+ if (ipid != 0)
+ {
+ /* This is the parent. Wait for the child we just forked to
+ exit (below) and return. */
+ (void) ixswait ((unsigned long) ipid, (const char *) NULL);
+
+ /* Force the log files to be reopened in case the child just
+ output any error messages and stdio doesn't handle
+ appending correctly. */
+ ulog_close ();
+
+ return TRUE;
+ }
+
+ /* This is the child. Detach from the terminal to avoid any
+ unexpected SIGHUP signals. At this point we are definitely
+ not a process group leader, so usysdep_detach will not fork
+ again. */
+ usysdep_detach ();
+
+ /* Now spawn the program and then exit. */
+ }
+
zlib = zbufalc (sizeof SBINDIR + sizeof "/" + strlen (zprogram));
sprintf (zlib, "%s/%s", SBINDIR, zprogram);
@@ -65,11 +97,17 @@ fsysdep_run (zprogram, zarg1, zarg2)
FALSE, TRUE, (const char *) NULL,
(const char *) NULL, (const char *) NULL);
ubuffree (zlib);
+
if (ipid < 0)
{
ulog (LOG_ERROR, "ixsspawn: %s", strerror (errno));
+ if (ffork)
+ _exit (EXIT_FAILURE);
return FALSE;
}
+ if (ffork)
+ _exit (EXIT_SUCCESS);
+
return TRUE;
}