mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
cleanup: libast: remove pre-fork(2) code (re: 7b0e0776
)
I had removed the legacy code for systems without fork(2) from ksh93, but not from libast. This commit deos that.
This commit is contained in:
parent
7a06d911e0
commit
7af1d56e7f
7 changed files with 71 additions and 141 deletions
|
@ -65,18 +65,11 @@ CHAR_MAX C XX 1 L
|
||||||
CHAR_MIN C XX 1 L
|
CHAR_MIN C XX 1 L
|
||||||
CHAR_TERM POSIX SC 2 FUW
|
CHAR_TERM POSIX SC 2 FUW
|
||||||
CHILD_MAX POSIX SC 1 CDLMUX 6 cc{
|
CHILD_MAX POSIX SC 1 CDLMUX 6 cc{
|
||||||
#if _lib_fork
|
|
||||||
#define child() fork()
|
|
||||||
#else
|
|
||||||
extern int spawnve(const char*, char* const[], char* const[]);
|
|
||||||
static char* cmd[] = { "/bin/echo", 0 };
|
|
||||||
#define child() spawnve(cmd[0],cmd,(char**)0)
|
|
||||||
#endif
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int n;
|
int n;
|
||||||
for (i = 3; i < 512 && (n = child()) >= 0; i++)
|
for (i = 3; i < 512 && (n = fork()) >= 0; i++)
|
||||||
if (!n) _exit(0);
|
if (!n) _exit(0);
|
||||||
while (wait((int*)0) > 0);
|
while (wait((int*)0) > 0);
|
||||||
for (n = 8; n < i; n <<= 1);
|
for (n = 8; n < i; n <<= 1);
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* *
|
* *
|
||||||
* This software is part of the ast package *
|
* This software is part of the ast package *
|
||||||
* Copyright (c) 1985-2012 AT&T Intellectual Property *
|
* Copyright (c) 1985-2012 AT&T Intellectual Property *
|
||||||
* Copyright (c) 2020-2021 Contributors to ksh 93u+m *
|
* Copyright (c) 2020-2022 Contributors to ksh 93u+m *
|
||||||
* and is licensed under the *
|
* and is licensed under the *
|
||||||
* Eclipse Public License, Version 1.0 *
|
* Eclipse Public License, Version 1.0 *
|
||||||
* by AT&T Intellectual Property *
|
* by AT&T Intellectual Property *
|
||||||
|
@ -65,24 +65,6 @@ setsid(void)
|
||||||
ioctl(fd, TIOCNOTTY, 0);
|
ioctl(fd, TIOCNOTTY, 0);
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
|
|
||||||
/*
|
|
||||||
* second child in s5 to avoid reacquiring the control tty
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if _lib_fork && HUH920711 /* some s5's botch this */
|
|
||||||
switch (fork())
|
|
||||||
{
|
|
||||||
case -1:
|
|
||||||
exit(1);
|
|
||||||
case 0:
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
return(pg);
|
return(pg);
|
||||||
}
|
}
|
||||||
|
|
|
@ -174,7 +174,6 @@ spawnveg(const char* path, char* const argv[], char* const envv[], pid_t pgid, i
|
||||||
pid_t
|
pid_t
|
||||||
spawnveg(const char* path, char* const argv[], char* const envv[], pid_t pgid, int tcfd)
|
spawnveg(const char* path, char* const argv[], char* const envv[], pid_t pgid, int tcfd)
|
||||||
{
|
{
|
||||||
#if _lib_fork || _lib_vfork
|
|
||||||
int n;
|
int n;
|
||||||
int m;
|
int m;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
|
@ -184,19 +183,15 @@ spawnveg(const char* path, char* const argv[], char* const envv[], pid_t pgid, i
|
||||||
volatile int* volatile exec_errno_ptr;
|
volatile int* volatile exec_errno_ptr;
|
||||||
#else
|
#else
|
||||||
int err[2];
|
int err[2];
|
||||||
#endif
|
#endif /* _real_vfork */
|
||||||
#endif
|
|
||||||
|
|
||||||
NOT_USED(tcfd);
|
NOT_USED(tcfd);
|
||||||
if (!envv)
|
if (!envv)
|
||||||
envv = environ;
|
envv = environ;
|
||||||
#if _lib_spawnve
|
#if _lib_spawnve
|
||||||
#if _lib_fork || _lib_vfork
|
|
||||||
if (!pgid)
|
if (!pgid)
|
||||||
#endif
|
|
||||||
return spawnve(path, argv, envv);
|
return spawnve(path, argv, envv);
|
||||||
#endif
|
#endif /* _lib_spawnve */
|
||||||
#if _lib_fork || _lib_vfork
|
|
||||||
n = errno;
|
n = errno;
|
||||||
#if _real_vfork
|
#if _real_vfork
|
||||||
exec_errno = 0;
|
exec_errno = 0;
|
||||||
|
@ -209,13 +204,13 @@ spawnveg(const char* path, char* const argv[], char* const envv[], pid_t pgid, i
|
||||||
fcntl(err[0], F_SETFD, FD_CLOEXEC);
|
fcntl(err[0], F_SETFD, FD_CLOEXEC);
|
||||||
fcntl(err[1], F_SETFD, FD_CLOEXEC);
|
fcntl(err[1], F_SETFD, FD_CLOEXEC);
|
||||||
}
|
}
|
||||||
#endif
|
#endif /* _real_vfork */
|
||||||
sigcritical(SIG_REG_EXEC|SIG_REG_PROC);
|
sigcritical(SIG_REG_EXEC|SIG_REG_PROC);
|
||||||
#if _lib_vfork
|
#if _lib_vfork
|
||||||
pid = vfork();
|
pid = vfork();
|
||||||
#else
|
#else
|
||||||
pid = fork();
|
pid = fork();
|
||||||
#endif
|
#endif /* _lib_vfork */
|
||||||
if (pid == -1)
|
if (pid == -1)
|
||||||
n = errno;
|
n = errno;
|
||||||
else if (!pid)
|
else if (!pid)
|
||||||
|
@ -236,7 +231,7 @@ spawnveg(const char* path, char* const argv[], char* const envv[], pid_t pgid, i
|
||||||
#elif defined(TIOCSPGRP)
|
#elif defined(TIOCSPGRP)
|
||||||
if (m)
|
if (m)
|
||||||
ioctl(2, TIOCSPGRP, &pgid);
|
ioctl(2, TIOCSPGRP, &pgid);
|
||||||
#endif
|
#endif /* _lib_tcgetpgrp */
|
||||||
}
|
}
|
||||||
execve(path, argv, envv);
|
execve(path, argv, envv);
|
||||||
#if _real_vfork
|
#if _real_vfork
|
||||||
|
@ -247,7 +242,7 @@ spawnveg(const char* path, char* const argv[], char* const envv[], pid_t pgid, i
|
||||||
m = errno;
|
m = errno;
|
||||||
write(err[1], &m, sizeof(m));
|
write(err[1], &m, sizeof(m));
|
||||||
}
|
}
|
||||||
#endif
|
#endif /* _real_vfork */
|
||||||
_exit(errno == ENOENT ? EXIT_NOTFOUND : EXIT_NOEXEC);
|
_exit(errno == ENOENT ? EXIT_NOTFOUND : EXIT_NOEXEC);
|
||||||
}
|
}
|
||||||
rid = pid;
|
rid = pid;
|
||||||
|
@ -280,7 +275,7 @@ spawnveg(const char* path, char* const argv[], char* const envv[], pid_t pgid, i
|
||||||
}
|
}
|
||||||
close(err[0]);
|
close(err[0]);
|
||||||
}
|
}
|
||||||
#endif
|
#endif /* _real_vfork */
|
||||||
sigcritical(0);
|
sigcritical(0);
|
||||||
if (pid != -1 && pgid > 0)
|
if (pid != -1 && pgid > 0)
|
||||||
{
|
{
|
||||||
|
@ -295,10 +290,6 @@ spawnveg(const char* path, char* const argv[], char* const envv[], pid_t pgid, i
|
||||||
}
|
}
|
||||||
errno = n;
|
errno = n;
|
||||||
return rid;
|
return rid;
|
||||||
#else
|
|
||||||
errno = ENOSYS;
|
|
||||||
return -1;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* *
|
* *
|
||||||
* This software is part of the ast package *
|
* This software is part of the ast package *
|
||||||
* Copyright (c) 1985-2011 AT&T Intellectual Property *
|
* Copyright (c) 1985-2011 AT&T Intellectual Property *
|
||||||
* Copyright (c) 2020-2021 Contributors to ksh 93u+m *
|
* Copyright (c) 2020-2022 Contributors to ksh 93u+m *
|
||||||
* and is licensed under the *
|
* and is licensed under the *
|
||||||
* Eclipse Public License, Version 1.0 *
|
* Eclipse Public License, Version 1.0 *
|
||||||
* by AT&T Intellectual Property *
|
* by AT&T Intellectual Property *
|
||||||
|
@ -40,12 +40,7 @@ NoN(vfork)
|
||||||
extern pid_t
|
extern pid_t
|
||||||
vfork(void)
|
vfork(void)
|
||||||
{
|
{
|
||||||
#if _lib_fork
|
|
||||||
return(fork());
|
return(fork());
|
||||||
#else
|
|
||||||
errno = ENOSYS;
|
|
||||||
return -1;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -64,6 +64,9 @@ struct _sfio_s;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <ast_lib.h>
|
#include <ast_lib.h>
|
||||||
|
#if !_lib_fork
|
||||||
|
#error In 2022, libast joined the 21st century and started requiring fork(2).
|
||||||
|
#endif
|
||||||
#include <ast_sys.h>
|
#include <ast_sys.h>
|
||||||
#include <ast_getopt.h> /* <stdlib.h> does this */
|
#include <ast_getopt.h> /* <stdlib.h> does this */
|
||||||
#include <ast_fcntl.h>
|
#include <ast_fcntl.h>
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
..
|
..
|
||||||
.TH PROC 3
|
.TH PROC 3
|
||||||
.SH NAME
|
.SH NAME
|
||||||
proc \- process control routines
|
proc \- process control routines (deprecated)
|
||||||
.SH SYNOPSIS
|
.SH SYNOPSIS
|
||||||
.EX
|
.EX
|
||||||
#include <proc.h>
|
#include <proc.h>
|
||||||
|
@ -50,14 +50,15 @@ int procrun(const char* \fIcommand\fP, char** \fIargv\fP);
|
||||||
.EE
|
.EE
|
||||||
.SH DESCRIPTION
|
.SH DESCRIPTION
|
||||||
These routines provide a portable interface to process creation and execution.
|
These routines provide a portable interface to process creation and execution.
|
||||||
They work on systems with
|
They used to work on systems with only
|
||||||
.IR fork (2)
|
|
||||||
and
|
|
||||||
.IR exec (2)
|
|
||||||
as well as on systems with only
|
|
||||||
.IR spawnve (2)
|
.IR spawnve (2)
|
||||||
or
|
or
|
||||||
.IR spawnveg (3).
|
.IR spawnveg (3).
|
||||||
|
Now that libast has joined the 21st century and requires
|
||||||
|
.IR fork (2)
|
||||||
|
and
|
||||||
|
.IR execve (2),
|
||||||
|
this interface is deprecated and only kept for backward compatibility.
|
||||||
.PP
|
.PP
|
||||||
.L procopen
|
.L procopen
|
||||||
runs
|
runs
|
||||||
|
|
|
@ -40,19 +40,11 @@
|
||||||
* not quite ready for _use_spawnveg
|
* not quite ready for _use_spawnveg
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if _use_spawnveg
|
|
||||||
#if _lib_fork
|
|
||||||
#undef _use_spawnveg
|
#undef _use_spawnveg
|
||||||
#else
|
|
||||||
#if _WINIX
|
|
||||||
#define _lib_fork 1
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef DEBUG_PROC
|
#ifndef DEBUG_PROC
|
||||||
#define DEBUG_PROC 1
|
#define DEBUG_PROC 1
|
||||||
#endif
|
#endif /* DEBUG_PROC */
|
||||||
|
|
||||||
#if _lib_socketpair
|
#if _lib_socketpair
|
||||||
#if _sys_socket
|
#if _sys_socket
|
||||||
|
@ -60,8 +52,8 @@
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#else
|
#else
|
||||||
#undef _lib_socketpair
|
#undef _lib_socketpair
|
||||||
#endif
|
#endif /* _sys_socket */
|
||||||
#endif
|
#endif /* _lib_socketpair */
|
||||||
|
|
||||||
Proc_t proc_default = { -1 };
|
Proc_t proc_default = { -1 };
|
||||||
|
|
||||||
|
@ -104,7 +96,7 @@ setopt(register void* a, register const void* p, register int n, const char* v)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif /* DEBUG_PROC */
|
||||||
|
|
||||||
#if _use_spawnveg
|
#if _use_spawnveg
|
||||||
|
|
||||||
|
@ -135,7 +127,7 @@ typedef struct Mod_s
|
||||||
|
|
||||||
} Modify_t;
|
} Modify_t;
|
||||||
|
|
||||||
#endif
|
#endif /* _use_spawnveg */
|
||||||
|
|
||||||
#ifdef SIGPIPE
|
#ifdef SIGPIPE
|
||||||
|
|
||||||
|
@ -150,7 +142,7 @@ ignoresig(int sig)
|
||||||
signal(sig, ignoresig);
|
signal(sig, ignoresig);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif /* SIGPIPE */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* do modification op and save previous state for restore()
|
* do modification op and save previous state for restore()
|
||||||
|
@ -159,13 +151,12 @@ ignoresig(int sig)
|
||||||
static int
|
static int
|
||||||
modify(Proc_t* proc, int forked, int op, long arg1, long arg2)
|
modify(Proc_t* proc, int forked, int op, long arg1, long arg2)
|
||||||
{
|
{
|
||||||
#if _lib_fork
|
|
||||||
if (forked)
|
if (forked)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
#ifndef TIOCSCTTY
|
#ifndef TIOCSCTTY
|
||||||
char* s;
|
char* s;
|
||||||
#endif
|
#endif /* !TIOCSCTTY */
|
||||||
|
|
||||||
switch (op)
|
switch (op)
|
||||||
{
|
{
|
||||||
|
@ -199,7 +190,7 @@ modify(Proc_t* proc, int forked, int op, long arg1, long arg2)
|
||||||
return -1;
|
return -1;
|
||||||
if ((arg2 = open(s, O_RDWR)) < 0)
|
if ((arg2 = open(s, O_RDWR)) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
#endif
|
#endif /* TIOCSCTTY */
|
||||||
for (i = 0; i <= 2; i++)
|
for (i = 0; i <= 2; i++)
|
||||||
if (arg1 != i && arg2 != i && fcntl(arg1, F_DUPFD, i) != i)
|
if (arg1 != i && arg2 != i && fcntl(arg1, F_DUPFD, i) != i)
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -234,11 +225,6 @@ modify(Proc_t* proc, int forked, int op, long arg1, long arg2)
|
||||||
}
|
}
|
||||||
#if _use_spawnveg
|
#if _use_spawnveg
|
||||||
else
|
else
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
NoP(forked);
|
|
||||||
#endif
|
|
||||||
#if _use_spawnveg
|
|
||||||
{
|
{
|
||||||
register Modify_t* m;
|
register Modify_t* m;
|
||||||
|
|
||||||
|
@ -266,7 +252,7 @@ modify(Proc_t* proc, int forked, int op, long arg1, long arg2)
|
||||||
}
|
}
|
||||||
#if F_dupfd_cloexec == F_DUPFD
|
#if F_dupfd_cloexec == F_DUPFD
|
||||||
fcntl(m->save, F_SETFD, FD_CLOEXEC);
|
fcntl(m->save, F_SETFD, FD_CLOEXEC);
|
||||||
#endif
|
#endif /* F_dupfd_cloexec == F_DUPFD */
|
||||||
close(arg2);
|
close(arg2);
|
||||||
if (fcntl(arg1, F_DUPFD, arg2) != arg2)
|
if (fcntl(arg1, F_DUPFD, arg2) != arg2)
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -313,7 +299,7 @@ modify(Proc_t* proc, int forked, int op, long arg1, long arg2)
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
NoP(proc);
|
NoP(proc);
|
||||||
#endif
|
#endif /* _use_spawnveg */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -383,7 +369,7 @@ restore(Proc_t* proc)
|
||||||
|
|
||||||
#define restore(p)
|
#define restore(p)
|
||||||
|
|
||||||
#endif
|
#endif /* _use_spawnveg */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* fork and exec or spawn proc(argv) and return a Proc_t handle
|
* fork and exec or spawn proc(argv) and return a Proc_t handle
|
||||||
|
@ -410,38 +396,30 @@ procopen(const char* cmd, char** argv, char** envv, long* modv, int flags)
|
||||||
char path[PATH_MAX];
|
char path[PATH_MAX];
|
||||||
char env[PATH_MAX + 2];
|
char env[PATH_MAX + 2];
|
||||||
int pio[2];
|
int pio[2];
|
||||||
#if _lib_fork
|
|
||||||
int pop[2];
|
int pop[2];
|
||||||
#endif
|
|
||||||
#if !_pipe_rw && !_lib_socketpair
|
#if !_pipe_rw && !_lib_socketpair
|
||||||
int poi[2];
|
int poi[2];
|
||||||
#endif
|
#endif /* !_pipe_rw && !_lib_socketpair */
|
||||||
#if defined(SIGCHLD) && ( _lib_sigprocmask || _lib_sigsetmask )
|
#if defined(SIGCHLD) && ( _lib_sigprocmask || _lib_sigsetmask )
|
||||||
Sig_mask_t mask;
|
Sig_mask_t mask;
|
||||||
#endif
|
#endif /* defined(SIGCHLD) && ( _lib_sigprocmask || _lib_sigsetmask ) */
|
||||||
#if _use_spawnveg
|
#if _use_spawnveg
|
||||||
int newenv = 0;
|
int newenv = 0;
|
||||||
#endif
|
#endif /* _use_spawnveg */
|
||||||
#if DEBUG_PROC
|
#if DEBUG_PROC
|
||||||
int debug = PROC_OPT_EXEC;
|
int debug = PROC_OPT_EXEC;
|
||||||
#endif
|
#endif /* DEBUG_PROC */
|
||||||
|
|
||||||
#if _lib_fork
|
|
||||||
if (!argv && (flags & (PROC_ORPHAN|PROC_OVERLAY)))
|
if (!argv && (flags & (PROC_ORPHAN|PROC_OVERLAY)))
|
||||||
#else
|
|
||||||
if (!argv || (flags & PROC_ORPHAN))
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
errno = ENOEXEC;
|
errno = ENOEXEC;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
pio[0] = pio[1] = -1;
|
pio[0] = pio[1] = -1;
|
||||||
#if _lib_fork
|
|
||||||
pop[0] = pop[1] = -1;
|
pop[0] = pop[1] = -1;
|
||||||
#endif
|
|
||||||
#if !_pipe_rw && !_lib_socketpair
|
#if !_pipe_rw && !_lib_socketpair
|
||||||
poi[0] = poi[1] = -1;
|
poi[0] = poi[1] = -1;
|
||||||
#endif
|
#endif /* !_pipe_rw && !_lib_socketpair */
|
||||||
if (cmd && (!*cmd || !pathpath(cmd, NiL, PATH_REGULAR|PATH_EXECUTE, path, sizeof(path))))
|
if (cmd && (!*cmd || !pathpath(cmd, NiL, PATH_REGULAR|PATH_EXECUTE, path, sizeof(path))))
|
||||||
goto bad;
|
goto bad;
|
||||||
switch (flags & (PROC_READ|PROC_WRITE))
|
switch (flags & (PROC_READ|PROC_WRITE))
|
||||||
|
@ -476,7 +454,7 @@ procopen(const char* cmd, char** argv, char** envv, long* modv, int flags)
|
||||||
#if _use_spawnveg
|
#if _use_spawnveg
|
||||||
if (!(flags & PROC_ORPHAN))
|
if (!(flags & PROC_ORPHAN))
|
||||||
newenv = 1;
|
newenv = 1;
|
||||||
#endif
|
#endif /* _use_spawnveg */
|
||||||
}
|
}
|
||||||
if (procfd >= 0)
|
if (procfd >= 0)
|
||||||
{
|
{
|
||||||
|
@ -492,11 +470,11 @@ procopen(const char* cmd, char** argv, char** envv, long* modv, int flags)
|
||||||
#else
|
#else
|
||||||
if (pipe(pio) || pipe(poi))
|
if (pipe(pio) || pipe(poi))
|
||||||
goto bad;
|
goto bad;
|
||||||
#endif
|
#endif /* _lib_socketpair */
|
||||||
}
|
}
|
||||||
else if (pipe(pio))
|
else if (pipe(pio))
|
||||||
goto bad;
|
goto bad;
|
||||||
#endif
|
#endif /* _pipe_rw */
|
||||||
}
|
}
|
||||||
if (flags & PROC_OVERLAY)
|
if (flags & PROC_OVERLAY)
|
||||||
{
|
{
|
||||||
|
@ -506,8 +484,7 @@ procopen(const char* cmd, char** argv, char** envv, long* modv, int flags)
|
||||||
#if _use_spawnveg
|
#if _use_spawnveg
|
||||||
else if (argv && !(flags & PROC_ORPHAN))
|
else if (argv && !(flags & PROC_ORPHAN))
|
||||||
proc->pid = 0;
|
proc->pid = 0;
|
||||||
#endif
|
#endif /* _use_spawnveg */
|
||||||
#if _lib_fork
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!(flags & PROC_FOREGROUND))
|
if (!(flags & PROC_FOREGROUND))
|
||||||
|
@ -528,9 +505,9 @@ procopen(const char* cmd, char** argv, char** envv, long* modv, int flags)
|
||||||
proc->mask = sigblock(mask);
|
proc->mask = sigblock(mask);
|
||||||
#else
|
#else
|
||||||
proc->sigchld = signal(SIGCHLD, SIG_DFL);
|
proc->sigchld = signal(SIGCHLD, SIG_DFL);
|
||||||
#endif
|
#endif /* _lib_sigsetmask */
|
||||||
#endif
|
#endif /* _lib_sigprocmask */
|
||||||
#endif
|
#endif /* defined(SIGCHLD) */
|
||||||
}
|
}
|
||||||
if ((flags & PROC_ORPHAN) && pipe(pop))
|
if ((flags & PROC_ORPHAN) && pipe(pop))
|
||||||
goto bad;
|
goto bad;
|
||||||
|
@ -558,15 +535,14 @@ procopen(const char* cmd, char** argv, char** envv, long* modv, int flags)
|
||||||
#else
|
#else
|
||||||
if (proc->sigchld != SIG_IGN)
|
if (proc->sigchld != SIG_IGN)
|
||||||
signal(SIGCHLD, SIG_DFL);
|
signal(SIGCHLD, SIG_DFL);
|
||||||
#endif
|
#endif /* _lib_sigsetmask */
|
||||||
#endif
|
#endif /* _lib_sigprocmask */
|
||||||
#endif
|
#endif /* defined(SIGCHLD) */
|
||||||
}
|
}
|
||||||
else if (proc->pid == -1)
|
else if (proc->pid == -1)
|
||||||
goto bad;
|
goto bad;
|
||||||
forked = 1;
|
forked = 1;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
if (!proc->pid)
|
if (!proc->pid)
|
||||||
{
|
{
|
||||||
#if _use_spawnveg
|
#if _use_spawnveg
|
||||||
|
@ -574,8 +550,7 @@ procopen(const char* cmd, char** argv, char** envv, long* modv, int flags)
|
||||||
char* oenviron0 = 0;
|
char* oenviron0 = 0;
|
||||||
|
|
||||||
v = 0;
|
v = 0;
|
||||||
#endif
|
#endif /* _use_spawnveg */
|
||||||
#if _lib_fork
|
|
||||||
if (flags & PROC_ORPHAN)
|
if (flags & PROC_ORPHAN)
|
||||||
{
|
{
|
||||||
if (!(proc->pid = fork()))
|
if (!(proc->pid = fork()))
|
||||||
|
@ -590,10 +565,8 @@ procopen(const char* cmd, char** argv, char** envv, long* modv, int flags)
|
||||||
_exit(EXIT_NOEXEC);
|
_exit(EXIT_NOEXEC);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
#if DEBUG_PROC
|
#if DEBUG_PROC
|
||||||
stropt(getenv(PROC_ENV_OPTIONS), options, sizeof(*options), setopt, &debug);
|
stropt(getenv(PROC_ENV_OPTIONS), options, sizeof(*options), setopt, &debug);
|
||||||
#if _lib_fork
|
|
||||||
if (debug & PROC_OPT_TRACE)
|
if (debug & PROC_OPT_TRACE)
|
||||||
{
|
{
|
||||||
if (!fork())
|
if (!fork())
|
||||||
|
@ -604,30 +577,29 @@ procopen(const char* cmd, char** argv, char** envv, long* modv, int flags)
|
||||||
}
|
}
|
||||||
sleep(2);
|
sleep(2);
|
||||||
}
|
}
|
||||||
#endif
|
#endif /* DEBUG_PROC */
|
||||||
#endif
|
|
||||||
if (flags & PROC_DAEMON)
|
if (flags & PROC_DAEMON)
|
||||||
{
|
{
|
||||||
#ifdef SIGHUP
|
#ifdef SIGHUP
|
||||||
modify(proc, forked, PROC_sig_ign, SIGHUP, 0);
|
modify(proc, forked, PROC_sig_ign, SIGHUP, 0);
|
||||||
#endif
|
#endif /* SIGHUP */
|
||||||
modify(proc, forked, PROC_sig_dfl, SIGTERM, 0);
|
modify(proc, forked, PROC_sig_dfl, SIGTERM, 0);
|
||||||
#ifdef SIGTSTP
|
#ifdef SIGTSTP
|
||||||
modify(proc, forked, PROC_sig_ign, SIGTSTP, 0);
|
modify(proc, forked, PROC_sig_ign, SIGTSTP, 0);
|
||||||
#endif
|
#endif /* SIGTSTP */
|
||||||
#ifdef SIGTTIN
|
#ifdef SIGTTIN
|
||||||
modify(proc, forked, PROC_sig_ign, SIGTTIN, 0);
|
modify(proc, forked, PROC_sig_ign, SIGTTIN, 0);
|
||||||
#endif
|
#endif /* SIGTTIN */
|
||||||
#ifdef SIGTTOU
|
#ifdef SIGTTOU
|
||||||
modify(proc, forked, PROC_sig_ign, SIGTTOU, 0);
|
modify(proc, forked, PROC_sig_ign, SIGTTOU, 0);
|
||||||
#endif
|
#endif /* SIGTTOU */
|
||||||
}
|
}
|
||||||
if (flags & (PROC_BACKGROUND|PROC_DAEMON))
|
if (flags & (PROC_BACKGROUND|PROC_DAEMON))
|
||||||
{
|
{
|
||||||
modify(proc, forked, PROC_sig_ign, SIGINT, 0);
|
modify(proc, forked, PROC_sig_ign, SIGINT, 0);
|
||||||
#ifdef SIGQUIT
|
#ifdef SIGQUIT
|
||||||
modify(proc, forked, PROC_sig_ign, SIGQUIT, 0);
|
modify(proc, forked, PROC_sig_ign, SIGQUIT, 0);
|
||||||
#endif
|
#endif /* SIGQUIT */
|
||||||
}
|
}
|
||||||
if (flags & (PROC_DAEMON|PROC_SESSION))
|
if (flags & (PROC_DAEMON|PROC_SESSION))
|
||||||
modify(proc, forked, PROC_sys_pgrp, -1, 0);
|
modify(proc, forked, PROC_sys_pgrp, -1, 0);
|
||||||
|
@ -657,7 +629,7 @@ procopen(const char* cmd, char** argv, char** envv, long* modv, int flags)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
if (poi[1] != 0 && modify(proc, forked, PROC_fd_dup|PROC_FD_CHILD, poi[1], PROC_ARG_NULL))
|
if (poi[1] != 0 && modify(proc, forked, PROC_fd_dup|PROC_FD_CHILD, poi[1], PROC_ARG_NULL))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
#endif
|
#endif /* _pipe_rw || _lib_socketpair */
|
||||||
}
|
}
|
||||||
else if (procfd >= 0)
|
else if (procfd >= 0)
|
||||||
{
|
{
|
||||||
|
@ -682,28 +654,23 @@ procopen(const char* cmd, char** argv, char** envv, long* modv, int flags)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#if _lib_fork
|
|
||||||
if (forked && (flags & PROC_ENVCLEAR))
|
if (forked && (flags & PROC_ENVCLEAR))
|
||||||
environ = 0;
|
environ = 0;
|
||||||
#if _use_spawnveg
|
#if _use_spawnveg
|
||||||
else
|
else if (newenv)
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
#if _use_spawnveg
|
|
||||||
if (newenv)
|
|
||||||
{
|
{
|
||||||
p = environ;
|
p = environ;
|
||||||
while (*p++);
|
while (*p++);
|
||||||
if (!(oenviron = (char**)memdup(environ, (p - environ) * sizeof(char*))))
|
if (!(oenviron = (char**)memdup(environ, (p - environ) * sizeof(char*))))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
#endif
|
#endif /* _use_spawnveg */
|
||||||
if (argv && envv != (char**)environ)
|
if (argv && envv != (char**)environ)
|
||||||
{
|
{
|
||||||
#if _use_spawnveg
|
#if _use_spawnveg
|
||||||
if (!newenv && environ[0][0] == '_' && environ[0][1] == '=')
|
if (!newenv && environ[0][0] == '_' && environ[0][1] == '=')
|
||||||
oenviron0 = environ[0];
|
oenviron0 = environ[0];
|
||||||
#endif
|
#endif /* _use_spawnveg */
|
||||||
env[0] = '_';
|
env[0] = '_';
|
||||||
env[1] = '=';
|
env[1] = '=';
|
||||||
env[2] = 0;
|
env[2] = 0;
|
||||||
|
@ -717,10 +684,8 @@ procopen(const char* cmd, char** argv, char** envv, long* modv, int flags)
|
||||||
if (!setenviron(*p++))
|
if (!setenviron(*p++))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
p = argv;
|
p = argv;
|
||||||
#if _lib_fork
|
|
||||||
if (forked && !p)
|
if (forked && !p)
|
||||||
return proc;
|
return proc;
|
||||||
#endif
|
|
||||||
#if DEBUG_PROC
|
#if DEBUG_PROC
|
||||||
if (!(debug & PROC_OPT_EXEC) || (debug & PROC_OPT_VERBOSE))
|
if (!(debug & PROC_OPT_EXEC) || (debug & PROC_OPT_VERBOSE))
|
||||||
{
|
{
|
||||||
|
@ -732,12 +697,12 @@ procopen(const char* cmd, char** argv, char** envv, long* modv, int flags)
|
||||||
while (*++p)
|
while (*++p)
|
||||||
sfprintf(sfstderr, " %s", *p);
|
sfprintf(sfstderr, " %s", *p);
|
||||||
sfprintf(sfstderr, "\n");
|
sfprintf(sfstderr, "\n");
|
||||||
sfsync(sfstderr);
|
sfsync(sfstderr);
|
||||||
if (!(debug & PROC_OPT_EXEC))
|
if (!(debug & PROC_OPT_EXEC))
|
||||||
_exit(0);
|
_exit(0);
|
||||||
p = argv;
|
p = argv;
|
||||||
}
|
}
|
||||||
#endif
|
#endif /* DEBUG_PROC */
|
||||||
if (cmd)
|
if (cmd)
|
||||||
{
|
{
|
||||||
strcpy(env + 2, path);
|
strcpy(env + 2, path);
|
||||||
|
@ -746,7 +711,7 @@ sfsync(sfstderr);
|
||||||
#if _use_spawnveg
|
#if _use_spawnveg
|
||||||
else if ((proc->pid = spawnveg(path, p, environ, proc->pgrp, -1)) != -1)
|
else if ((proc->pid = spawnveg(path, p, environ, proc->pgrp, -1)) != -1)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
#endif
|
#endif /* _use_spawnveg */
|
||||||
if (errno != ENOEXEC)
|
if (errno != ENOEXEC)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
|
@ -774,7 +739,7 @@ sfsync(sfstderr);
|
||||||
#if _use_spawnveg
|
#if _use_spawnveg
|
||||||
else
|
else
|
||||||
proc->pid = spawnveg(env + 2, p, environ, proc->pgrp, -1);
|
proc->pid = spawnveg(env + 2, p, environ, proc->pgrp, -1);
|
||||||
#endif
|
#endif /* _use_spawnveg */
|
||||||
cleanup:
|
cleanup:
|
||||||
if (forked)
|
if (forked)
|
||||||
{
|
{
|
||||||
|
@ -798,7 +763,7 @@ sfsync(sfstderr);
|
||||||
restore(proc);
|
restore(proc);
|
||||||
if (flags & PROC_OVERLAY)
|
if (flags & PROC_OVERLAY)
|
||||||
exit(0);
|
exit(0);
|
||||||
#endif
|
#endif /* _use_spawnveg */
|
||||||
}
|
}
|
||||||
if (proc->pid != -1)
|
if (proc->pid != -1)
|
||||||
{
|
{
|
||||||
|
@ -820,9 +785,9 @@ sfsync(sfstderr);
|
||||||
proc->mask = sigblock(mask);
|
proc->mask = sigblock(mask);
|
||||||
#else
|
#else
|
||||||
proc->sigchld = signal(SIGCHLD, SIG_DFL);
|
proc->sigchld = signal(SIGCHLD, SIG_DFL);
|
||||||
#endif
|
#endif /* _lib_sigsetmask */
|
||||||
#endif
|
#endif /* _lib_sigprocmask */
|
||||||
#endif
|
#endif /* defined(SIGCHLD) */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (modv)
|
else if (modv)
|
||||||
|
@ -855,7 +820,7 @@ sfsync(sfstderr);
|
||||||
if ((handler = signal(SIGPIPE, ignoresig)) != SIG_DFL && handler != ignoresig)
|
if ((handler = signal(SIGPIPE, ignoresig)) != SIG_DFL && handler != ignoresig)
|
||||||
signal(SIGPIPE, handler);
|
signal(SIGPIPE, handler);
|
||||||
}
|
}
|
||||||
#endif
|
#endif /* SIGPIPE */
|
||||||
switch (procfd)
|
switch (procfd)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
|
@ -868,7 +833,7 @@ sfsync(sfstderr);
|
||||||
#else
|
#else
|
||||||
proc->wfd = poi[1];
|
proc->wfd = poi[1];
|
||||||
close(poi[0]);
|
close(poi[0]);
|
||||||
#endif
|
#endif /* _pipe_rw || _lib_socketpair */
|
||||||
/* FALLTHROUGH */
|
/* FALLTHROUGH */
|
||||||
case 1:
|
case 1:
|
||||||
proc->rfd = pio[0];
|
proc->rfd = pio[0];
|
||||||
|
@ -907,9 +872,9 @@ sfsync(sfstderr);
|
||||||
#else
|
#else
|
||||||
if (proc->sigchld != SIG_DFL)
|
if (proc->sigchld != SIG_DFL)
|
||||||
signal(SIGCHLD, proc->sigchld);
|
signal(SIGCHLD, proc->sigchld);
|
||||||
#endif
|
#endif /* _lib_sigsetmask */
|
||||||
#endif
|
#endif /* _lib_sigprocmask */
|
||||||
#endif
|
#endif /* defined(SIGCHLD) */
|
||||||
}
|
}
|
||||||
if ((flags & PROC_CLEANUP) && modv)
|
if ((flags & PROC_CLEANUP) && modv)
|
||||||
for (i = 0; n = modv[i]; i++)
|
for (i = 0; n = modv[i]; i++)
|
||||||
|
@ -936,7 +901,7 @@ sfsync(sfstderr);
|
||||||
close(poi[0]);
|
close(poi[0]);
|
||||||
if (poi[1] >= 0)
|
if (poi[1] >= 0)
|
||||||
close(poi[1]);
|
close(poi[1]);
|
||||||
#endif
|
#endif /* !_pipe_rw && !_lib_socketpair */
|
||||||
procfree(proc);
|
procfree(proc);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue