1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-10-27 16:50:58 +01:00

45058: internal: Add symbolic names to possible values of zexit()'s "from_where" parameter. No functional change.

This commit is contained in:
Daniel Shahaf 2019-12-17 04:43:48 +00:00
parent 2cb15a23f8
commit 8bc4400762
9 changed files with 40 additions and 25 deletions

View file

@ -1,5 +1,10 @@
2019-12-17 Daniel Shahaf <danielsh@apache.org> 2019-12-17 Daniel Shahaf <danielsh@apache.org>
* 45058: Src/Modules/zpty.c, Src/Zle/zle_main.c, Src/builtin.c,
Src/exec.c, Src/init.c, Src/signals.c, Src/subst.c, Src/zsh.h:
internal: Add symbolic names to possible values of zexit()'s
"from_where" parameter. No functional change.
* unposted: Src/builtin.c: Update comment to reflect variable * unposted: Src/builtin.c: Update comment to reflect variable
rename in 41012 (zsh-5.3.1-182-gd7110d8f0). rename in 41012 (zsh-5.3.1-182-gd7110d8f0).

View file

@ -426,7 +426,7 @@ newptycmd(char *nam, char *pname, char **args, int echo, int nblock)
execode(prog, 1, 0, "zpty"); execode(prog, 1, 0, "zpty");
stopmsg = 2; stopmsg = 2;
mypid = 0; /* trick to ensure we _exit() */ mypid = 0; /* trick to ensure we _exit() */
zexit(lastval, 0); zexit(lastval, ZEXIT_NORMAL);
} }
master = movefd(master); master = movefd(master);
if (master == -1) { if (master == -1) {

View file

@ -905,7 +905,7 @@ getbyte(long do_keytmout, int *timeout, int full)
if ((zlereadflags & ZLRF_IGNOREEOF) && icnt++ < 20) if ((zlereadflags & ZLRF_IGNOREEOF) && icnt++ < 20)
continue; continue;
stopmsg = 1; stopmsg = 1;
zexit(1, 0); zexit(1, ZEXIT_NORMAL);
} }
icnt = 0; icnt = 0;
if (errno == EINTR) { if (errno == EINTR) {
@ -928,7 +928,7 @@ getbyte(long do_keytmout, int *timeout, int full)
} else if (errno != 0) { } else if (errno != 0) {
zerr("error on TTY read: %e", errno); zerr("error on TTY read: %e", errno);
stopmsg = 1; stopmsg = 1;
zexit(1, 0); zexit(1, ZEXIT_NORMAL);
} }
} }
if (cc == '\r') /* undo the exchange of \n and \r determined by */ if (cc == '\r') /* undo the exchange of \n and \r determined by */

View file

@ -5665,7 +5665,7 @@ bin_break(char *name, char **argv, UNUSED(Options ops), int func)
} }
return lastval; return lastval;
} }
zexit(num, 0); /* else treat return as logout/exit */ zexit(num, ZEXIT_NORMAL); /* else treat return as logout/exit */
break; break;
case BIN_LOGOUT: case BIN_LOGOUT:
if (unset(LOGINSHELL)) { if (unset(LOGINSHELL)) {
@ -5687,7 +5687,7 @@ bin_break(char *name, char **argv, UNUSED(Options ops), int func)
* If we are already exiting... give this all up as * If we are already exiting... give this all up as
* a bad job. * a bad job.
*/ */
if (stopmsg || (zexit(0,2), !stopmsg)) { if (stopmsg || (zexit(0, ZEXIT_DEFERRED), !stopmsg)) {
retflag = 1; retflag = 1;
breaks = loops; breaks = loops;
exit_pending = 1; exit_pending = 1;
@ -5695,7 +5695,7 @@ bin_break(char *name, char **argv, UNUSED(Options ops), int func)
exit_val = num; exit_val = num;
} }
} else } else
zexit(num, 0); zexit(num, ZEXIT_NORMAL);
break; break;
} }
return 0; return 0;
@ -5780,14 +5780,15 @@ _realexit(void)
/* exit the shell. val is the return value of the shell. * /* exit the shell. val is the return value of the shell. *
* from_where is * from_where is
* 1 if zexit is called because of a signal * ZEXIT_SIGNAL if zexit is called because of a signal
* 2 if we can't actually exit yet (e.g. functions need * ZEXIT_DEFERRED if we can't actually exit yet (e.g., functions need
* terminating) but should perform the usual interactive tests. * terminating) but should perform the usual interactive
* tests.
*/ */
/**/ /**/
mod_export void mod_export void
zexit(int val, int from_where) zexit(int val, enum zexit_t from_where)
{ {
/* /*
* Don't do anything recursively: see below. * Don't do anything recursively: see below.
@ -5798,7 +5799,7 @@ zexit(int val, int from_where)
if (shell_exiting == -1) if (shell_exiting == -1)
return; return;
if (isset(MONITOR) && !stopmsg && from_where != 1) { if (isset(MONITOR) && !stopmsg && from_where != ZEXIT_SIGNAL) {
scanjobs(); /* check if jobs need printing */ scanjobs(); /* check if jobs need printing */
if (isset(CHECKJOBS)) if (isset(CHECKJOBS))
checkjobs(); /* check if any jobs are running/stopped */ checkjobs(); /* check if any jobs are running/stopped */
@ -5808,7 +5809,8 @@ zexit(int val, int from_where)
} }
} }
/* Positive shell_exiting means we have been here before */ /* Positive shell_exiting means we have been here before */
if (from_where == 2 || (shell_exiting++ && from_where)) if (from_where == ZEXIT_DEFERRED ||
(shell_exiting++ && from_where != ZEXIT_NORMAL))
return; return;
/* /*
@ -5824,12 +5826,12 @@ zexit(int val, int from_where)
if (isset(MONITOR)) { if (isset(MONITOR)) {
/* send SIGHUP to any jobs left running */ /* send SIGHUP to any jobs left running */
killrunjobs(from_where == 1); killrunjobs(from_where == ZEXIT_SIGNAL);
} }
if (isset(RCS) && interact) { if (isset(RCS) && interact) {
if (!nohistsave) { if (!nohistsave) {
int writeflags = HFILE_USE_OPTIONS; int writeflags = HFILE_USE_OPTIONS;
if (from_where == 1) if (from_where == ZEXIT_SIGNAL)
writeflags |= HFILE_NO_REWRITE; writeflags |= HFILE_NO_REWRITE;
saveandpophiststack(1, writeflags); saveandpophiststack(1, writeflags);
savehistfile(NULL, 1, writeflags); savehistfile(NULL, 1, writeflags);

View file

@ -5949,7 +5949,7 @@ doshfunc(Shfunc shfunc, LinkList doshargs, int noreturnval)
* exit command was handled. * exit command was handled.
*/ */
stopmsg = 1; stopmsg = 1;
zexit(exit_val, 0); zexit(exit_val, ZEXIT_NORMAL);
} }
} }

View file

@ -161,7 +161,7 @@ loop(int toplevel, int justonce)
* Handle that now. * Handle that now.
*/ */
stopmsg = 1; stopmsg = 1;
zexit(exit_val, 0); zexit(exit_val, ZEXIT_NORMAL);
} }
if (tok == LEXERR && !lastval) if (tok == LEXERR && !lastval)
lastval = 1; lastval = 1;
@ -1371,7 +1371,7 @@ init_misc(char *cmd, char *zsh_name)
bshin = fdopen(SHIN, "r"); bshin = fdopen(SHIN, "r");
execstring(cmd, 0, 1, "cmdarg"); execstring(cmd, 0, 1, "cmdarg");
stopmsg = 1; stopmsg = 1;
zexit((exit_pending || shell_exiting) ? exit_val : lastval, 0); zexit((exit_pending || shell_exiting) ? exit_val : lastval, ZEXIT_NORMAL);
} }
if (interact && isset(RCS)) if (interact && isset(RCS))
@ -1778,20 +1778,20 @@ zsh_main(UNUSED(int argc), char **argv)
if (!lastval) if (!lastval)
lastval = 1; lastval = 1;
stopmsg = 1; stopmsg = 1;
zexit(lastval, 0); zexit(lastval, ZEXIT_NORMAL);
} }
if (!(isset(IGNOREEOF) && interact)) { if (!(isset(IGNOREEOF) && interact)) {
#if 0 #if 0
if (interact) if (interact)
fputs(islogin ? "logout\n" : "exit\n", shout); fputs(islogin ? "logout\n" : "exit\n", shout);
#endif #endif
zexit(lastval, 0); zexit(lastval, ZEXIT_NORMAL);
continue; continue;
} }
noexitct++; noexitct++;
if (noexitct >= 10) { if (noexitct >= 10) {
stopmsg = 1; stopmsg = 1;
zexit(lastval, 0); zexit(lastval, ZEXIT_NORMAL);
} }
/* /*
* Don't print the message if it was already handled by * Don't print the message if it was already handled by

View file

@ -654,7 +654,7 @@ zhandler(int sig)
_exit(SIGPIPE); _exit(SIGPIPE);
else if (!isatty(SHTTY)) { else if (!isatty(SHTTY)) {
stopmsg = 1; stopmsg = 1;
zexit(SIGPIPE, 1); zexit(SIGPIPE, ZEXIT_SIGNAL);
} }
} }
break; break;
@ -662,7 +662,7 @@ zhandler(int sig)
case SIGHUP: case SIGHUP:
if (!handletrap(SIGHUP)) { if (!handletrap(SIGHUP)) {
stopmsg = 1; stopmsg = 1;
zexit(SIGHUP, 1); zexit(SIGHUP, ZEXIT_SIGNAL);
} }
break; break;
@ -670,7 +670,7 @@ zhandler(int sig)
if (!handletrap(SIGINT)) { if (!handletrap(SIGINT)) {
if ((isset(PRIVILEGED) || isset(RESTRICTED)) && if ((isset(PRIVILEGED) || isset(RESTRICTED)) &&
isset(INTERACTIVE) && (noerrexit & NOERREXIT_SIGNAL)) isset(INTERACTIVE) && (noerrexit & NOERREXIT_SIGNAL))
zexit(SIGINT, 1); zexit(SIGINT, ZEXIT_SIGNAL);
if (list_pipe || chline || simple_pline) { if (list_pipe || chline || simple_pline) {
breaks = loops; breaks = loops;
errflag |= ERRFLAG_INT; errflag |= ERRFLAG_INT;
@ -703,7 +703,7 @@ zhandler(int sig)
errflag = noerrs = 0; errflag = noerrs = 0;
zwarn("timeout"); zwarn("timeout");
stopmsg = 1; stopmsg = 1;
zexit(SIGALRM, 1); zexit(SIGALRM, ZEXIT_SIGNAL);
} }
} }
break; break;

View file

@ -3044,7 +3044,7 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags,
* shouldn't be any if not interactive. * shouldn't be any if not interactive.
*/ */
stopmsg = 1; stopmsg = 1;
zexit(1, 0); zexit(1, ZEXIT_NORMAL);
} else } else
_exit(1); _exit(1);
} }

View file

@ -3222,6 +3222,14 @@ enum {
/* Hooks in core. */ /* Hooks in core. */
/***************************************/ /***************************************/
/* The type of zexit()'s second parameter, which see. */
enum zexit_t {
/* This isn't a bitfield. The values are here just for explicitness. */
ZEXIT_NORMAL = 0,
ZEXIT_SIGNAL = 1,
ZEXIT_DEFERRED = 2
};
#define EXITHOOK (zshhooks + 0) #define EXITHOOK (zshhooks + 0)
#define BEFORETRAPHOOK (zshhooks + 1) #define BEFORETRAPHOOK (zshhooks + 1)
#define AFTERTRAPHOOK (zshhooks + 2) #define AFTERTRAPHOOK (zshhooks + 2)