1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

Decrease SHLVL before doing 'exec' from main shell

Problem:

$ exec ksh
$ echo $SHLVL
2
$ exec ksh
$ echo $SHLVL
3
$ exec ksh
$ echo $SHLVL
4

...etc. SHLVL is supposed to acount the number of shell processes
that you need to exit before you get logged out. Since ksh was
replacing itself with a new shell in the same process using 'exec',
SHLVL should not increase.

src/cmd/ksh93/bltins/misc.c: b_exec():
- When about to replace the shell and we're not in a subshell,
  decrease SHLVL to cancel out a subsequent increase by the
  replacing shell. Bash and zsh also do this.
This commit is contained in:
Martijn Dekker 2021-05-19 00:02:49 +02:00
parent c828ea8d0d
commit e5e1d4b53e
4 changed files with 15 additions and 3 deletions

4
NEWS
View file

@ -3,6 +3,10 @@ For full details, see the git log at: https://github.com/ksh93/ksh
Any uppercase BUG_* names are modernish shell bug IDs. Any uppercase BUG_* names are modernish shell bug IDs.
2021-05-18:
- Fixed SHLVL so that replacing ksh by itself (exec ksh) will not increase it.
2021-05-13: 2021-05-13:
- Fixed a bug with 'test -t 1' that was introduced on 2021-04-26: - Fixed a bug with 'test -t 1' that was introduced on 2021-04-26:

View file

@ -161,6 +161,9 @@ int b_exec(int argc,char *argv[], Shbltin_t *context)
if(job_close(logdata.sh) < 0) if(job_close(logdata.sh) < 0)
return(1); return(1);
#endif /* JOBS */ #endif /* JOBS */
/* if the main shell is about to be replaced, decrease SHLVL to cancel out a subsequent increase */
if(!shgd->realsubshell)
(*SHLVL->nvalue.ip)--;
/* force bad exec to terminate shell */ /* force bad exec to terminate shell */
pp = (struct checkpt*)logdata.sh->jmplist; pp = (struct checkpt*)logdata.sh->jmplist;
pp->mode = SH_JMPEXIT; pp->mode = SH_JMPEXIT;

View file

@ -21,7 +21,7 @@
#define SH_RELEASE_FORK "93u+m" /* only change if you develop a new ksh93 fork */ #define SH_RELEASE_FORK "93u+m" /* only change if you develop a new ksh93 fork */
#define SH_RELEASE_SVER "1.0.0-beta.2" /* semantic version number: https://semver.org */ #define SH_RELEASE_SVER "1.0.0-beta.2" /* semantic version number: https://semver.org */
#define SH_RELEASE_DATE "2021-05-13" /* must be in this format for $((.sh.version)) */ #define SH_RELEASE_DATE "2021-05-18" /* must be in this format for $((.sh.version)) */
#define SH_RELEASE_CPYR "(c) 2020-2021 Contributors to ksh " SH_RELEASE_FORK #define SH_RELEASE_CPYR "(c) 2020-2021 Contributors to ksh " SH_RELEASE_FORK
/* Scripts sometimes field-split ${.sh.version}, so don't change amount of whitespace. */ /* Scripts sometimes field-split ${.sh.version}, so don't change amount of whitespace. */

View file

@ -1802,8 +1802,8 @@ be the value that was assigned plus the number of seconds since the assignment.
.TP .TP
.SM .SM
.B SHLVL .B SHLVL
An integer variable the is incremented each time the shell An integer variable that is incremented and exported
is invoked and is exported. each time the shell is invoked.
If If
.SM .SM
.B SHLVL .B SHLVL
@ -6028,6 +6028,11 @@ is given,
the command specified by the command specified by
the arguments is executed in place of this shell the arguments is executed in place of this shell
without creating a new process. without creating a new process.
The value of the
.SM
.B SHLVL
environment variable is decreased by one,
unless the shell replaced is a subshell.
The The
.B \-c .B \-c
option causes the environment to be cleared before applying option causes the environment to be cleared before applying