diff --git a/NEWS b/NEWS index e6349b635..bbe407ffa 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,11 @@ For full details, see the git log at: https://github.com/ksh93/ksh/tree/1.0 Any uppercase BUG_* names are modernish shell bug IDs. +2022-07-27: + +- Fixed a bug introduced on 2022-02-08 where $PPID was incorrect when a script + without a #! path was executed. + 2022-07-26: - Fixed incorrect handling of initial zeros in test/[ and [[ arithmetic diff --git a/src/cmd/ksh93/include/shell.h b/src/cmd/ksh93/include/shell.h index d61caf737..d411259ef 100644 --- a/src/cmd/ksh93/include/shell.h +++ b/src/cmd/ksh93/include/shell.h @@ -250,6 +250,7 @@ struct Shell_s pid_t pid; /* $$, the main shell's PID (invariable) */ pid_t ppid; /* $PPID, the main shell's parent's PID */ pid_t current_pid; /* ${.sh.pid}, PID of current ksh process (updates when subshell forks) */ + pid_t current_ppid; /* PPID of current ksh process (updates when subshell forks) */ unsigned char sigruntime[2]; Namval_t *bltin_nodes; Namval_t *bltin_cmds; diff --git a/src/cmd/ksh93/include/version.h b/src/cmd/ksh93/include/version.h index fe3503a52..5aa32ded7 100644 --- a/src/cmd/ksh93/include/version.h +++ b/src/cmd/ksh93/include/version.h @@ -22,8 +22,8 @@ #include #define SH_RELEASE_FORK "93u+m" /* only change if you develop a new ksh93 fork */ -#define SH_RELEASE_SVER "1.0.0-rc.2" /* semantic version number: https://semver.org */ -#define SH_RELEASE_DATE "2022-07-26" /* must be in this format for $((.sh.version)) */ +#define SH_RELEASE_SVER "1.0.0-rc.3" /* semantic version number: https://semver.org */ +#define SH_RELEASE_DATE "2022-07-27" /* must be in this format for $((.sh.version)) */ #define SH_RELEASE_CPYR "(c) 2020-2022 Contributors to ksh " SH_RELEASE_FORK /* Scripts sometimes field-split ${.sh.version}, so don't change amount of whitespace. */ diff --git a/src/cmd/ksh93/sh/init.c b/src/cmd/ksh93/sh/init.c index d5dbfa37c..0314bae08 100644 --- a/src/cmd/ksh93/sh/init.c +++ b/src/cmd/ksh93/sh/init.c @@ -1276,7 +1276,7 @@ Shell_t *sh_init(register int argc,register char *argv[], Shinit_f userinit) sh_regress_init(); #endif sh.current_pid = sh.pid = getpid(); - sh.ppid = getppid(); + sh.current_ppid = sh.ppid = getppid(); sh.userid=getuid(); sh.euserid=geteuid(); sh.groupid=getgid(); @@ -1697,9 +1697,9 @@ int sh_reinit(char *argv[]) sh.inpipe = sh.outpipe = 0; job_clear(); job.in_critical = 0; - /* update ${.sh.pid}, $$, $PPID */ - sh.ppid = sh.current_pid; - sh.current_pid = sh.pid = getpid(); + /* update $$, $PPID */ + sh.ppid = sh.current_ppid; + sh.pid = sh.current_pid; /* call user init function, if any */ if(sh.userinit) (*sh.userinit)(&sh, 1); diff --git a/src/cmd/ksh93/sh/xec.c b/src/cmd/ksh93/sh/xec.c index 6d024378d..9b962d432 100644 --- a/src/cmd/ksh93/sh/xec.c +++ b/src/cmd/ksh93/sh/xec.c @@ -2852,6 +2852,7 @@ pid_t _sh_fork(register pid_t parent,int flags,int *jobid) vmtrace(-1); #endif /* This is the child process */ + sh.current_ppid = sh.current_pid; sh.current_pid = getpid(); /* ${.sh.pid} */ sh.outpipepid = ((flags&FPOU)?sh.current_pid:0); if(sh.trapnote&SH_SIGTERM) diff --git a/src/cmd/ksh93/tests/variables.sh b/src/cmd/ksh93/tests/variables.sh index eef45c049..61eb54454 100755 --- a/src/cmd/ksh93/tests/variables.sh +++ b/src/cmd/ksh93/tests/variables.sh @@ -147,9 +147,16 @@ fi # PPID exp=$$ got=${ $SHELL -c 'print $PPID'; } -if [[ ${ $SHELL -c 'print $PPID'; } != $$ ]] -then err_exit "PPID variable failed -- expected '$exp', got '$got'" -fi +[[ $got == $$ ]] || err_exit "PPID variable failed in -c script -- expected '$exp', got '$got'" +print 'print $PPID' >ppid.sh +chmod +x ppid.sh +./ppid.sh >|out +got=$(|ppid.sh +./ppid.sh >|out +got=$(