2 * This file has been modified for the cdrkit suite.
4 * The behaviour and appearence of the program code below can differ to a major
5 * extent from the version distributed by the original author(s).
7 * For details, see Changelog file distributed with the cdrkit package. If you
8 * received this file from another source then ask the distributing person for
9 * a log of modifications.
13 /* @(#)spawn.c 1.17 04/09/25 Copyright 1985, 1989, 1995-2003 J. Schilling */
15 * Spawn another process/ wait for child process
17 * Copyright (c) 1985, 1989, 1995-2003 J. Schilling
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License version 2
22 * as published by the Free Software Foundation.
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
29 * You should have received a copy of the GNU General Public License along with
30 * this program; see the file COPYING. If not, write to the Free Software
31 * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
37 #define fspawnl __nothing__ /* prototype in schily.h is wrong */
38 #define spawnl __nothing__ /* prototype in schily.h is wrong */
50 EXPORT int fspawnl __PR((FILE *, FILE *, FILE *, ...));
53 fspawnv(in, out, err, argc, argv)
62 if ((pid = fspawnv_nowait(in, out, err, argv[0], argc, argv)) < 0)
65 return (wait_chld(pid));
71 fspawnl(FILE *in, FILE *out, FILE *err, ...)
74 fspawnl(in, out, err, va_alist)
83 char *xav[MAX_F_ARGS];
94 while (va_arg(args, char *) != NULL)
98 if (ac < MAX_F_ARGS) {
101 pav = av = (char **)malloc((ac+1)*sizeof (char *));
112 p = va_arg(args, char *);
117 ret = fspawnv(in, out, err, ac, av);
124 fspawnv_nowait(in, out, err, name, argc, argv)
132 int pid = -1; /* Initialization needed to make GCC happy */
135 for (i = 1; i < 64; i *= 2) {
136 if ((pid = fork()) >= 0)
143 * silly: fexecv must set av[ac] = NULL
144 * so we have to cast argv tp (char **)
146 rols_fexecv(name, in, out, err, argc, (char **)argv);
160 died = wait(&status);
161 } while (died < 0 && geterrno() == EINTR);
164 } while (died != pid);
166 if (WCOREDUMP(status))
169 return (WEXITSTATUS(status));