Skip to content

Commit

Permalink
cleanup: rm JOBS symbol, POSIX signal ifdefs, waitpid(2) fallback
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
McDutchie committed Mar 4, 2023
1 parent e500628 commit da74ed6
Show file tree
Hide file tree
Showing 22 changed files with 75 additions and 538 deletions.
10 changes: 3 additions & 7 deletions src/cmd/ksh93/bltins/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
* *
Expand Down Expand Up @@ -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)--;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
8 changes: 1 addition & 7 deletions src/cmd/ksh93/bltins/trap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
* *
Expand Down Expand Up @@ -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') /* <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)
Expand Down Expand Up @@ -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 $$'
*/
Expand Down Expand Up @@ -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
Expand Down
10 changes: 0 additions & 10 deletions src/cmd/ksh93/data/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 "]"
Expand Down Expand Up @@ -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]"
Expand Down
32 changes: 14 additions & 18 deletions src/cmd/ksh93/data/msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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])";
Expand Down
29 changes: 2 additions & 27 deletions src/cmd/ksh93/data/signals.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
* *
Expand All @@ -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)<<SH_SIGBITS))
#define TRAP(n) (((n)|SH_TRAP)-1)

Expand Down Expand Up @@ -61,16 +57,7 @@ const struct shtable2 shtab_signals[] =
"CANCEL", VAL(SIGCANCEL,SH_SIGIGNORE), S("Thread cancellation"),
#endif /*SIGCANCEL */
#ifdef SIGCHLD
"CHLD", VAL(SIGCHLD,SH_SIGFAULT), S("Death of Child"),
# ifdef SIGCLD
# if SIGCLD!=SIGCHLD
"CLD", VAL(SIGCLD,SH_SIGFAULT), S("Death of Child"),
# endif
# endif /* SIGCLD */
#else
# ifdef SIGCLD
"CLD", VAL(SIGCLD,SH_SIGFAULT), S("Death of Child"),
# endif /* SIGCLD */
"CHLD", VAL(SIGCHLD,SH_SIGFAULT), S("Child process terminated or stopped"),
#endif /* SIGCHLD */
#ifdef SIGCONT
"CONT", VAL(SIGCONT,SH_SIGIGNORE), S("Stopped process continued"),
Expand Down Expand Up @@ -102,11 +89,7 @@ const struct shtable2 shtab_signals[] =
#endif /* SIGGRANT */
"HUP", VAL(SIGHUP,SH_SIGDONE), S("Hangup"),
"ILL", VAL(SIGILL,SH_SIGDONE), S("Illegal instruction"),
#ifdef JOBS
"INT", VAL(SIGINT,SH_SIGINTERACTIVE), S("Interrupt"),
#else
"INT", VAL(SIGINT,SH_SIGINTERACTIVE), "",
#endif /* JOBS */
#ifdef SIGINFO
"INFO", VAL(SIGINFO,SH_SIGIGNORE), S("Information request"),
#endif /* SIGINFO */
Expand Down Expand Up @@ -148,11 +131,7 @@ const struct shtable2 shtab_signals[] =
"PHONE", VAL(SIGPHONE,0), S("Phone interrupt"),
#endif /* SIGPHONE */
#ifdef SIGPIPE
#ifdef JOBS
"PIPE", VAL(SIGPIPE,SH_SIGDONE), S("Broken Pipe"),
#else
"PIPE", VAL(SIGPIPE,SH_SIGDONE), "",
#endif /* JOBS */
#endif /* SIGPIPE */
#ifdef SIGPOLL
"POLL", VAL(SIGPOLL,SH_SIGDONE), S("Polling alarm"),
Expand Down Expand Up @@ -201,11 +180,7 @@ const struct shtable2 shtab_signals[] =
"THAW", VAL(SIGTHAW,SH_SIGIGNORE), S("Special signal used by CPR"),
#endif /* SIGTHAW */
#ifdef SIGTINT
# ifdef JOBS
"TINT", VAL(SIGTINT,0), S("Interrupt"),
# else
"TINT", VAL(SIGTINT,0), "",
# endif /* JOBS */
#endif /* SIGTINT */
#ifdef SIGTRAP
"TRAP", VAL(SIGTRAP,SH_SIGDONE), S("Trace/BPT trap"),
Expand Down
16 changes: 4 additions & 12 deletions src/cmd/ksh93/include/builtins.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,10 @@ extern int b_unset(int, char*[],Shbltin_t*);
extern int b_unalias(int, char*[],Shbltin_t*);

/* The following are for job control */
#if defined(SIGCLD) || defined(SIGCHLD)
extern int b_jobs(int, char*[],Shbltin_t*);
extern int b_kill(int, char*[],Shbltin_t*);
# ifdef SIGTSTP
extern int b_bg(int, char*[],Shbltin_t*);
# endif /* SIGTSTP */
# ifdef SIGSTOP
extern int b_suspend(int, char*[],Shbltin_t*);
# endif /* SIGSTOP */
#endif
extern int b_jobs(int, char*[],Shbltin_t*);
extern int b_kill(int, char*[],Shbltin_t*);
extern int b_bg(int, char*[],Shbltin_t*);
extern int b_suspend(int, char*[],Shbltin_t*);

/* The following utilities are built-in because of side-effects */
extern int b_builtin(int, char*[],Shbltin_t*);
Expand Down Expand Up @@ -182,10 +176,8 @@ extern const char sh_opthist[];
#endif /* !SHOPT_SCRIPTONLY */
extern const char sh_optjobs[];
extern const char sh_optkill[];
#if defined(JOBS) && defined(SIGSTOP)
extern const char sh_optstop[];
extern const char sh_optsuspend[];
#endif /* defined(JOBS) && defined(SIGSTOP) */
extern const char sh_optksh[];
extern const char sh_optlet[];
extern const char sh_optprint[];
Expand Down
53 changes: 14 additions & 39 deletions src/cmd/ksh93/include/jobs.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* *
* This software is part of the ast package *
* Copyright (c) 1982-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 *
* *
Expand Down Expand Up @@ -32,27 +32,17 @@
#endif /* !SIGINT */
#include "FEATURE/options"
#include <aso.h>
#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
{
Expand All @@ -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
Expand All @@ -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 */
Expand All @@ -109,8 +95,6 @@ struct jobs

extern struct jobs job;

#ifdef JOBS

#if !_std_malloc
#include <vmalloc.h>
#ifdef vmlocked
Expand Down Expand Up @@ -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
Expand All @@ -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 */
3 changes: 1 addition & 2 deletions src/cmd/ksh93/sh.1
Original file line number Diff line number Diff line change
Expand Up @@ -6948,8 +6948,7 @@ option or by name with the
option
(as given in
.BR <signal.h> ,
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
Expand Down
Loading

0 comments on commit da74ed6

Please sign in to comment.