From da74ed6f26ccad2a241a18c3518cbc8c94a7c378 Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Sat, 4 Mar 2023 00:23:57 +0000 Subject: [PATCH] cleanup: rm JOBS symbol, POSIX signal ifdefs, waitpid(2) fallback jobs.h defines the JOBS symbol that is set if the system is deemed to support jobs control. This symbol was set if either SIGCHLD or SIGCLD is a signal on the current system. There is no POSIX compliant system made in recent decades that doesn't have SIGCHLD, whereas SIGCLD is completely obsolete. As expected, bit rot set in long ago; a test build of ksh with JOBS disabled failed. It is not worth fixing. All changed files: - Remove JOBS symbol and corresponding fallbacks. - Remove preprocessor checks for the following signal symbols that have been specified by POSIX for decaces: SIGCHLD, SIGHUP, SIGPIPE, SIGQUIT, SIGSTOP, SIGTSTP, SIGTTIN, SIGTTOU. - Remove all checks for and references to the obsolete SIGCLD symbol (all systems have been using SIGCHLD instead for decades). src/lib/libast/comp/waitpid.c: - Removed. All POSIX-ish operating systems provide waitpid(2), so none of the fallback code has been used for many years. --- src/cmd/ksh93/bltins/misc.c | 10 +- src/cmd/ksh93/bltins/trap.c | 8 +- src/cmd/ksh93/data/builtins.c | 10 -- src/cmd/ksh93/data/msg.c | 32 +++-- src/cmd/ksh93/data/signals.c | 29 +---- src/cmd/ksh93/include/builtins.h | 16 +-- src/cmd/ksh93/include/jobs.h | 53 +++------ src/cmd/ksh93/sh.1 | 3 +- src/cmd/ksh93/sh/fault.c | 10 +- src/cmd/ksh93/sh/jobs.c | 97 +++------------ src/cmd/ksh93/sh/main.c | 4 - src/cmd/ksh93/sh/subshell.c | 6 +- src/cmd/ksh93/sh/xec.c | 29 +---- src/cmd/ksh93/tests/sigchld.sh | 2 +- src/lib/libast/Mamfile | 12 +- src/lib/libast/comp/waitpid.c | 196 ------------------------------- src/lib/libast/features/signal.c | 6 +- src/lib/libast/misc/procclose.c | 8 +- src/lib/libast/misc/procopen.c | 46 ++------ src/lib/libast/misc/sigcrit.c | 16 +-- src/lib/libast/misc/signal.c | 10 +- src/lib/libast/sfio/sfmode.c | 10 +- 22 files changed, 75 insertions(+), 538 deletions(-) delete mode 100644 src/lib/libast/comp/waitpid.c diff --git a/src/cmd/ksh93/bltins/misc.c b/src/cmd/ksh93/bltins/misc.c index 338d08d11bd7..ca8e143fa247 100644 --- a/src/cmd/ksh93/bltins/misc.c +++ b/src/cmd/ksh93/bltins/misc.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1982-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2022 Contributors to ksh 93u+m * +* Copyright (c) 2020-2023 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -143,10 +143,8 @@ int b_exec(int argc,char *argv[], Shbltin_t *context) pname = argv[0]; if(arg0) argv[0] = arg0; -#ifdef JOBS if(job_close() < 0) return(1); -#endif /* JOBS */ /* if the main shell is about to be replaced, decrease SHLVL to cancel out a subsequent increase */ if(!sh.realsubshell) (*SHLVL->nvalue.ip)--; @@ -421,12 +419,11 @@ int b_wait(int n,register char *argv[],Shbltin_t *context) return(sh.exitval); } -#ifdef JOBS -# if 0 +#if 0 /* for the dictionary generator */ int b_fg(int n,char *argv[],Shbltin_t *context){} int b_disown(int n,char *argv[],Shbltin_t *context){} -# endif +#endif int b_bg(register int n,register char *argv[],Shbltin_t *context) { register int flag = **argv; @@ -504,7 +501,6 @@ int b_jobs(register int n,char *argv[],Shbltin_t *context) job_wait((pid_t)0); return(sh.exitval); } -#endif /* * times command diff --git a/src/cmd/ksh93/bltins/trap.c b/src/cmd/ksh93/bltins/trap.c index 82948e4e3a47..e8760c592da2 100644 --- a/src/cmd/ksh93/bltins/trap.c +++ b/src/cmd/ksh93/bltins/trap.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1982-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2022 Contributors to ksh 93u+m * +* Copyright (c) 2020-2023 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -219,16 +219,12 @@ int b_kill(int argc,char *argv[],Shbltin_t *context) register int sig=SIGTERM, flag=0, n; int usemenu = 0; NOT_USED(argc); -#if defined(JOBS) && defined(SIGSTOP) if(**argv == 's') /* top == kill -s STOP */ { flag |= S_FLAG; signame = "STOP"; } while((n = optget(argv, **argv == 's' ? sh_optstop : sh_optkill))) switch(n) -#else - while((n = optget(argv,sh_optkill))) switch(n) -#endif /* defined(JOBS) && defined(SIGSTOP) */ { case ':': if((signame=argv[opt_info.index++]) && (sig=sig_number(signame+1))>=0) @@ -298,7 +294,6 @@ int b_kill(int argc,char *argv[],Shbltin_t *context) return(sh.exitval); } -#if defined(JOBS) && defined(SIGSTOP) /* * former default alias suspend='kill -s STOP $$' */ @@ -337,7 +332,6 @@ int b_suspend(int argc,char *argv[],Shbltin_t *context) } return(0); } -#endif /* defined(JOBS) && defined(SIGSTOP) */ /* * Given the name or number of a signal return the signal number diff --git a/src/cmd/ksh93/data/builtins.c b/src/cmd/ksh93/data/builtins.c index e6ddddadebfc..c2e54e20a6cb 100644 --- a/src/cmd/ksh93/data/builtins.c +++ b/src/cmd/ksh93/data/builtins.c @@ -97,21 +97,13 @@ const struct shtable3 shtab_builtins[] = #else "echo", NV_BLTIN|BLT_ENV, Bltin(echo), #endif /* SHOPT_ECHOPRINT */ -#ifdef JOBS -# ifdef SIGTSTP "bg", NV_BLTIN|BLT_ENV, bltin(bg), "fg", NV_BLTIN|BLT_ENV|BLT_EXIT, bltin(bg), "disown", NV_BLTIN|BLT_ENV, bltin(bg), "kill", NV_BLTIN|BLT_ENV, bltin(kill), -# else - "/bin/kill", NV_BLTIN|BLT_ENV, bltin(kill), -# endif /* SIGTSTP */ "jobs", NV_BLTIN|BLT_ENV, bltin(jobs), -# ifdef SIGSTOP "stop", NV_BLTIN|BLT_ENV, bltin(kill), "suspend", NV_BLTIN|BLT_ENV, bltin(suspend), -# endif /* SIGSTOP */ -#endif /* JOBS */ "false", NV_BLTIN|BLT_ENV, bltin(false), "getopts", NV_BLTIN|BLT_ENV, bltin(getopts), #if SHOPT_MKSERVICE @@ -1138,7 +1130,6 @@ _JOB_ "[+SEE ALSO?\bps\b(1), \bjobs\b(1), \bkill\b(2), \bsignal\b(2)]" ; -#if defined(JOBS) && defined(SIGSTOP) const char sh_optstop[] = "[-1c?\n@(#)$Id: stop (ksh 93u+m) 2020-06-22 $\n]" "[--catalog?" SH_DICT "]" @@ -1174,7 +1165,6 @@ const char sh_optsuspend[] = "}" "[+SEE ALSO?\bkill\b(1)]" ; -#endif /* defined(JOBS) && defined(SIGSTOP) */ const char sh_optlet[] = "[-1c?\n@(#)$Id: let (AT&T Research) 2000-04-02 $\n]" diff --git a/src/cmd/ksh93/data/msg.c b/src/cmd/ksh93/data/msg.c index d5abe2f71e8a..7987c864e63c 100644 --- a/src/cmd/ksh93/data/msg.c +++ b/src/cmd/ksh93/data/msg.c @@ -146,24 +146,20 @@ const char is_talias[] = "is a tracked alias for"; const char is_function[] = " is a function"; const char is_ufunction[] = " is an undefined function"; const char e_autoloadfrom[] = " (autoload from %s)"; -#ifdef JOBS -# ifdef SIGTSTP - const char e_newtty[] = "Switching to new tty driver..."; - const char e_oldtty[] = "Reverting to old tty driver..."; - const char e_no_start[] = "Cannot start job control"; -# endif /*SIGTSTP */ - const char e_no_jctl[] = "No job control"; - const char e_terminate[] = "You have stopped jobs"; - const char e_done[] = " Done"; - const char e_nlspace[] = "\n "; - const char e_running[] = " Running"; - const char e_ambiguous[] = "%s: Ambiguous"; - const char e_jobsrunning[] = "You have running jobs"; - const char e_no_job[] = "no such job"; - const char e_no_proc[] = "no such process"; - const char e_badpid[] = "%s: invalid process ID"; - const char e_jobusage[] = "%s: Arguments must be %%job or process IDs"; -#endif /* JOBS */ +const char e_newtty[] = "Switching to new tty driver..."; +const char e_oldtty[] = "Reverting to old tty driver..."; +const char e_no_start[] = "Cannot start job control"; +const char e_no_jctl[] = "No job control"; +const char e_terminate[] = "You have stopped jobs"; +const char e_done[] = " Done"; +const char e_nlspace[] = "\n "; +const char e_running[] = " Running"; +const char e_ambiguous[] = "%s: Ambiguous"; +const char e_jobsrunning[] = "You have running jobs"; +const char e_no_job[] = "no such job"; +const char e_no_proc[] = "no such process"; +const char e_badpid[] = "%s: invalid process ID"; +const char e_jobusage[] = "%s: Arguments must be %%job or process IDs"; const char e_coredump[] = "(coredump)"; const char e_alphanum[] = "[_[:alpha:]]*([_[:alnum:]])"; const char e_devfdNN[] = "/dev/fd/+([0-9])"; diff --git a/src/cmd/ksh93/data/signals.c b/src/cmd/ksh93/data/signals.c index b49ab75b5b29..717ebdff8990 100644 --- a/src/cmd/ksh93/data/signals.c +++ b/src/cmd/ksh93/data/signals.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1982-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2022 Contributors to ksh 93u+m * +* Copyright (c) 2020-2023 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -19,10 +19,6 @@ #include "defs.h" #include "jobs.h" -#if defined(SIGCLD) && !defined(SIGCHLD) -# define SIGCHLD SIGCLD -#endif - #define VAL(sig,mode) ((sig+1)|((mode)< +#include "terminal.h" -#undef JOBS -#if defined(SIGCLD) && !defined(SIGCHLD) -# define SIGCHLD SIGCLD +#ifndef SIGCHLD +# error ksh 93u+m requires SIGCHLD #endif -#ifdef SIGCHLD -# define JOBS 1 -# include "terminal.h" -# ifdef FIOLOOKLD +#ifdef FIOLOOKLD /* Ninth edition */ extern int tty_ld, ntty_ld; # define OTTYDISC tty_ld # define NTTYDISC ntty_ld -# endif /* FIOLOOKLD */ -#else -# undef SIGTSTP -# undef SH_MONITOR -# define SH_MONITOR 0 -# define job_set(x) -# define job_reset(x) -#endif +#endif /* FIOLOOKLD */ struct process { @@ -67,10 +57,8 @@ struct process unsigned short p_exitmin; /* minimum exit value for xargs */ unsigned short p_flag; /* flags - see below */ unsigned int p_env; /* subshell environment number */ -#ifdef JOBS off_t p_name; /* history file offset for command */ struct termios p_stty; /* terminal state for job */ -#endif /* JOBS */ }; struct jobs @@ -90,10 +78,8 @@ struct jobs int numbjob; /* number of background jobs */ #endif /* SHOPT_BGX */ short fd; /* tty descriptor number */ -#ifdef JOBS int suspend; /* suspend character */ int linedisc; /* line discipline */ -#endif /* JOBS */ char jobcontrol; /* turned on for interactive shell with control of terminal */ char waitsafe; /* wait will not block */ char waitall; /* wait for all jobs in pipe */ @@ -109,8 +95,6 @@ struct jobs extern struct jobs job; -#ifdef JOBS - #if !_std_malloc #include #ifdef vmlocked @@ -144,14 +128,11 @@ extern const char e_access[]; extern const char e_terminate[]; extern const char e_no_jctl[]; extern const char e_signo[]; -#ifdef SIGTSTP - extern const char e_no_start[]; -#endif /* SIGTSTP */ +extern const char e_no_start[]; #ifdef NTTYDISC extern const char e_newtty[]; extern const char e_oldtty[]; #endif /* NTTYDISC */ -#endif /* JOBS */ /* * The following are defined in jobs.c @@ -168,18 +149,12 @@ extern void job_subrestore(void*); #if SHOPT_BGX extern void job_chldtrap(int); #endif /* SHOPT_BGX */ -#ifdef JOBS - extern void job_init(int); - extern int job_close(void); - extern int job_list(struct process*,int); - extern int job_hup(struct process *, int); - extern int job_switch(struct process*,int); - extern void job_fork(pid_t); - extern int job_reap(int); -#else -# define job_init(flag) -# define job_close() (0) -# define job_fork(p) -#endif /* JOBS */ +extern void job_init(int); +extern int job_close(void); +extern int job_list(struct process*,int); +extern int job_hup(struct process *, int); +extern int job_switch(struct process*,int); +extern void job_fork(pid_t); +extern int job_reap(int); #endif /* !JOB_NFLAG */ diff --git a/src/cmd/ksh93/sh.1 b/src/cmd/ksh93/sh.1 index 06fff18a3254..cd6e270ff4d6 100644 --- a/src/cmd/ksh93/sh.1 +++ b/src/cmd/ksh93/sh.1 @@ -6948,8 +6948,7 @@ option or by name with the option (as given in .BR , -stripped of the prefix ``SIG'' with -the exception that SIGCLD is named CHLD). +stripped of the prefix ``SIG''. For backward compatibility, the .B n and diff --git a/src/cmd/ksh93/sh/fault.c b/src/cmd/ksh93/sh/fault.c index 98d6a7e5e1c5..b72d90f1105c 100644 --- a/src/cmd/ksh93/sh/fault.c +++ b/src/cmd/ksh93/sh/fault.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1982-2014 AT&T Intellectual Property * -* Copyright (c) 2020-2022 Contributors to ksh 93u+m * +* Copyright (c) 2020-2023 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -174,7 +174,6 @@ void sh_fault(register int sig) { sh.lastsig = sig; flag = SH_SIGSET; -#ifdef SIGTSTP if(sig==SIGTSTP && pp->mode==SH_JMPCMD) { if(sh_isstate(SH_STOPOK)) @@ -185,7 +184,6 @@ void sh_fault(register int sig) } goto done; } -#endif /* SIGTSTP */ } #ifdef ERROR_NOTIFY if((error_info.flags&ERROR_NOTIFY) && sh.bltinfun) @@ -568,7 +566,6 @@ void sh_exit(register int xno) sh.exitval |= (sig=sh.lastsig); if(pp && pp->mode>1) cursig = -1; -#ifdef SIGTSTP if((sh.trapnote&SH_SIGTSTP) && job.jobcontrol) { /* ^Z detected by the shell */ @@ -613,16 +610,13 @@ void sh_exit(register int xno) return; } } -#endif /* SIGTSTP */ /* unlock output pool */ sh_offstate(SH_NOTRACK); if(!(pool=sfpool(NIL(Sfio_t*),sh.outpool,SF_WRITE))) pool = sh.outpool; /* can't happen? */ sfclrlock(pool); -#ifdef SIGPIPE if(sh.lastsig==SIGPIPE) sfpurge(pool); -#endif /* SIGPIPE */ sfclrlock(sfstdin); if(!pp) sh_done(sig); @@ -679,10 +673,8 @@ noreturn void sh_done(register int sig) #endif /* SHOPT_ACCT */ if(mbwide() && sh_editor_active()) tty_cooked(-1); -#ifdef JOBS if((sh_isoption(SH_INTERACTIVE) && sh_isoption(SH_LOGIN_SHELL)) || (!sh_isoption(SH_INTERACTIVE) && (sig==SIGHUP))) job_walk(sfstderr, job_hup, SIGHUP, NIL(char**)); -#endif /* JOBS */ job_close(); if(nv_search("VMTRACE", sh.var_tree,0)) strmatch((char*)0,(char*)0); diff --git a/src/cmd/ksh93/sh/jobs.c b/src/cmd/ksh93/sh/jobs.c index 2cedab599ab6..72c7f5f938ff 100644 --- a/src/cmd/ksh93/sh/jobs.c +++ b/src/cmd/ksh93/sh/jobs.c @@ -171,22 +171,17 @@ static Sfio_t *outfile; static pid_t lastpid; static struct back_save bck; -#ifdef JOBS - static void job_set(struct process*); - static void job_reset(struct process*); - static void job_waitsafe(int); - static struct process *job_byname(char*); - static struct process *job_bystring(char*); - static struct termios my_stty; /* terminal state for shell */ - static char *job_string; -#else - extern const char e_coredump[]; -#endif /* JOBS */ +static void job_set(struct process*); +static void job_reset(struct process*); +static void job_waitsafe(int); +static struct process *job_byname(char*); +static struct process *job_bystring(char*); +static struct termios my_stty; /* terminal state for shell */ +static char *job_string; -#ifdef SIGTSTP static void job_unstop(struct process*); static void job_fgrp(struct process*, int); -# ifndef _lib_tcgetpgrp +#ifndef _lib_tcgetpgrp # ifdef TIOCGPGRP static int _i_; # define tcgetpgrp(a) (ioctl(a, TIOCGPGRP, &_i_)>=0?_i_:-1) @@ -200,18 +195,12 @@ static struct back_save bck; return(-1); # endif /* TIOCGPGRP */ } -# endif /* _lib_tcgetpgrp */ -#else -# define job_unstop(pw) -# undef CNSUSP -#endif /* SIGTSTP */ +#endif /* _lib_tcgetpgrp */ #ifndef OTTYDISC # undef NTTYDISC #endif /* OTTYDISC */ -#ifdef JOBS - typedef int (*Waitevent_f)(int,long,int); #if SHOPT_BGX @@ -369,7 +358,6 @@ int job_reap(register int sig) continue; } } -#ifdef SIGTSTP else px=job_byjid(pw->p_job); if (WIFCONTINUED(wstat) && wcontinued) @@ -390,7 +378,6 @@ int job_reap(register int sig) continue; } else -#endif /* SIGTSTP */ { /* check for coprocess completion */ if(pid==sh.cpid) @@ -513,7 +500,7 @@ int job_reap(register int sig) } /* - * This is the SIGCLD interrupt routine + * This is the SIGCHLD interrupt routine */ static void job_waitsafe(int sig) { @@ -535,9 +522,6 @@ void job_init(int lflag) register int ntry=0; job.fd = JOBTTY; signal(SIGCHLD,job_waitsafe); -# if defined(SIGCLD) && (SIGCLD!=SIGCHLD) - signal(SIGCLD,job_waitsafe); -# endif if(njob_savelist < NJOB_SAVELIST) init_savelist(); if(!sh_isoption(SH_INTERACTIVE)) @@ -566,9 +550,7 @@ void job_init(int lflag) /* This should have already been done by rlogin */ register int fd; register char *ttynam; -#ifndef SIGTSTP setpgid(0,sh.pid); -#endif /*SIGTSTP */ if(job.mypgid<0 || !(ttynam=ttyname(JOBTTY))) return; while(close(JOBTTY)<0 && errno==EINTR) @@ -577,12 +559,9 @@ void job_init(int lflag) return; if(fd!=JOBTTY) sh_iorenumber(fd,JOBTTY); -#ifdef SIGTSTP tcsetpgrp(JOBTTY,sh.pid); -#endif /* SIGTSTP */ job.mypgid = sh.pid; } -#ifdef SIGTSTP possible = (setpgid(0,job.mypgid) >= 0) || errno==EPERM; if(possible) { @@ -602,7 +581,6 @@ void job_init(int lflag) } } } -#endif /* SIGTTIN */ #ifdef NTTYDISC /* set the line discipline */ if(job.linedisc>=0) @@ -630,11 +608,10 @@ void job_init(int lflag) #endif /* NTTYDISC */ if(!possible) return; -#ifdef SIGTSTP /* make sure that we are a process group leader */ setpgid(0,sh.pid); job.mypid = sh.pid; -# if defined(SA_NOCLDSTOP) || defined(SA_NOCLDWAIT) +#if defined(SA_NOCLDSTOP) || defined(SA_NOCLDWAIT) # if !defined(SA_NOCLDSTOP) # define SA_NOCLDSTOP 0 # endif @@ -642,13 +619,13 @@ void job_init(int lflag) # define SA_NOCLDWAIT 0 # endif sigflag(SIGCHLD, SA_NOCLDSTOP|SA_NOCLDWAIT, 0); -# endif /* SA_NOCLDSTOP || SA_NOCLDWAIT */ +#endif /* SA_NOCLDSTOP || SA_NOCLDWAIT */ signal(SIGTTIN,SIG_IGN); signal(SIGTTOU,SIG_IGN); /* The shell now handles ^Z */ signal(SIGTSTP,sh_fault); tcsetpgrp(JOBTTY,sh.pid); -# ifdef CNSUSP +#ifdef CNSUSP /* set the switch character */ tty_get(JOBTTY,&my_stty); job.suspend = (unsigned)my_stty.c_cc[VSUSP]; @@ -657,10 +634,9 @@ void job_init(int lflag) my_stty.c_cc[VSUSP] = CSWTCH; tty_set(JOBTTY,TCSAFLUSH,&my_stty); } -# endif /* CNSUSP */ +#endif /* CNSUSP */ sh_onoption(SH_MONITOR); job.jobcontrol++; -#endif /* SIGTSTP */ return; } @@ -708,10 +684,8 @@ int job_close(void) } } job_unlock(); -# ifdef SIGTSTP if(job.jobcontrol && setpgid(0,job.mypgid)>=0) tcsetpgrp(job.fd,job.mypgid); -# endif /* SIGTSTP */ # ifdef NTTYDISC if(job.linedisc>=0) { @@ -757,30 +731,24 @@ static void job_set(register struct process *pw) /* restore terminal state for job */ tty_set(job.fd,TCSAFLUSH,&pw->p_stty); } -#ifdef SIGTSTP if((pw->p_flag&P_STOPPED) || tcgetpgrp(job.fd) == sh.pid) tcsetpgrp(job.fd,pw->p_fgrp); /* if job is stopped, resume it in the background */ if(!sh.forked) job_unstop(pw); sh.forked = 0; -#endif /* SIGTSTP */ } static void job_reset(register struct process *pw) { /* save the terminal state for current job */ -#ifdef SIGTSTP pid_t tgrp; -#endif if(!job.jobcontrol) return; -#ifdef SIGTSTP if((tgrp=tcgetpgrp(job.fd))!=job.mypid) job_fgrp(pw,tgrp); if(tcsetpgrp(job.fd,job.mypid) !=0) return; -#endif /* SIGTSTP */ /* force the following tty_get() to do a tcgetattr() unless fg */ if(!(pw->p_flag&P_MOVED2FG)) tty_set(-1, 0, NIL(struct termios*)); @@ -793,7 +761,6 @@ static void job_reset(register struct process *pw) } beenhere = 0; } -#endif /* JOBS */ /* * wait built-in command @@ -807,7 +774,6 @@ void job_bwait(char **jobs) job_wait((pid_t)-1); else while(jp = *jobs++) { -#ifdef JOBS if(*jp == '%') { job_lock(); @@ -819,13 +785,11 @@ void job_bwait(char **jobs) return; } else -#endif /* JOBS */ pid = pid_fromstring(jp); job_wait(-pid); } } -#ifdef JOBS /* * execute function for each job */ @@ -1009,11 +973,7 @@ int job_kill(register struct process *pw,register int sig) register pid_t pid; register int r; const char *msg; -#ifdef SIGTSTP int stopsig = (sig==SIGSTOP||sig==SIGTSTP||sig==SIGTTIN||sig==SIGTTOU); -#else -# define stopsig 1 -#endif /* SIGTSTP */ job_lock(); errno = ECHILD; if(!pw) @@ -1023,7 +983,6 @@ int job_kill(register struct process *pw,register int sig) { if(pid==0 && job.jobcontrol) r = job_walk(outfile, job_kill,sig, (char**)0); -#ifdef SIGTSTP if(sig==SIGSTOP && pid==sh.pid && sh.ppid==1) { /* can't stop login shell */ @@ -1052,31 +1011,21 @@ int job_kill(register struct process *pw,register int sig) } } } -#else - if(pid>=0) - r = kill(pid,sig); - else - r = killpg(-pid,sig); -#endif /* SIGTSTP */ } else { if(pid = pw->p_pgrp) { r = killpg(pid,sig); -#ifdef SIGTSTP if(r>=0 && (sig==SIGHUP||sig==SIGTERM || sig==SIGCONT)) job_unstop(pw); -#endif /* SIGTSTP */ if(r>=0) sh_delay(.05,0); } while(pw && pw->p_pgrp==0 && (r=kill(pw->p_pid,sig))>=0) { -#ifdef SIGTSTP if(sig==SIGHUP || sig==SIGTERM) kill(pw->p_pid,SIGCONT); -#endif /* SIGTSTP */ pw = pw->p_nxtproc; } } @@ -1153,13 +1102,6 @@ static struct process *job_byname(char *name) return(pz); } -#else -# define job_set(x) -# define job_reset(x) -#endif /* JOBS */ - - - /* * Initialize the process posting array */ @@ -1289,12 +1231,10 @@ int job_post(pid_t pid, pid_t join) pw->p_pid,pw->p_pgrp,job.savesig,join); sfsync(sfstderr); #endif /* DEBUG */ -#ifdef JOBS if(hp && !sh_isstate(SH_PROFILE)) pw->p_name=hist_tell(sh.hist_ptr,(int)hp->histind-1); else pw->p_name = -1; -#endif /* JOBS */ if ((val = job_chksave(pid))>=0 && !jobfork) { pw->p_exit = val; @@ -1468,7 +1408,6 @@ int job_wait(register pid_t pid) } if(pw && (pw->p_flag&(P_DONE|P_STOPPED))) { -#ifdef SIGTSTP if(pw->p_flag&P_STOPPED) { pw->p_flag |= P_EXITSAVE; @@ -1484,7 +1423,6 @@ int job_wait(register pid_t pid) pw->p_flag &= ~(P_NOTIFY|P_SIGNALLED|P_STOPPED|P_EXITSAVE); } else -#endif /* SIGTSTP */ { if(pw->p_flag&P_SIGNALLED) { @@ -1545,13 +1483,11 @@ int job_wait(register pid_t pid) /* propagate keyboard interrupts to parent */ if((pw->p_flag&P_SIGNALLED) && pw->p_exit==SIGINT && !(sh.sigflag[SIGINT]&SH_SIGOFF)) kill(sh.current_pid,SIGINT); -#ifdef SIGTSTP else if((pw->p_flag&P_STOPPED) && pw->p_exit==SIGTSTP) { job.parent = 0; kill(sh.current_pid,SIGTSTP); } -#endif /* SIGTSTP */ } else if(job.jobcontrol) { @@ -1600,7 +1536,6 @@ int job_switch(register struct process *pw,int bgflag) job_unlock(); return(0); } -#ifdef SIGTSTP if(bgflag=='b') { sfprintf(outfile,"[%d]\t",(int)pw->p_job); @@ -1633,13 +1568,10 @@ int job_switch(register struct process *pw,int bgflag) } else if(pw->p_flag&P_STOPPED) job_unstop(pw); -#endif /* SIGTSTP */ job_unlock(); return(0); } - -#ifdef SIGTSTP /* * Set the foreground group associated with a job */ @@ -1671,7 +1603,6 @@ static void job_unstop(register struct process *px) killpg(px->p_pgrp,SIGCONT); } } -#endif /* SIGTSTP */ /* * remove a job from table diff --git a/src/cmd/ksh93/sh/main.c b/src/cmd/ksh93/sh/main.c index f7e6eb7e3d6b..7e449036efce 100644 --- a/src/cmd/ksh93/sh/main.c +++ b/src/cmd/ksh93/sh/main.c @@ -457,9 +457,7 @@ static void exfile(register Sfio_t *iop,register int fno) sfclose(top); } /* make sure that we own the terminal */ -#ifdef SIGTSTP tcsetpgrp(job.fd,sh.pid); -#endif /* SIGTSTP */ } /* error return here */ sfclrerr(iop); @@ -499,7 +497,6 @@ static void exfile(register Sfio_t *iop,register int fno) if(sh_isstate(SH_INTERACTIVE) && !tdone) { register char *mail; -#ifdef JOBS sh_offstate(SH_MONITOR); if(sh_isoption(SH_MONITOR)) sh_onstate(SH_MONITOR); @@ -508,7 +505,6 @@ static void exfile(register Sfio_t *iop,register int fno) job_walk(sfstderr,job_list,JOB_NFLAG,(char**)0); job_wait((pid_t)0); } -#endif /* JOBS */ if((mail=nv_getval(MAILPNOD)) || (mail=nv_getval(MAILNOD))) { time(&curtime); diff --git a/src/cmd/ksh93/sh/subshell.c b/src/cmd/ksh93/sh/subshell.c index d575c1f9a5e8..1a9686703f47 100644 --- a/src/cmd/ksh93/sh/subshell.c +++ b/src/cmd/ksh93/sh/subshell.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1982-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2022 Contributors to ksh 93u+m * +* Copyright (c) 2020-2023 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -639,7 +639,6 @@ Sfio_t *sh_subshell(Shnode_t *t, volatile int flags, int comsub) sh_subfork(); } #endif /* _lib_fchdir */ -#ifdef SIGTSTP /* Virtual subshells are not safe to suspend (^Z, SIGTSTP) in the interactive main shell. */ if(sh_isstate(SH_INTERACTIVE)) { @@ -648,7 +647,6 @@ Sfio_t *sh_subshell(Shnode_t *t, volatile int flags, int comsub) else sh_subfork(); } -#endif sh_offstate(SH_INTERACTIVE); sh_exec(t,flags); } @@ -677,10 +675,8 @@ Sfio_t *sh_subshell(Shnode_t *t, volatile int flags, int comsub) nv_restore(sp); if(comsub) { -#ifdef SIGTSTP if(savst.states & sh_state(SH_INTERACTIVE)) sigrelease(SIGTSTP); -#endif /* re-enable job control */ job.jobcontrol = sp->jobcontrol; if(sp->monitor) diff --git a/src/cmd/ksh93/sh/xec.c b/src/cmd/ksh93/sh/xec.c index 897882515df1..f5742cde96d5 100644 --- a/src/cmd/ksh93/sh/xec.c +++ b/src/cmd/ksh93/sh/xec.c @@ -55,7 +55,7 @@ #endif #undef _use_ntfork_tcpgrp -#if defined(JOBS) && SHOPT_SPAWN && _lib_posix_spawn > 1 && _lib_posix_spawn_file_actions_addtcsetpgrp_np +#if SHOPT_SPAWN && _lib_posix_spawn > 1 && _lib_posix_spawn_file_actions_addtcsetpgrp_np #define _use_ntfork_tcpgrp 1 #endif @@ -1556,18 +1556,9 @@ int sh_exec(register const Shnode_t *t, int flags) if(!sh_isstate(SH_MONITOR)) sigrelease(SIGINT); } - if(type&FAMP) - { - if(sh_isstate(SH_PROFILE) || sh_isstate(SH_INTERACTIVE)) - { - /* print job number */ -#ifdef JOBS - sfprintf(sfstderr,"[%d]\t%d\n",jobid,parent); -#else - sfprintf(sfstderr,"%d\n",parent); -#endif /* JOBS */ - } - } + /* print job number */ + if(type&FAMP && (sh_isstate(SH_PROFILE) || sh_isstate(SH_INTERACTIVE))) + sfprintf(sfstderr,"[%d]\t%d\n",jobid,parent); break; } else @@ -1939,10 +1930,8 @@ int sh_exec(register const Shnode_t *t, int flags) } } sh.exitval = n; -#ifdef SIGTSTP if(!pipejob && sh_isstate(SH_MONITOR) && job.jobcontrol) tcsetpgrp(JOBTTY,sh.pid); -#endif /* SIGTSTP */ job.curpgid = savepgid; job.exitval = saveexitval; job.waitall = savewaitall; @@ -2824,7 +2813,6 @@ pid_t _sh_fork(register pid_t parent,int flags,int *jobid) if(job.toclear) job_clear(); job.waitall = waitall; -#ifdef JOBS /* first process defines process group */ if(sh_isstate(SH_MONITOR)) { @@ -2840,7 +2828,6 @@ pid_t _sh_fork(register pid_t parent,int flags,int *jobid) setpgid(parent,parent); } } -#endif /* JOBS */ if(!sh_isstate(SH_MONITOR) && job.waitall && postid==0) job.curpgid = parent; if(flags&FCOOP) @@ -2871,7 +2858,6 @@ pid_t _sh_fork(register pid_t parent,int flags,int *jobid) if(sh.trapnote&SH_SIGTERM) sh_exit(SH_EXITSIG|SIGTERM); sh_timerdel(NIL(void*)); -#ifdef JOBS if(sh_isstate(SH_MONITOR)) { parent = sh.current_pid; @@ -2879,21 +2865,16 @@ pid_t _sh_fork(register pid_t parent,int flags,int *jobid) job.curpgid = parent; while(setpgid(0,job.curpgid)<0 && job.curpgid!=parent) job.curpgid = parent; -# ifdef SIGTSTP if(job.jobcontrol && job.curpgid==parent && !(flags&FAMP)) tcsetpgrp(job.fd,job.curpgid); -# endif /* SIGTSTP */ } -# ifdef SIGTSTP if(job.jobcontrol) { signal(SIGTTIN,SIG_DFL); signal(SIGTTOU,SIG_DFL); signal(SIGTSTP,SIG_DFL); } -# endif /* SIGTSTP */ job.jobcontrol = 0; -#endif /* JOBS */ job.toclear = 1; sh_offoption(SH_LOGIN_SHELL); sh_onstate(SH_FORKED); @@ -3542,10 +3523,8 @@ static pid_t sh_ntfork(const Shnode_t *t,char *argv[],int *jobid,int topfd) { _sh_fork(spawnpid,0,jobid); job_fork(spawnpid); -#ifdef JOBS if(grp==1) job.curpgid = spawnpid; -#endif /* JOBS */ } return(spawnpid); } diff --git a/src/cmd/ksh93/tests/sigchld.sh b/src/cmd/ksh93/tests/sigchld.sh index 028a95fea0d6..32b0990a1e47 100755 --- a/src/cmd/ksh93/tests/sigchld.sh +++ b/src/cmd/ksh93/tests/sigchld.sh @@ -106,7 +106,7 @@ fi got=$( ( sleep .1;print $'\n') | $SHELL -c 'function handler { : ;} trap handler CHLD; sleep .03 & IFS= read; print good') } 2> /dev/null -[[ $got == good ]] || err_exit 'SIGCLD handler effects read behavior' +[[ $got == good ]] || err_exit 'SIGCHLD handler affects read behavior' set -- $( ( diff --git a/src/lib/libast/Mamfile b/src/lib/libast/Mamfile index d4164d4775ef..a18f04664584 100644 --- a/src/lib/libast/Mamfile +++ b/src/lib/libast/Mamfile @@ -2881,16 +2881,6 @@ make install prev comp/setsid.c exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -Icomp -Iinclude -Istd -D_PACKAGE_ast -c comp/setsid.c done setsid.o generated - make waitpid.o - make comp/waitpid.c - prev include/error.h implicit - prev sig.h implicit - prev include/wait.h implicit - prev include/ast.h implicit - done comp/waitpid.c - prev comp/waitpid.c - exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -Icomp -Iinclude -Istd -D_PACKAGE_ast -c comp/waitpid.c - done waitpid.o generated make fcntl.o make comp/fcntl.c prev include/error.h implicit @@ -5157,7 +5147,7 @@ make install exec - ${AR} rc libast.a state.o opendir.o readdir.o rewinddir.o seekdir.o telldir.o getcwd.o fastfind.o hashalloc.o hashdump.o hashfree.o hashlast.o hashlook.o hashscan.o hashsize.o hashview.o hashwalk.o memhash.o memsum.o strhash.o strkey.o strsum.o stracmp.o strnacmp.o ccmap.o ccmapid.o ccnative.o chresc.o chrtoi.o exec - ${AR} rc libast.a streval.o strexpr.o strmatch.o strcopy.o modei.o modex.o strmode.o strlcat.o strlcpy.o strlook.o strncopy.o strsearch.o strpsearch.o stresc.o stropt.o strtape.o strpcmp.o strnpcmp.o strvcmp.o strnvcmp.o tok.o tokline.o tokscan.o pathaccess.o pathcat.o pathcanon.o pathcheck.o pathpath.o pathexists.o pathfind.o pathicase.o pathkey.o pathprobe.o pathrepl.o pathnative.o pathposix.o pathtemp.o pathtmp.o pathstat.o pathgetlink.o pathsetlink.o pathbin.o pathshell.o pathcd.o pathprog.o ftwalk.o ftwflags.o fts.o astintercept.o conformance.o getenv.o setenviron.o optget.o optjoin.o optesc.o optctx.o strsort.o struniq.o magic.o mime.o mimetype.o signal.o sigflag.o systrace.o error.o errorf.o errormsg.o errorx.o localeconv.o setlocale.o translate.o catopen.o iconv.o lc.o lctab.o mc.o base64.o recfmt.o recstr.o reclen.o fmtrec.o fmtbase.o fmtbuf.o fmtclock.o fmtdev.o fmtelapsed.o fmterror.o fmtesc.o fmtfmt.o fmtfs.o fmtident.o fmtint.o fmtip4.o fmtip6.o fmtls.o fmtmatch.o fmtmode.o fmtnum.o fmtperm.o fmtre.o fmttime.o exec - ${AR} rc libast.a fmtuid.o fmtgid.o fmtsignal.o fmtscale.o fmttmx.o fmttv.o fmtversion.o strelapsed.o strperm.o struid.o strgid.o strtoip4.o strtoip6.o stack.o stk.o swapget.o swapmem.o swapop.o swapput.o sigdata.o sigcrit.o sigunblock.o procopen.o procclose.o procrun.o procfree.o tmdate.o tmequiv.o tmfix.o tmfmt.o tmform.o tmgoff.o tminit.o tmleap.o tmlex.o tmlocale.o tmmake.o tmpoff.o tmscan.o tmsleep.o tmtime.o tmtype.o tmweek.o tmword.o tmzone.o tmxdate.o tmxduration.o tmxfmt.o tmxgettime.o tmxleap.o tmxmake.o tmxscan.o tmxsettime.o tmxsleep.o tmxtime.o tmxtouch.o tvcmp.o tvgettime.o tvsettime.o tvsleep.o tvtouch.o cmdarg.o vecargs.o vecfile.o vecfree.o vecload.o vecstring.o univdata.o touch.o mnt.o debug.o memccpy.o memchr.o memcmp.o memcpy.o memdup.o memmove.o memset.o mkdir.o mkfifo.o mknod.o rmdir.o remove.o rename.o link.o unlink.o strdup.o strchr.o strrchr.o strstr.o strtod.o strtold.o strtol.o strtoll.o strtoul.o strtoull.o strton.o strtonll.o strntod.o strntold.o strnton.o - exec - ${AR} rc libast.a strntonll.o strntol.o strntoll.o strntoul.o strntoull.o strcasecmp.o strncasecmp.o strerror.o mktemp.o tmpnam.o fsync.o execlp.o execve.o execvp.o execvpe.o spawnveg.o vfork.o killpg.o getlogin.o putenv.o setenv.o unsetenv.o lstat.o statvfs.o eaccess.o gross.o omitted.o readlink.o symlink.o getpgrp.o setpgid.o setsid.o waitpid.o fcntl.o open.o atexit.o getdents.o getwd.o dup2.o errno.o getpreroot.o ispreroot.o realopen.o setpreroot.o getgroups.o mount.o system.o iblocks.o modedata.o tmdata.o memfatal.o sfkeyprintf.o sfdcdio.o sfdcdos.o sfdcfilter.o sfdcseekable.o sfdcslow.o sfdcsubstr.o sfdctee.o sfdcunion.o sfdcmore.o sfdcprefix.o wc.o wc2utf8.o basename.o closelog.o dirname.o fmtmsglib.o fnmatch.o ftw.o getdate.o getsubopt.o glob.o nftw.o openlog.o re_comp.o resolvepath.o realpath.o regcmp.o regexp.o setlogmask.o strftime.o strptime.o swab.o syslog.o tempnam.o wordexp.o mktime.o regalloc.o regclass.o regcoll.o regcomp.o regcache.o regdecomp.o regerror.o regexec.o regfatal.o reginit.o + exec - ${AR} rc libast.a strntonll.o strntol.o strntoll.o strntoul.o strntoull.o strcasecmp.o strncasecmp.o strerror.o mktemp.o tmpnam.o fsync.o execlp.o execve.o execvp.o execvpe.o spawnveg.o vfork.o killpg.o getlogin.o putenv.o setenv.o unsetenv.o lstat.o statvfs.o eaccess.o gross.o omitted.o readlink.o symlink.o getpgrp.o setpgid.o setsid.o fcntl.o open.o atexit.o getdents.o getwd.o dup2.o errno.o getpreroot.o ispreroot.o realopen.o setpreroot.o getgroups.o mount.o system.o iblocks.o modedata.o tmdata.o memfatal.o sfkeyprintf.o sfdcdio.o sfdcdos.o sfdcfilter.o sfdcseekable.o sfdcslow.o sfdcsubstr.o sfdctee.o sfdcunion.o sfdcmore.o sfdcprefix.o wc.o wc2utf8.o basename.o closelog.o dirname.o fmtmsglib.o fnmatch.o ftw.o getdate.o getsubopt.o glob.o nftw.o openlog.o re_comp.o resolvepath.o realpath.o regcmp.o regexp.o setlogmask.o strftime.o strptime.o swab.o syslog.o tempnam.o wordexp.o mktime.o regalloc.o regclass.o regcoll.o regcomp.o regcache.o regdecomp.o regerror.o regexec.o regfatal.o reginit.o exec - ${AR} rc libast.a regnexec.o regsubcomp.o regsubexec.o regsub.o regrecord.o regrexec.o regstat.o dtclose.o dtdisc.o dthash.o dtlist.o dtmethod.o dtopen.o dtstat.o dtstrhash.o dttree.o dtuser.o dtview.o dtwalk.o dtnew.o dtcomp.o sfclose.o sfclrlock.o sfdisc.o sfdlen.o sfexcept.o sfgetl.o sfgetu.o sfcvt.o sfecvt.o sffcvt.o sfextern.o sffilbuf.o sfflsbuf.o sfprints.o sfgetd.o sfgetr.o sfllen.o sfmode.o sfmove.o sfnew.o sfpkrd.o sfnotify.o sfnputc.o sfopen.o sfpeek.o sfpoll.o sfpool.o sfpopen.o sfprintf.o sfputd.o sfputl.o sfputr.o sfputu.o sfrd.o sfread.o sfreserve.o sfscanf.o sfseek.o sfset.o sfsetbuf.o sfsetfd.o sfsize.o sfsk.o sfstack.o sfstrtod.o sfsync.o sfswap.o sftable.o sftell.o sftmp.o sfungetc.o sfvprintf.o sfvscanf.o sfwr.o sfwrite.o sfpurge.o sfraise.o sfwalk.o sfgetm.o sfputm.o sfresize.o _sfclrerr.o _sfeof.o _sferror.o _sffileno.o _sfopen.o _sfstacked.o _sfvalue.o _sfgetc.o _sfgetl.o _sfgetl2.o _sfgetu.o _sfgetu2.o _sfdlen.o _sfllen.o _sfslen.o _sfulen.o _sfputc.o _sfputd.o _sfputl.o _sfputm.o exec - ${AR} rc libast.a _sfputu.o clearerr.o fclose.o fdopen.o fflush.o fgetc.o fgetpos.o fgets.o fopen.o fprintf.o fpurge.o fputs.o fread.o freopen.o fscanf.o fseek.o fseeko.o fsetpos.o ftell.o ftello.o fwrite.o getw.o pclose.o popen.o printf.o putchar.o puts.o putw.o rewind.o scanf.o setbuf.o setbuffer.o setlinebuf.o setvbuf.o snprintf.o sprintf.o sscanf.o asprintf.o vasprintf.o tmpfile.o ungetc.o vfprintf.o vfscanf.o vprintf.o vscanf.o vsnprintf.o vsprintf.o vsscanf.o _doprnt.o _doscan.o _filbuf.o _flsbuf.o _stdopen.o _stdprintf.o _stdscanf.o _stdsprnt.o _stdvbuf.o _stdvsnprnt.o _stdvsprnt.o _stdvsscn.o fgetwc.o fwprintf.o putwchar.o vfwscanf.o wprintf.o fgetws.o fwscanf.o swprintf.o vswprintf.o wscanf.o fputwc.o getwc.o swscanf.o vswscanf.o fputws.o getwchar.o ungetwc.o vwprintf.o fwide.o putwc.o vfwprintf.o vwscanf.o stdio_c99.o fcloseall.o fmemopen.o getdelim.o getline.o frexp.o frexpl.o astcopy.o exec - ${AR} rc libast.a astconf.o astdynamic.o astquery.o astwinsize.o conftab.o aststatic.o getopt.o getoptl.o aso.o asolock.o asometh.o asorelax.o aso-sem.o aso-fcntl.o vmbest.o vmclear.o vmclose.o vmdcheap.o vmdebug.o vmdisc.o vmexit.o vmlast.o vmopen.o vmpool.o vmprivate.o vmprofile.o vmregion.o vmsegment.o vmset.o vmstat.o vmstrdup.o vmtrace.o vmwalk.o vmmopen.o malloc.o vmgetmem.o diff --git a/src/lib/libast/comp/waitpid.c b/src/lib/libast/comp/waitpid.c deleted file mode 100644 index 268ad629acf4..000000000000 --- a/src/lib/libast/comp/waitpid.c +++ /dev/null @@ -1,196 +0,0 @@ -/*********************************************************************** -* * -* This software is part of the ast package * -* Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2022 Contributors to ksh 93u+m * -* and is licensed under the * -* Eclipse Public License, Version 2.0 * -* * -* A copy of the License is available at * -* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html * -* (with md5 checksum 84283fa8859daf213bdda5a9f8d1be1d) * -* * -* Glenn Fowler * -* David Korn * -* Phong Vo * -* Martijn Dekker * -* Johnothan King * -* * -***********************************************************************/ -/* - * POSIX waitpid() - * - * PID < -1 WUNTRACED may not be fully supported - * process group specifics ignored by non-{waitpid,wait4} - */ - -#include -#include - -#if _lib_waitpid - -NoN(waitpid) - -#else - -#if _lib_wait4 - -struct rusage; - -extern int wait4(int, int*, int, struct rusage*); - -pid_t -waitpid(pid_t pid, int* status, int flags) -{ - return(wait4(pid, status, flags, NiL)); -} - -#else - -#undef SIGCLD - -#if _lib_wait3 - -extern int wait3(int*, int, struct rusage*); - -#else - -#if _lib_wait2 - -#define wait3(s,f,u) wait2(s,f) - -extern int wait2(int*, int); - -#else - -#include - -#define wait3(s,f,u) wait(s) - -static int caught; - -static void -catch(sig) -int sig; -{ - NoP(sig); - caught = 1; -} - -#endif - -#endif - -#include - -struct zombie -{ - struct zombie* next; - int status; - pid_t pid; -}; - -pid_t -waitpid(pid_t pid, int* status, int flags) -{ - register struct zombie* zp; - register struct zombie* pp; - register int p; - int s; -#if !_lib_wait2 && !_lib_wait3 -#if !defined(SIGCLD) - int n; - int oerrno; -#endif - Sig_handler_t handler; -#endif - - static struct zombie* zombies; - - pp = 0; - zp = zombies; - while (zp) - { - if (zp->pid >= 0 && (zp->pid == pid || pid <= 0)) - { - if (pp) pp->next = zp->next; - else zombies = zp->next; - if (status) *status = zp->status; - pid = zp->pid; - free(zp); - return(pid); - } - } - if (pid > 0 && kill(pid, 0) < 0) return(-1); - for (;;) - { -#if !_lib_wait2 && !_lib_wait3 -#if !defined(SIGCLD) - oerrno = errno; -#endif - if (flags & WNOHANG) - { - caught = 0; -#if defined(SIGCLD) - handler = signal(SIGCLD, catch); - if (!caught) - { - signal(SIGCLD, handler); - return(0); - } -#else -#if defined(SIGALRM) - handler = signal(SIGALRM, catch); - n = alarm(1); -#endif -#endif - } -#endif - p = wait3(&s, flags, NiL); -#if !_lib_wait3 -#if !_lib_wait2 -#if defined(SIGCLD) - if (flags & WNOHANG) signal(SIGCLD, handler); -#else -#if defined(SIGALRM) - if (flags & WNOHANG) - { - if (n == 0 && !caught || n == 1) alarm(n); - else if (n > 1) alarm(n - caught); - signal(SIGALRM, handler); - } - if (p == -1 && errno == EINTR) - { - errno = oerrno; - p = 0; - s = 0; - } -#endif -#endif -#else - if (p == -1 && errno == EINVAL && (flags & ~WNOHANG)) - p = wait3(&s, flags & WNOHANG, NiL); -#endif -#endif - if (p <= 0) - { - if (p == 0 && status) *status = s; - return(p); - } - if (pid <= 0 || p == pid) - { - if (status) *status = s; - return(p); - } - if (!(zp = newof(0, struct zombie, 1, 0))) return(-1); - zp->pid = p; - zp->status = s; - zp->next = zombies; - zombies = zp; - } - UNREACHABLE(); -} - -#endif - -#endif diff --git a/src/lib/libast/features/signal.c b/src/lib/libast/features/signal.c index d9c9b2ee0952..e4b6e4ab1274 100644 --- a/src/lib/libast/features/signal.c +++ b/src/lib/libast/features/signal.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2022 Contributors to ksh 93u+m * +* Copyright (c) 2020-2023 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -69,10 +69,6 @@ static struct _m_ map[] = #define HAD_SIGCHLD 1 "Child status change", "CHLD", SIGCHLD, #endif -#ifdef SIGCLD -#define HAD_SIGCLD 1 -"Death of child", "CLD", SIGCLD, -#endif #ifdef SIGCONT #define HAD_SIGCONT 1 "Stopped process continued", "CONT", SIGCONT, diff --git a/src/lib/libast/misc/procclose.c b/src/lib/libast/misc/procclose.c index 29111d62e3d0..142dd98d9e28 100644 --- a/src/lib/libast/misc/procclose.c +++ b/src/lib/libast/misc/procclose.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2022 Contributors to ksh 93u+m * +* Copyright (c) 2020-2023 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -67,17 +67,13 @@ procclose(register Proc_t* p) signal(SIGINT, p->sigint); if (p->sigquit != SIG_IGN) signal(SIGQUIT, p->sigquit); -#if defined(SIGCHLD) #if _lib_sigprocmask sigprocmask(SIG_SETMASK, &p->mask, NiL); -#else -#if _lib_sigsetmask +#elif _lib_sigsetmask sigsetmask(p->mask); #else if (p->sigchld != SIG_DFL) signal(SIGCHLD, p->sigchld); -#endif -#endif #endif } status = status == -1 ? diff --git a/src/lib/libast/misc/procopen.c b/src/lib/libast/misc/procopen.c index 5472327d5242..0f384269e0d3 100644 --- a/src/lib/libast/misc/procopen.c +++ b/src/lib/libast/misc/procopen.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2022 Contributors to ksh 93u+m * +* Copyright (c) 2020-2023 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -140,8 +140,6 @@ typedef struct Mod_s #endif /* _use_spawnveg */ -#ifdef SIGPIPE - /* * catch but ignore sig * avoids SIG_IGN being passed to children @@ -153,8 +151,6 @@ ignoresig(int sig) signal(sig, ignoresig); } -#endif /* SIGPIPE */ - /* * do modification op and save previous state for restore() */ @@ -411,9 +407,9 @@ procopen(const char* cmd, char** argv, char** envv, long* modv, int flags) #if !_pipe_rw && !_lib_socketpair int poi[2]; #endif /* !_pipe_rw && !_lib_socketpair */ -#if defined(SIGCHLD) && ( _lib_sigprocmask || _lib_sigsetmask ) +#if _lib_sigprocmask || _lib_sigsetmask Sig_mask_t mask; -#endif /* defined(SIGCHLD) && ( _lib_sigprocmask || _lib_sigsetmask ) */ +#endif /* _lib_sigprocmask || _lib_sigsetmask */ #if _use_spawnveg int newenv = 0; #endif /* _use_spawnveg */ @@ -505,20 +501,16 @@ procopen(const char* cmd, char** argv, char** envv, long* modv, int flags) signalled = 1; proc->sigint = signal(SIGINT, SIG_IGN); proc->sigquit = signal(SIGQUIT, SIG_IGN); -#if defined(SIGCHLD) #if _lib_sigprocmask sigemptyset(&mask); sigaddset(&mask, SIGCHLD); sigprocmask(SIG_BLOCK, &mask, &proc->mask); -#else -#if _lib_sigsetmask +#elif _lib_sigsetmask mask = sigmask(SIGCHLD); proc->mask = sigblock(mask); #else proc->sigchld = signal(SIGCHLD, SIG_DFL); -#endif /* _lib_sigsetmask */ #endif /* _lib_sigprocmask */ -#endif /* defined(SIGCHLD) */ } if ((flags & PROC_ORPHAN) && pipe(pop)) goto bad; @@ -537,18 +529,14 @@ procopen(const char* cmd, char** argv, char** envv, long* modv, int flags) proc->sigquit = SIG_DFL; signal(SIGQUIT, proc->sigquit); } -#if defined(SIGCHLD) #if _lib_sigprocmask sigprocmask(SIG_SETMASK, &proc->mask, NiL); -#else -#if _lib_sigsetmask +#elif _lib_sigsetmask sigsetmask(proc->mask); #else if (proc->sigchld != SIG_IGN) signal(SIGCHLD, SIG_DFL); -#endif /* _lib_sigsetmask */ #endif /* _lib_sigprocmask */ -#endif /* defined(SIGCHLD) */ } else if (proc->pid == -1) goto bad; @@ -591,26 +579,16 @@ procopen(const char* cmd, char** argv, char** envv, long* modv, int flags) #endif /* DEBUG_PROC */ if (flags & PROC_DAEMON) { -#ifdef SIGHUP modify(proc, forked, PROC_sig_ign, SIGHUP, 0); -#endif /* SIGHUP */ modify(proc, forked, PROC_sig_dfl, SIGTERM, 0); -#ifdef SIGTSTP modify(proc, forked, PROC_sig_ign, SIGTSTP, 0); -#endif /* SIGTSTP */ -#ifdef SIGTTIN modify(proc, forked, PROC_sig_ign, SIGTTIN, 0); -#endif /* SIGTTIN */ -#ifdef SIGTTOU modify(proc, forked, PROC_sig_ign, SIGTTOU, 0); -#endif /* SIGTTOU */ } if (flags & (PROC_BACKGROUND|PROC_DAEMON)) { modify(proc, forked, PROC_sig_ign, SIGINT, 0); -#ifdef SIGQUIT modify(proc, forked, PROC_sig_ign, SIGQUIT, 0); -#endif /* SIGQUIT */ } if (flags & (PROC_DAEMON|PROC_SESSION)) modify(proc, forked, PROC_sys_pgrp, -1, 0); @@ -785,20 +763,16 @@ procopen(const char* cmd, char** argv, char** envv, long* modv, int flags) signalled = 1; proc->sigint = signal(SIGINT, SIG_IGN); proc->sigquit = signal(SIGQUIT, SIG_IGN); -#if defined(SIGCHLD) #if _lib_sigprocmask sigemptyset(&mask); sigaddset(&mask, SIGCHLD); sigprocmask(SIG_BLOCK, &mask, &proc->mask); -#else -#if _lib_sigsetmask +#elif _lib_sigsetmask mask = sigmask(SIGCHLD); proc->mask = sigblock(mask); #else proc->sigchld = signal(SIGCHLD, SIG_DFL); -#endif /* _lib_sigsetmask */ #endif /* _lib_sigprocmask */ -#endif /* defined(SIGCHLD) */ } } else if (modv) @@ -823,7 +797,6 @@ procopen(const char* cmd, char** argv, char** envv, long* modv, int flags) } if (procfd >= 0) { -#ifdef SIGPIPE if ((flags & (PROC_WRITE|PROC_IGNORE)) == (PROC_WRITE|PROC_IGNORE)) { Handler_t handler; @@ -831,7 +804,6 @@ procopen(const char* cmd, char** argv, char** envv, long* modv, int flags) if ((handler = signal(SIGPIPE, ignoresig)) != SIG_DFL && handler != ignoresig) signal(SIGPIPE, handler); } -#endif /* SIGPIPE */ switch (procfd) { case 0: @@ -874,18 +846,14 @@ procopen(const char* cmd, char** argv, char** envv, long* modv, int flags) signal(SIGINT, proc->sigint); if (proc->sigquit != SIG_IGN) signal(SIGQUIT, proc->sigquit); -#if defined(SIGCHLD) #if _lib_sigprocmask sigprocmask(SIG_SETMASK, &proc->mask, NiL); -#else -#if _lib_sigsetmask +#elif _lib_sigsetmask sigsetmask(proc->mask); #else if (proc->sigchld != SIG_DFL) signal(SIGCHLD, proc->sigchld); -#endif /* _lib_sigsetmask */ #endif /* _lib_sigprocmask */ -#endif /* defined(SIGCHLD) */ } if ((flags & PROC_CLEANUP) && modv) for (i = 0; n = modv[i]; i++) diff --git a/src/lib/libast/misc/sigcrit.c b/src/lib/libast/misc/sigcrit.c index dac775edb09a..508e488daff3 100644 --- a/src/lib/libast/misc/sigcrit.c +++ b/src/lib/libast/misc/sigcrit.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2022 Contributors to ksh 93u+m * +* Copyright (c) 2020-2023 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -34,27 +34,13 @@ static struct signals[] = /* held inside critical region */ { SIGINT, SIG_REG_EXEC, -#ifdef SIGPIPE SIGPIPE, SIG_REG_EXEC, -#endif -#ifdef SIGQUIT SIGQUIT, SIG_REG_EXEC, -#endif -#ifdef SIGHUP SIGHUP, SIG_REG_EXEC, -#endif -#if defined(SIGCHLD) && ( !defined(SIGCLD) || SIGCHLD != SIGCLD || _lib_sigprocmask || _lib_sigsetmask ) SIGCHLD, SIG_REG_PROC, -#endif -#ifdef SIGTSTP SIGTSTP, SIG_REG_TERM, -#endif -#ifdef SIGTTIN SIGTTIN, SIG_REG_TERM, -#endif -#ifdef SIGTTOU SIGTTOU, SIG_REG_TERM, -#endif }; #ifndef SIG_SETMASK diff --git a/src/lib/libast/misc/signal.c b/src/lib/libast/misc/signal.c index 01636ec6a9f1..66466b5422fd 100644 --- a/src/lib/libast/misc/signal.c +++ b/src/lib/libast/misc/signal.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2022 Contributors to ksh 93u+m * +* Copyright (c) 2020-2023 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -86,19 +86,12 @@ signal(int sig, Sig_handler_t fun) #if defined(SA_INTERRUPT) || defined(SA_RESTART) switch (sig) { -#if defined(SIGIO) || defined(SIGTSTP) || defined(SIGTTIN) || defined(SIGTTOU) #if defined(SIGIO) case SIGIO: #endif -#if defined(SIGTSTP) case SIGTSTP: -#endif -#if defined(SIGTTIN) case SIGTTIN: -#endif -#if defined(SIGTTOU) case SIGTTOU: -#endif #if defined(SA_RESTART) na.sa_flags = SA_RESTART; #endif @@ -110,7 +103,6 @@ signal(int sig, Sig_handler_t fun) #endif break; } -#endif if (sigaction(sig, &na, &oa)) return 0; if (unblock) diff --git a/src/lib/libast/sfio/sfmode.c b/src/lib/libast/sfio/sfmode.c index 959ad745f976..455627dff7fb 100644 --- a/src/lib/libast/sfio/sfmode.c +++ b/src/lib/libast/sfio/sfmode.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2022 Contributors to ksh 93u+m * +* Copyright (c) 2020-2023 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -56,9 +56,7 @@ static char* Version = "\n@(#)$Id: sfio (AT&T Labs - Research) 2009-09-15 $\0\n" #include typedef void(* Sfsignal_f)(int); #endif -#ifdef SIGPIPE static int _Sfsigp = 0; /* # of streams needing SIGPIPE protection */ -#endif /* done at exiting time */ static void _sfcleanup(void) @@ -196,7 +194,7 @@ int _sfpopen(reg Sfio_t* f, int fd, int pid, int stdio) /* stdio popen() does no p->file = fd; p->sigp = (!stdio && pid >= 0 && (f->flags&SF_WRITE)) ? 1 : 0; -#ifdef SIGPIPE /* protect from broken pipe signal */ + /* protect from broken pipe signal */ if(p->sigp) { Sfsignal_f handler; @@ -204,7 +202,6 @@ int _sfpopen(reg Sfio_t* f, int fd, int pid, int stdio) /* stdio popen() does no signal(SIGPIPE, handler); /* honor user handler */ _Sfsigp += 1; } -#endif return 0; } @@ -243,15 +240,12 @@ int _sfpclose(reg Sfio_t* f) EXIT_CODE(WEXITSTATUS(status)); sigcritical(0); #endif - -#ifdef SIGPIPE if(p->sigp && (_Sfsigp -= 1) <= 0) { Sfsignal_f handler; if((handler = signal(SIGPIPE,SIG_DFL)) != SIG_DFL && handler != SIG_IGN) signal(SIGPIPE,handler); /* honor user handler */ _Sfsigp = 0; } -#endif } free(p);