aboutsummaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2025-09-07 09:37:02 +0100
committerRon Yorston <rmy@pobox.com>2025-09-07 09:43:26 +0100
commit5fefada144ed3cf22ba24e7812b57ecf52e3e2ac (patch)
treee9e407ee0f1eef50e64d74e0584f78be2d0023bc /shell
parent01fbdbf4b48cedf0869e010ef5ccb817d6677e42 (diff)
downloadbusybox-w32-5fefada144ed3cf22ba24e7812b57ecf52e3e2ac.tar.gz
busybox-w32-5fefada144ed3cf22ba24e7812b57ecf52e3e2ac.tar.bz2
busybox-w32-5fefada144ed3cf22ba24e7812b57ecf52e3e2ac.zip
ash: rename got_sigchld, doing_jobctl, and INT_ON/OFF to match dash
Merge upstream commit 9f490785e. The changes are cosmetic, to bring the code into line with dash.
Diffstat (limited to 'shell')
-rw-r--r--shell/ash.c316
1 files changed, 158 insertions, 158 deletions
diff --git a/shell/ash.c b/shell/ash.c
index 656f3d73b..dd3c885f4 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -595,7 +595,7 @@ struct globals_misc {
595 */ 595 */
596 volatile /*sig_atomic_t*/ smallint pending_int; /* 1 = got SIGINT */ 596 volatile /*sig_atomic_t*/ smallint pending_int; /* 1 = got SIGINT */
597#if !ENABLE_PLATFORM_MINGW32 597#if !ENABLE_PLATFORM_MINGW32
598 volatile /*sig_atomic_t*/ smallint got_sigchld; /* 1 = got SIGCHLD */ 598 volatile /*sig_atomic_t*/ smallint gotsigchld; /* 1 = got SIGCHLD */
599 volatile /*sig_atomic_t*/ smallint pending_sig; /* last pending signal */ 599 volatile /*sig_atomic_t*/ smallint pending_sig; /* last pending signal */
600#endif 600#endif
601 smallint exception_type; /* kind of exception: */ 601 smallint exception_type; /* kind of exception: */
@@ -708,7 +708,7 @@ extern struct globals_misc *BB_GLOBAL_CONST ash_ptr_to_globals_misc;
708#define exception_type (G_misc.exception_type ) 708#define exception_type (G_misc.exception_type )
709#define suppress_int (G_misc.suppress_int ) 709#define suppress_int (G_misc.suppress_int )
710#define pending_int (G_misc.pending_int ) 710#define pending_int (G_misc.pending_int )
711#define got_sigchld (G_misc.got_sigchld ) 711#define gotsigchld (G_misc.gotsigchld )
712#define pending_sig (G_misc.pending_sig ) 712#define pending_sig (G_misc.pending_sig )
713#define nullstr (G_misc.nullstr ) 713#define nullstr (G_misc.nullstr )
714#define optlist (G_misc.optlist ) 714#define optlist (G_misc.optlist )
@@ -860,13 +860,13 @@ static void exitshell(void) NORETURN;
860 * more fun than worrying about efficiency and portability. :-)) 860 * more fun than worrying about efficiency and portability. :-))
861 */ 861 */
862#if DEBUG_INTONOFF 862#if DEBUG_INTONOFF
863# define INT_OFF do { \ 863# define INTOFF do { \
864 TRACE(("%s:%d INT_OFF(%d)\n", __func__, __LINE__, suppress_int)); \ 864 TRACE(("%s:%d INTOFF(%d)\n", __func__, __LINE__, suppress_int)); \
865 suppress_int++; \ 865 suppress_int++; \
866 barrier(); \ 866 barrier(); \
867} while (0) 867} while (0)
868#else 868#else
869# define INT_OFF do { \ 869# define INTOFF do { \
870 suppress_int++; \ 870 suppress_int++; \
871 barrier(); \ 871 barrier(); \
872} while (0) 872} while (0)
@@ -885,7 +885,7 @@ raise_exception(int e)
885 if (exception_handler == NULL) 885 if (exception_handler == NULL)
886 abort(); 886 abort();
887#endif 887#endif
888 INT_OFF; 888 INTOFF;
889 exception_type = e; 889 exception_type = e;
890 longjmp(exception_handler->loc, 1); 890 longjmp(exception_handler->loc, 1);
891} 891}
@@ -900,7 +900,7 @@ raise_exception(int e)
900 * Called when a SIGINT is received. (If the user specifies 900 * Called when a SIGINT is received. (If the user specifies
901 * that SIGINT is to be trapped or ignored using the trap builtin, then 901 * that SIGINT is to be trapped or ignored using the trap builtin, then
902 * this routine is not called.) suppress_int is nonzero when interrupts 902 * this routine is not called.) suppress_int is nonzero when interrupts
903 * are held using the INT_OFF macro. (The test for iflag is just 903 * are held using the INTOFF macro. (The test for iflag is just
904 * defensive programming.) 904 * defensive programming.)
905 */ 905 */
906static void raise_interrupt(void) IF_NOT_PLATFORM_MINGW32(NORETURN); 906static void raise_interrupt(void) IF_NOT_PLATFORM_MINGW32(NORETURN);
@@ -958,12 +958,12 @@ int_on(void)
958 barrier(); 958 barrier();
959} 959}
960#if DEBUG_INTONOFF 960#if DEBUG_INTONOFF
961# define INT_ON do { \ 961# define INTON do { \
962 TRACE(("%s:%d INT_ON(%d)\n", __func__, __LINE__, suppress_int-1)); \ 962 TRACE(("%s:%d INTON(%d)\n", __func__, __LINE__, suppress_int-1)); \
963 int_on(); \ 963 int_on(); \
964} while (0) 964} while (0)
965#else 965#else
966# define INT_ON int_on() 966# define INTON int_on()
967#endif 967#endif
968static IF_NOT_ASH_OPTIMIZE_FOR_SIZE(inline) void 968static IF_NOT_ASH_OPTIMIZE_FOR_SIZE(inline) void
969force_int_on(void) 969force_int_on(void)
@@ -974,7 +974,7 @@ force_int_on(void)
974 raise_interrupt(); /* does not return */ 974 raise_interrupt(); /* does not return */
975 barrier(); 975 barrier();
976} 976}
977#define FORCE_INT_ON force_int_on() 977#define FORCEINTON force_int_on()
978 978
979#define SAVE_INT(v) ((v) = suppress_int) 979#define SAVE_INT(v) ((v) = suppress_int)
980 980
@@ -992,27 +992,27 @@ force_int_on(void)
992static void 992static void
993outstr(const char *p, FILE *file) 993outstr(const char *p, FILE *file)
994{ 994{
995 INT_OFF; 995 INTOFF;
996 fputs(p, file); 996 fputs(p, file);
997 INT_ON; 997 INTON;
998} 998}
999 999
1000static void 1000static void
1001flush_stdout_stderr(void) 1001flush_stdout_stderr(void)
1002{ 1002{
1003 INT_OFF; 1003 INTOFF;
1004 fflush_all(); 1004 fflush_all();
1005 INT_ON; 1005 INTON;
1006} 1006}
1007 1007
1008/* Was called outcslow(c,FILE*), but c was always '\n' */ 1008/* Was called outcslow(c,FILE*), but c was always '\n' */
1009static void 1009static void
1010newline_and_flush(FILE *dest) 1010newline_and_flush(FILE *dest)
1011{ 1011{
1012 INT_OFF; 1012 INTOFF;
1013 putc('\n', dest); 1013 putc('\n', dest);
1014 fflush(dest); 1014 fflush(dest);
1015 INT_ON; 1015 INTON;
1016} 1016}
1017 1017
1018static int out1fmt(const char *, ...) __attribute__((__format__(__printf__,1,2))); 1018static int out1fmt(const char *, ...) __attribute__((__format__(__printf__,1,2)));
@@ -1022,11 +1022,11 @@ out1fmt(const char *fmt, ...)
1022 va_list ap; 1022 va_list ap;
1023 int r; 1023 int r;
1024 1024
1025 INT_OFF; 1025 INTOFF;
1026 va_start(ap, fmt); 1026 va_start(ap, fmt);
1027 r = vprintf(fmt, ap); 1027 r = vprintf(fmt, ap);
1028 va_end(ap); 1028 va_end(ap);
1029 INT_ON; 1029 INTON;
1030 return r; 1030 return r;
1031} 1031}
1032 1032
@@ -1037,11 +1037,11 @@ fmtstr(char *outbuf, size_t length, const char *fmt, ...)
1037 va_list ap; 1037 va_list ap;
1038 int ret; 1038 int ret;
1039 1039
1040 INT_OFF; 1040 INTOFF;
1041 va_start(ap, fmt); 1041 va_start(ap, fmt);
1042 ret = vsnprintf(outbuf, length, fmt, ap); 1042 ret = vsnprintf(outbuf, length, fmt, ap);
1043 va_end(ap); 1043 va_end(ap);
1044 INT_ON; 1044 INTON;
1045 return ret > (int)length ? length : ret; 1045 return ret > (int)length ? length : ret;
1046} 1046}
1047 1047
@@ -1896,14 +1896,14 @@ stalloc(size_t nbytes)
1896 len = sizeof(struct stack_block) - MINSIZE + blocksize; 1896 len = sizeof(struct stack_block) - MINSIZE + blocksize;
1897 if (len < blocksize) 1897 if (len < blocksize)
1898 ash_msg_and_raise_error(bb_msg_memory_exhausted); 1898 ash_msg_and_raise_error(bb_msg_memory_exhausted);
1899 INT_OFF; 1899 INTOFF;
1900 sp = ckmalloc(len); 1900 sp = ckmalloc(len);
1901 sp->prev = g_stackp; 1901 sp->prev = g_stackp;
1902 g_stacknxt = sp->space; 1902 g_stacknxt = sp->space;
1903 g_stacknleft = blocksize; 1903 g_stacknleft = blocksize;
1904 sstrend = g_stacknxt + blocksize; 1904 sstrend = g_stacknxt + blocksize;
1905 g_stackp = sp; 1905 g_stackp = sp;
1906 INT_ON; 1906 INTON;
1907 } 1907 }
1908 p = g_stacknxt; 1908 p = g_stacknxt;
1909 g_stacknxt += aligned; 1909 g_stacknxt += aligned;
@@ -1969,7 +1969,7 @@ popstackmark(struct stackmark *mark)
1969 if (!mark->stackp) 1969 if (!mark->stackp)
1970 return; 1970 return;
1971 1971
1972 INT_OFF; 1972 INTOFF;
1973 while (g_stackp != mark->stackp) { 1973 while (g_stackp != mark->stackp) {
1974 sp = g_stackp; 1974 sp = g_stackp;
1975 g_stackp = sp->prev; 1975 g_stackp = sp->prev;
@@ -1978,7 +1978,7 @@ popstackmark(struct stackmark *mark)
1978 g_stacknxt = mark->stacknxt; 1978 g_stacknxt = mark->stacknxt;
1979 g_stacknleft = mark->stacknleft; 1979 g_stacknleft = mark->stacknleft;
1980 sstrend = mark->stacknxt + mark->stacknleft; 1980 sstrend = mark->stacknxt + mark->stacknleft;
1981 INT_ON; 1981 INTON;
1982} 1982}
1983 1983
1984/* 1984/*
@@ -2007,7 +2007,7 @@ growstackblock(size_t min)
2007 struct stack_block *prevstackp; 2007 struct stack_block *prevstackp;
2008 size_t grosslen; 2008 size_t grosslen;
2009 2009
2010 INT_OFF; 2010 INTOFF;
2011 sp = g_stackp; 2011 sp = g_stackp;
2012 prevstackp = sp->prev; 2012 prevstackp = sp->prev;
2013 grosslen = newlen + sizeof(struct stack_block) - MINSIZE; 2013 grosslen = newlen + sizeof(struct stack_block) - MINSIZE;
@@ -2017,7 +2017,7 @@ growstackblock(size_t min)
2017 g_stacknxt = sp->space; 2017 g_stacknxt = sp->space;
2018 g_stacknleft = newlen; 2018 g_stacknleft = newlen;
2019 sstrend = sp->space + newlen; 2019 sstrend = sp->space + newlen;
2020 INT_ON; 2020 INTON;
2021 } else { 2021 } else {
2022 char *oldspace = g_stacknxt; 2022 char *oldspace = g_stacknxt;
2023 size_t oldlen = g_stacknleft; 2023 size_t oldlen = g_stacknleft;
@@ -2877,7 +2877,7 @@ setvar(const char *name, const char *val, int flags)
2877 vallen = strlen(val); 2877 vallen = strlen(val);
2878 } 2878 }
2879 2879
2880 INT_OFF; 2880 INTOFF;
2881 nameeq = ckzalloc(namelen + vallen + 2); 2881 nameeq = ckzalloc(namelen + vallen + 2);
2882 p = mempcpy(nameeq, name, namelen); 2882 p = mempcpy(nameeq, name, namelen);
2883 if (val) { 2883 if (val) {
@@ -2885,7 +2885,7 @@ setvar(const char *name, const char *val, int flags)
2885 strcpy(p, val); 2885 strcpy(p, val);
2886 } 2886 }
2887 vp = setvareq(nameeq, flags | VNOSAVE); 2887 vp = setvareq(nameeq, flags | VNOSAVE);
2888 INT_ON; 2888 INTON;
2889 2889
2890 return vp; 2890 return vp;
2891} 2891}
@@ -3440,7 +3440,7 @@ setpwd(const char *val, int setold)
3440 if (setold) { 3440 if (setold) {
3441 setvar("OLDPWD", oldcur, VEXPORT); 3441 setvar("OLDPWD", oldcur, VEXPORT);
3442 } 3442 }
3443 INT_OFF; 3443 INTOFF;
3444 if (physdir != nullstr) { 3444 if (physdir != nullstr) {
3445 if (physdir != oldcur) 3445 if (physdir != oldcur)
3446 free(physdir); 3446 free(physdir);
@@ -3457,7 +3457,7 @@ setpwd(const char *val, int setold)
3457 free(oldcur); 3457 free(oldcur);
3458 } 3458 }
3459 curdir = dir; 3459 curdir = dir;
3460 INT_ON; 3460 INTON;
3461 setvar("PWD", dir, VEXPORT); 3461 setvar("PWD", dir, VEXPORT);
3462} 3462}
3463 3463
@@ -3475,7 +3475,7 @@ docd(const char *dest, int flags)
3475 3475
3476 TRACE(("docd(\"%s\", %d) called\n", dest, flags)); 3476 TRACE(("docd(\"%s\", %d) called\n", dest, flags));
3477 3477
3478 INT_OFF; 3478 INTOFF;
3479 if (!(flags & CD_PHYSICAL)) { 3479 if (!(flags & CD_PHYSICAL)) {
3480 dir = updatepwd(dest); 3480 dir = updatepwd(dest);
3481 if (dir) 3481 if (dir)
@@ -3487,7 +3487,7 @@ docd(const char *dest, int flags)
3487 setpwd(dir, 1); 3487 setpwd(dir, 1);
3488 hashcd(); 3488 hashcd();
3489 out: 3489 out:
3490 INT_ON; 3490 INTON;
3491 return err; 3491 return err;
3492} 3492}
3493 3493
@@ -4074,7 +4074,7 @@ setalias(const char *name, const char *val)
4074 4074
4075 app = __lookupalias(name); 4075 app = __lookupalias(name);
4076 ap = *app; 4076 ap = *app;
4077 INT_OFF; 4077 INTOFF;
4078 if (ap) { 4078 if (ap) {
4079 if (!(ap->flag & ALIASINUSE)) { 4079 if (!(ap->flag & ALIASINUSE)) {
4080 free(ap->val); 4080 free(ap->val);
@@ -4090,7 +4090,7 @@ setalias(const char *name, const char *val)
4090 /*ap->next = NULL;*/ 4090 /*ap->next = NULL;*/
4091 *app = ap; 4091 *app = ap;
4092 } 4092 }
4093 INT_ON; 4093 INTON;
4094} 4094}
4095 4095
4096static int 4096static int
@@ -4101,9 +4101,9 @@ unalias(const char *name)
4101 app = __lookupalias(name); 4101 app = __lookupalias(name);
4102 4102
4103 if (*app) { 4103 if (*app) {
4104 INT_OFF; 4104 INTOFF;
4105 *app = freealias(*app); 4105 *app = freealias(*app);
4106 INT_ON; 4106 INTON;
4107 return 0; 4107 return 0;
4108 } 4108 }
4109 4109
@@ -4116,7 +4116,7 @@ rmaliases(void)
4116 struct alias *ap, **app; 4116 struct alias *ap, **app;
4117 int i; 4117 int i;
4118 4118
4119 INT_OFF; 4119 INTOFF;
4120 for (i = 0; i < ATABSIZE; i++) { 4120 for (i = 0; i < ATABSIZE; i++) {
4121 app = &atab[i]; 4121 app = &atab[i];
4122 for (ap = *app; ap; ap = *app) { 4122 for (ap = *app; ap; ap = *app) {
@@ -4126,7 +4126,7 @@ rmaliases(void)
4126 } 4126 }
4127 } 4127 }
4128 } 4128 }
4129 INT_ON; 4129 INTON;
4130} 4130}
4131 4131
4132static void 4132static void
@@ -4254,13 +4254,13 @@ static int forkshell(struct job *, union node *, int);
4254static int waitforjob(struct job *); 4254static int waitforjob(struct job *);
4255 4255
4256#if !JOBS && !JOBS_WIN32 4256#if !JOBS && !JOBS_WIN32
4257enum { doing_jobctl = 0 }; 4257enum { jobctl = 0 };
4258#define setjobctl(on) do {} while (0) 4258#define setjobctl(on) do {} while (0)
4259#elif JOBS_WIN32 4259#elif JOBS_WIN32
4260static smallint doing_jobctl; //references:8 4260static smallint jobctl; //references:8
4261#define setjobctl(on) do { if (rootshell) doing_jobctl = on; } while (0) 4261#define setjobctl(on) do { if (rootshell) jobctl = on; } while (0)
4262#else /* JOBS */ 4262#else /* JOBS */
4263static smallint doing_jobctl; //references:8 4263static smallint jobctl; //references:8
4264static void setjobctl(int); 4264static void setjobctl(int);
4265#endif 4265#endif
4266 4266
@@ -4286,7 +4286,7 @@ static void
4286signal_handler(int signo) 4286signal_handler(int signo)
4287{ 4287{
4288 if (signo == SIGCHLD) { 4288 if (signo == SIGCHLD) {
4289 got_sigchld = 1; 4289 gotsigchld = 1;
4290 if (!trap[SIGCHLD]) 4290 if (!trap[SIGCHLD])
4291 return; 4291 return;
4292 } 4292 }
@@ -4658,7 +4658,7 @@ freejob(struct job *jp)
4658 int i; 4658 int i;
4659#endif 4659#endif
4660 4660
4661 INT_OFF; 4661 INTOFF;
4662#if ENABLE_PLATFORM_POSIX || JOBS_WIN32 4662#if ENABLE_PLATFORM_POSIX || JOBS_WIN32
4663 for (i = jp->nprocs, ps = jp->ps; --i >= 0; ps++) { 4663 for (i = jp->nprocs, ps = jp->ps; --i >= 0; ps++) {
4664 if (ps->ps_cmd != nullstr) 4664 if (ps->ps_cmd != nullstr)
@@ -4669,7 +4669,7 @@ freejob(struct job *jp)
4669 free(jp->ps); 4669 free(jp->ps);
4670 jp->used = 0; 4670 jp->used = 0;
4671 set_curjob(jp, CUR_DELETE); 4671 set_curjob(jp, CUR_DELETE);
4672 INT_ON; 4672 INTON;
4673} 4673}
4674 4674
4675#if JOBS 4675#if JOBS
@@ -4695,7 +4695,7 @@ setjobctl(int on)
4695 int fd; 4695 int fd;
4696 int pgrp; 4696 int pgrp;
4697 4697
4698 if (on == doing_jobctl || rootshell == 0) 4698 if (on == jobctl || rootshell == 0)
4699 return; 4699 return;
4700 if (on) { 4700 if (on) {
4701 int ofd; 4701 int ofd;
@@ -4755,7 +4755,7 @@ setjobctl(int on)
4755 fd = -1; 4755 fd = -1;
4756 } 4756 }
4757 ttyfd = fd; 4757 ttyfd = fd;
4758 doing_jobctl = on; 4758 jobctl = on;
4759} 4759}
4760#endif 4760#endif
4761 4761
@@ -4844,7 +4844,7 @@ restartjob(struct job *jp, int mode)
4844 int status; 4844 int status;
4845 pid_t pgid; 4845 pid_t pgid;
4846 4846
4847 INT_OFF; 4847 INTOFF;
4848 if (jp->state == JOBDONE) 4848 if (jp->state == JOBDONE)
4849 goto out; 4849 goto out;
4850 jp->state = JOBRUNNING; 4850 jp->state = JOBRUNNING;
@@ -4864,7 +4864,7 @@ restartjob(struct job *jp, int mode)
4864 } while (--i); 4864 } while (--i);
4865 out: 4865 out:
4866 status = (mode == FORK_FG) ? waitforjob(jp) : 0; 4866 status = (mode == FORK_FG) ? waitforjob(jp) : 0;
4867 INT_ON; 4867 INTON;
4868 return status; 4868 return status;
4869} 4869}
4870 4870
@@ -5001,12 +5001,12 @@ waitproc(int block, int *status)
5001 int err; 5001 int err;
5002 5002
5003#if JOBS 5003#if JOBS
5004 if (doing_jobctl) 5004 if (jobctl)
5005 flags |= WUNTRACED; 5005 flags |= WUNTRACED;
5006#endif 5006#endif
5007 5007
5008 do { 5008 do {
5009 got_sigchld = 0; 5009 gotsigchld = 0;
5010 do 5010 do
5011 err = waitpid(-1, status, flags); 5011 err = waitpid(-1, status, flags);
5012 while (err < 0 && errno == EINTR); 5012 while (err < 0 && errno == EINTR);
@@ -5016,14 +5016,14 @@ waitproc(int block, int *status)
5016 5016
5017 sigfillset(&oldmask); 5017 sigfillset(&oldmask);
5018 sigprocmask2(SIG_SETMASK, &oldmask); /* mask is updated */ 5018 sigprocmask2(SIG_SETMASK, &oldmask); /* mask is updated */
5019 while (!got_sigchld && !pending_sig) 5019 while (!gotsigchld && !pending_sig)
5020 sigsuspend(&oldmask); 5020 sigsuspend(&oldmask);
5021 sigprocmask(SIG_SETMASK, &oldmask, NULL); 5021 sigprocmask(SIG_SETMASK, &oldmask, NULL);
5022 //simpler, but unsafe: a signal can set pending_sig after check, but before pause(): 5022 //simpler, but unsafe: a signal can set pending_sig after check, but before pause():
5023 //while (!got_sigchld && !pending_sig) 5023 //while (!gotsigchld && !pending_sig)
5024 // pause(); 5024 // pause();
5025 5025
5026 } while (got_sigchld); 5026 } while (gotsigchld);
5027 5027
5028 return err; 5028 return err;
5029#else 5029#else
@@ -5047,25 +5047,25 @@ waitone(int block, struct job *job)
5047 5047
5048 TRACE(("dowait(0x%x) called\n", block)); 5048 TRACE(("dowait(0x%x) called\n", block));
5049 5049
5050 /* It's wrong to call waitpid() outside of INT_OFF region: 5050 /* It's wrong to call waitpid() outside of INTOFF region:
5051 * signal can arrive just after syscall return and handler can 5051 * signal can arrive just after syscall return and handler can
5052 * longjmp away, losing stop/exit notification processing. 5052 * longjmp away, losing stop/exit notification processing.
5053 * Thus, for "jobs" builtin, and for waiting for a fg job, 5053 * Thus, for "jobs" builtin, and for waiting for a fg job,
5054 * we call waitpid() (blocking or non-blocking) inside INT_OFF. 5054 * we call waitpid() (blocking or non-blocking) inside INTOFF.
5055 * 5055 *
5056 * However, for "wait" builtin it is wrong to simply call waitpid() 5056 * However, for "wait" builtin it is wrong to simply call waitpid()
5057 * in INT_OFF region: "wait" needs to wait for any running job 5057 * in INTOFF region: "wait" needs to wait for any running job
5058 * to change state, but should exit on any trap too. 5058 * to change state, but should exit on any trap too.
5059 * In INT_OFF region, a signal just before syscall entry can set 5059 * In INTOFF region, a signal just before syscall entry can set
5060 * pending_sig variables, but we can't check them, and we would 5060 * pending_sig variables, but we can't check them, and we would
5061 * either enter a sleeping waitpid() (BUG), or need to busy-loop. 5061 * either enter a sleeping waitpid() (BUG), or need to busy-loop.
5062 * 5062 *
5063 * Because of this, we run inside INT_OFF, but use a special routine 5063 * Because of this, we run inside INTOFF, but use a special routine
5064 * which combines waitpid() and sigsuspend(). 5064 * which combines waitpid() and sigsuspend().
5065 * This is the reason why we need to have a handler for SIGCHLD: 5065 * This is the reason why we need to have a handler for SIGCHLD:
5066 * SIG_DFL handler does not wake sigsuspend(). 5066 * SIG_DFL handler does not wake sigsuspend().
5067 */ 5067 */
5068 INT_OFF; 5068 INTOFF;
5069 pid = waitproc(block, &status); 5069 pid = waitproc(block, &status);
5070 TRACE(("wait returns pid %d, status=%d\n", pid, status)); 5070 TRACE(("wait returns pid %d, status=%d\n", pid, status));
5071 if (pid <= 0) 5071 if (pid <= 0)
@@ -5127,7 +5127,7 @@ waitone(int block, struct job *job)
5127 } 5127 }
5128 /* The process wasn't found in job list */ 5128 /* The process wasn't found in job list */
5129 out: 5129 out:
5130 INT_ON; 5130 INTON;
5131 5131
5132#if BASH_WAIT_N 5132#if BASH_WAIT_N
5133 if (want_jobexitstatus) { 5133 if (want_jobexitstatus) {
@@ -5154,7 +5154,7 @@ static int
5154dowait(int block, struct job *jp) 5154dowait(int block, struct job *jp)
5155{ 5155{
5156#if !ENABLE_PLATFORM_MINGW32 5156#if !ENABLE_PLATFORM_MINGW32
5157 smallint gotchld = *(volatile smallint *)&got_sigchld; 5157 smallint gotchld = *(volatile smallint *)&gotsigchld;
5158 int rpid; 5158 int rpid;
5159 int pid; 5159 int pid;
5160 5160
@@ -5513,7 +5513,7 @@ makejob(int nprocs)
5513 if (jp->state != JOBDONE || !jp->waited) 5513 if (jp->state != JOBDONE || !jp->waited)
5514 continue; 5514 continue;
5515#if JOBS || JOBS_WIN32 5515#if JOBS || JOBS_WIN32
5516 if (doing_jobctl) 5516 if (jobctl)
5517 continue; 5517 continue;
5518#endif 5518#endif
5519 freejob(jp); 5519 freejob(jp);
@@ -5522,8 +5522,8 @@ makejob(int nprocs)
5522 memset(jp, 0, sizeof(*jp)); 5522 memset(jp, 0, sizeof(*jp));
5523#if JOBS 5523#if JOBS
5524 /* jp->jobctl is a bitfield. 5524 /* jp->jobctl is a bitfield.
5525 * "jp->jobctl |= doing_jobctl" likely to give awful code */ 5525 * "jp->jobctl |= jobctl" likely to give awful code */
5526 if (doing_jobctl) 5526 if (jobctl)
5527 jp->jobctl = 1; 5527 jp->jobctl = 1;
5528#endif 5528#endif
5529 jp->prev_job = curjob; 5529 jp->prev_job = curjob;
@@ -5860,7 +5860,7 @@ clear_traps(void)
5860{ 5860{
5861 char **tp; 5861 char **tp;
5862 5862
5863 INT_OFF; 5863 INTOFF;
5864 for (tp = trap; tp <= &trap[NTRAP_LAST]; tp++) { 5864 for (tp = trap; tp <= &trap[NTRAP_LAST]; tp++) {
5865 if (*tp && **tp) { /* trap not NULL or "" (SIG_IGN) */ 5865 if (*tp && **tp) { /* trap not NULL or "" (SIG_IGN) */
5866 if (trap_ptr == trap) 5866 if (trap_ptr == trap)
@@ -5872,7 +5872,7 @@ clear_traps(void)
5872 } 5872 }
5873 } 5873 }
5874 may_have_traps = 0; 5874 may_have_traps = 0;
5875 INT_ON; 5875 INTON;
5876} 5876}
5877 5877
5878#if !ENABLE_PLATFORM_MINGW32 5878#if !ENABLE_PLATFORM_MINGW32
@@ -5944,7 +5944,7 @@ forkchild(struct job *jp, union node *n, int mode)
5944 clear_traps(); 5944 clear_traps();
5945#if JOBS 5945#if JOBS
5946 /* do job control only in root shell */ 5946 /* do job control only in root shell */
5947 doing_jobctl = 0; 5947 jobctl = 0;
5948 if (mode != FORK_NOJOB && jp->jobctl && oldlvl == 0) { 5948 if (mode != FORK_NOJOB && jp->jobctl && oldlvl == 0) {
5949 pid_t pgrp; 5949 pid_t pgrp;
5950 5950
@@ -6052,7 +6052,7 @@ forkparent(struct job *jp, union node *n, int mode, HANDLE proc)
6052 ps->ps_proc = proc; 6052 ps->ps_proc = proc;
6053#endif 6053#endif
6054#if JOBS || JOBS_WIN32 6054#if JOBS || JOBS_WIN32
6055 if (doing_jobctl && n) 6055 if (jobctl && n)
6056 ps->ps_cmd = commandtext(n); 6056 ps->ps_cmd = commandtext(n);
6057#endif 6057#endif
6058 } 6058 }
@@ -6604,7 +6604,7 @@ redirect(union node *redir, int flags)
6604 return; 6604 return;
6605 6605
6606 sv = NULL; 6606 sv = NULL;
6607 INT_OFF; 6607 INTOFF;
6608 if (flags & REDIR_PUSH) 6608 if (flags & REDIR_PUSH)
6609 sv = redirlist; 6609 sv = redirlist;
6610 do { 6610 do {
@@ -6669,7 +6669,7 @@ redirect(union node *redir, int flags)
6669#endif 6669#endif
6670 } 6670 }
6671 } while ((redir = redir->nfile.next) != NULL); 6671 } while ((redir = redir->nfile.next) != NULL);
6672 INT_ON; 6672 INTON;
6673 6673
6674//dash:#define REDIR_SAVEFD2 03 /* set preverrout */ 6674//dash:#define REDIR_SAVEFD2 03 /* set preverrout */
6675#define REDIR_SAVEFD2 0 6675#define REDIR_SAVEFD2 0
@@ -6757,7 +6757,7 @@ popredir(int drop)
6757 6757
6758 if (redirlist == NULL) 6758 if (redirlist == NULL)
6759 return; 6759 return;
6760 INT_OFF; 6760 INTOFF;
6761 rp = redirlist; 6761 rp = redirlist;
6762 for (i = 0; i < rp->pair_count; i++) { 6762 for (i = 0; i < rp->pair_count; i++) {
6763 int fd = rp->two_fd[i].orig_fd; 6763 int fd = rp->two_fd[i].orig_fd;
@@ -6777,7 +6777,7 @@ popredir(int drop)
6777 } 6777 }
6778 redirlist = rp->next; 6778 redirlist = rp->next;
6779 free(rp); 6779 free(rp);
6780 INT_ON; 6780 INTON;
6781} 6781}
6782 6782
6783static void 6783static void
@@ -6804,11 +6804,11 @@ ash_arith(const char *s)
6804 math_state.setvar = setvar0; 6804 math_state.setvar = setvar0;
6805 //math_state.endofname = endofname; 6805 //math_state.endofname = endofname;
6806 6806
6807 INT_OFF; 6807 INTOFF;
6808 result = arith(&math_state, s); 6808 result = arith(&math_state, s);
6809 if (math_state.errmsg) 6809 if (math_state.errmsg)
6810 ash_msg_and_raise_error(math_state.errmsg); 6810 ash_msg_and_raise_error(math_state.errmsg);
6811 INT_ON; 6811 INTON;
6812 6812
6813 return result; 6813 return result;
6814} 6814}
@@ -7029,7 +7029,7 @@ ifsfree(void)
7029 if (!p) 7029 if (!p)
7030 goto out; 7030 goto out;
7031 7031
7032 INT_OFF; 7032 INTOFF;
7033 do { 7033 do {
7034 struct ifsregion *ifsp; 7034 struct ifsregion *ifsp;
7035 ifsp = p->next; 7035 ifsp = p->next;
@@ -7037,7 +7037,7 @@ ifsfree(void)
7037 p = ifsp; 7037 p = ifsp;
7038 } while (p); 7038 } while (p);
7039 ifsfirst.next = NULL; 7039 ifsfirst.next = NULL;
7040 INT_ON; 7040 INTON;
7041 out: 7041 out:
7042 ifslastp = NULL; 7042 ifslastp = NULL;
7043} 7043}
@@ -7252,11 +7252,11 @@ recordregion(int start, int end, int nulonly)
7252 if (ifslastp == NULL) { 7252 if (ifslastp == NULL) {
7253 ifsp = &ifsfirst; 7253 ifsp = &ifsfirst;
7254 } else { 7254 } else {
7255 INT_OFF; 7255 INTOFF;
7256 ifsp = ckzalloc(sizeof(*ifsp)); 7256 ifsp = ckzalloc(sizeof(*ifsp));
7257 /*ifsp->next = NULL; - ckzalloc did it */ 7257 /*ifsp->next = NULL; - ckzalloc did it */
7258 ifslastp->next = ifsp; 7258 ifslastp->next = ifsp;
7259 INT_ON; 7259 INTON;
7260 } 7260 }
7261 ifslastp = ifsp; 7261 ifslastp = ifsp;
7262 ifslastp->begoff = start; 7262 ifslastp->begoff = start;
@@ -7273,11 +7273,11 @@ removerecordregions(int endoff)
7273 if (ifsfirst.endoff > endoff) { 7273 if (ifsfirst.endoff > endoff) {
7274 while (ifsfirst.next) { 7274 while (ifsfirst.next) {
7275 struct ifsregion *ifsp; 7275 struct ifsregion *ifsp;
7276 INT_OFF; 7276 INTOFF;
7277 ifsp = ifsfirst.next->next; 7277 ifsp = ifsfirst.next->next;
7278 free(ifsfirst.next); 7278 free(ifsfirst.next);
7279 ifsfirst.next = ifsp; 7279 ifsfirst.next = ifsp;
7280 INT_ON; 7280 INTON;
7281 } 7281 }
7282 if (ifsfirst.begoff > endoff) { 7282 if (ifsfirst.begoff > endoff) {
7283 ifslastp = NULL; 7283 ifslastp = NULL;
@@ -7293,11 +7293,11 @@ removerecordregions(int endoff)
7293 ifslastp = ifslastp->next; 7293 ifslastp = ifslastp->next;
7294 while (ifslastp->next) { 7294 while (ifslastp->next) {
7295 struct ifsregion *ifsp; 7295 struct ifsregion *ifsp;
7296 INT_OFF; 7296 INTOFF;
7297 ifsp = ifslastp->next->next; 7297 ifsp = ifslastp->next->next;
7298 free(ifslastp->next); 7298 free(ifslastp->next);
7299 ifslastp->next = ifsp; 7299 ifslastp->next = ifsp;
7300 INT_ON; 7300 INTON;
7301 } 7301 }
7302 if (ifslastp->endoff > endoff) 7302 if (ifslastp->endoff > endoff)
7303 ifslastp->endoff = endoff; 7303 ifslastp->endoff = endoff;
@@ -7422,7 +7422,7 @@ evalbackcmd(union node *n, struct backcmd *result
7422#else 7422#else
7423 if (forkshell(jp, n, FORK_NOJOB) == 0) { 7423 if (forkshell(jp, n, FORK_NOJOB) == 0) {
7424 /* child */ 7424 /* child */
7425 FORCE_INT_ON; 7425 FORCEINTON;
7426 close(pip[ip]); 7426 close(pip[ip]);
7427 /* ic is index of child end of pipe *and* fd to connect it to */ 7427 /* ic is index of child end of pipe *and* fd to connect it to */
7428 if (pip[ic] != ic) { 7428 if (pip[ic] != ic) {
@@ -7484,7 +7484,7 @@ expbackq(union node *cmd, int flag IF_BASH_PROCESS_SUBST(, int ctl))
7484 if (flag & EXP_DISCARD) 7484 if (flag & EXP_DISCARD)
7485 goto out; 7485 goto out;
7486 7486
7487 INT_OFF; 7487 INTOFF;
7488 startloc = expdest - (char *)stackblock(); 7488 startloc = expdest - (char *)stackblock();
7489 pushstackmark(&smark, startloc); 7489 pushstackmark(&smark, startloc);
7490 evalbackcmd(cmd, &in IF_BASH_PROCESS_SUBST(, ctl)); 7490 evalbackcmd(cmd, &in IF_BASH_PROCESS_SUBST(, ctl));
@@ -7518,7 +7518,7 @@ expbackq(union node *cmd, int flag IF_BASH_PROCESS_SUBST(, int ctl))
7518 back_exitstatus = waitforjob(in.jp); 7518 back_exitstatus = waitforjob(in.jp);
7519 } 7519 }
7520 done: 7520 done:
7521 INT_ON; 7521 INTON;
7522 7522
7523 /* Eat all trailing newlines */ 7523 /* Eat all trailing newlines */
7524 dest = expdest; 7524 dest = expdest;
@@ -8622,7 +8622,7 @@ expandmeta(struct strlist *str /*, int flag*/)
8622 if (!hasmeta(str->text)) 8622 if (!hasmeta(str->text))
8623 goto nometa; 8623 goto nometa;
8624 8624
8625 INT_OFF; 8625 INTOFF;
8626 p = preglob(str->text, RMESCAPE_ALLOC | RMESCAPE_HEAP); 8626 p = preglob(str->text, RMESCAPE_ALLOC | RMESCAPE_HEAP);
8627// GLOB_NOMAGIC (GNU): if no *?[ chars in pattern, return it even if no match 8627// GLOB_NOMAGIC (GNU): if no *?[ chars in pattern, return it even if no match
8628// GLOB_NOCHECK: if no match, return unchanged pattern (sans \* escapes?) 8628// GLOB_NOCHECK: if no match, return unchanged pattern (sans \* escapes?)
@@ -8653,12 +8653,12 @@ expandmeta(struct strlist *str /*, int flag*/)
8653#endif 8653#endif
8654 addglob(&pglob); 8654 addglob(&pglob);
8655 globfree(&pglob); 8655 globfree(&pglob);
8656 INT_ON; 8656 INTON;
8657 break; 8657 break;
8658 case GLOB_NOMATCH: 8658 case GLOB_NOMATCH:
8659 //nometa2: 8659 //nometa2:
8660 globfree(&pglob); 8660 globfree(&pglob);
8661 INT_ON; 8661 INTON;
8662 nometa: 8662 nometa:
8663 *exparg.lastp = str; 8663 *exparg.lastp = str;
8664 rmescapes(str->text, 0, NULL); 8664 rmescapes(str->text, 0, NULL);
@@ -8666,7 +8666,7 @@ expandmeta(struct strlist *str /*, int flag*/)
8666 break; 8666 break;
8667 default: /* GLOB_NOSPACE */ 8667 default: /* GLOB_NOSPACE */
8668 globfree(&pglob); 8668 globfree(&pglob);
8669 INT_ON; 8669 INTON;
8670 ash_msg_and_raise_error(bb_msg_memory_exhausted); 8670 ash_msg_and_raise_error(bb_msg_memory_exhausted);
8671 } 8671 }
8672 str = str->next; 8672 str = str->next;
@@ -8926,7 +8926,7 @@ expandmeta(struct strlist *str /*, int flag*/)
8926 goto nometa; 8926 goto nometa;
8927 savelastp = exparg.lastp; 8927 savelastp = exparg.lastp;
8928 8928
8929 INT_OFF; 8929 INTOFF;
8930 p = preglob(str->text, RMESCAPE_ALLOC | RMESCAPE_HEAP); 8930 p = preglob(str->text, RMESCAPE_ALLOC | RMESCAPE_HEAP);
8931 len = strlen(p); 8931 len = strlen(p);
8932 exp.dir_max = len + PATH_MAX; 8932 exp.dir_max = len + PATH_MAX;
@@ -8936,7 +8936,7 @@ expandmeta(struct strlist *str /*, int flag*/)
8936 free(exp.dir); 8936 free(exp.dir);
8937 if (p != str->text) 8937 if (p != str->text)
8938 free(p); 8938 free(p);
8939 INT_ON; 8939 INTON;
8940 if (exparg.lastp == savelastp) { 8940 if (exparg.lastp == savelastp) {
8941 /* 8941 /*
8942 * no matches 8942 * no matches
@@ -9369,7 +9369,7 @@ clearcmdentry(void)
9369 struct tblentry **pp; 9369 struct tblentry **pp;
9370 struct tblentry *cmdp; 9370 struct tblentry *cmdp;
9371 9371
9372 INT_OFF; 9372 INTOFF;
9373 for (tblp = cmdtable; tblp < &cmdtable[CMDTABLESIZE]; tblp++) { 9373 for (tblp = cmdtable; tblp < &cmdtable[CMDTABLESIZE]; tblp++) {
9374 pp = tblp; 9374 pp = tblp;
9375 while ((cmdp = *pp) != NULL) { 9375 while ((cmdp = *pp) != NULL) {
@@ -9386,7 +9386,7 @@ clearcmdentry(void)
9386 } 9386 }
9387 } 9387 }
9388 } 9388 }
9389 INT_ON; 9389 INTON;
9390} 9390}
9391 9391
9392/* 9392/*
@@ -9440,13 +9440,13 @@ delete_cmd_entry(void)
9440{ 9440{
9441 struct tblentry *cmdp; 9441 struct tblentry *cmdp;
9442 9442
9443 INT_OFF; 9443 INTOFF;
9444 cmdp = *lastcmdentry; 9444 cmdp = *lastcmdentry;
9445 *lastcmdentry = cmdp->next; 9445 *lastcmdentry = cmdp->next;
9446 if (cmdp->cmdtype == CMDFUNCTION) 9446 if (cmdp->cmdtype == CMDFUNCTION)
9447 freefunc(cmdp->param.func); 9447 freefunc(cmdp->param.func);
9448 free(cmdp); 9448 free(cmdp);
9449 INT_ON; 9449 INTON;
9450} 9450}
9451 9451
9452/* 9452/*
@@ -10314,11 +10314,11 @@ defun(union node *func)
10314{ 10314{
10315 struct cmdentry entry; 10315 struct cmdentry entry;
10316 10316
10317 INT_OFF; 10317 INTOFF;
10318 entry.cmdtype = CMDFUNCTION; 10318 entry.cmdtype = CMDFUNCTION;
10319 entry.u.func = copyfunc(func); 10319 entry.u.func = copyfunc(func);
10320 addcmdentry(func->ndefun.text, &entry); 10320 addcmdentry(func->ndefun.text, &entry);
10321 INT_ON; 10321 INTON;
10322} 10322}
10323 10323
10324/* Reasons for skipping commands (see comment on breakcmd routine) */ 10324/* Reasons for skipping commands (see comment on breakcmd routine) */
@@ -10739,7 +10739,7 @@ evalsubshell(union node *n, int flags)
10739 if (!backgnd && (flags & EV_EXIT) && !may_have_traps) 10739 if (!backgnd && (flags & EV_EXIT) && !may_have_traps)
10740 goto nofork; 10740 goto nofork;
10741#endif 10741#endif
10742 INT_OFF; 10742 INTOFF;
10743 if (backgnd == FORK_FG) 10743 if (backgnd == FORK_FG)
10744 get_tty_state(); 10744 get_tty_state();
10745 jp = makejob(1); 10745 jp = makejob(1);
@@ -10752,7 +10752,7 @@ evalsubshell(union node *n, int flags)
10752#else 10752#else
10753 if (forkshell(jp, n, backgnd) == 0) { 10753 if (forkshell(jp, n, backgnd) == 0) {
10754 /* child */ 10754 /* child */
10755 INT_ON; 10755 INTON;
10756 flags |= EV_EXIT; 10756 flags |= EV_EXIT;
10757 if (backgnd) 10757 if (backgnd)
10758 flags &= ~EV_TESTED; 10758 flags &= ~EV_TESTED;
@@ -10766,7 +10766,7 @@ evalsubshell(union node *n, int flags)
10766 status = 0; 10766 status = 0;
10767 if (backgnd == FORK_FG) 10767 if (backgnd == FORK_FG)
10768 status = waitforjob(jp); 10768 status = waitforjob(jp);
10769 INT_ON; 10769 INTON;
10770 return status; 10770 return status;
10771} 10771}
10772 10772
@@ -10855,7 +10855,7 @@ evalpipe(union node *n, int flags)
10855 for (lp = n->npipe.cmdlist; lp; lp = lp->next) 10855 for (lp = n->npipe.cmdlist; lp; lp = lp->next)
10856 pipelen++; 10856 pipelen++;
10857 flags |= EV_EXIT; 10857 flags |= EV_EXIT;
10858 INT_OFF; 10858 INTOFF;
10859 if (n->npipe.pipe_backgnd == 0) 10859 if (n->npipe.pipe_backgnd == 0)
10860 get_tty_state(); 10860 get_tty_state();
10861 jp = makejob(pipelen); 10861 jp = makejob(pipelen);
@@ -10881,7 +10881,7 @@ evalpipe(union node *n, int flags)
10881#else 10881#else
10882 if (forkshell(jp, lp->n, n->npipe.pipe_backgnd) == 0) { 10882 if (forkshell(jp, lp->n, n->npipe.pipe_backgnd) == 0) {
10883 /* child */ 10883 /* child */
10884 INT_ON; 10884 INTON;
10885 if (pip[1] >= 0) { 10885 if (pip[1] >= 0) {
10886 close(pip[0]); 10886 close(pip[0]);
10887 } 10887 }
@@ -10909,7 +10909,7 @@ evalpipe(union node *n, int flags)
10909 status = waitforjob(jp); 10909 status = waitforjob(jp);
10910 TRACE(("evalpipe: job done exit status %d\n", status)); 10910 TRACE(("evalpipe: job done exit status %d\n", status));
10911 } 10911 }
10912 INT_ON; 10912 INTON;
10913 10913
10914 return status; 10914 return status;
10915} 10915}
@@ -11013,7 +11013,7 @@ poplocalvars(int keep)
11013 int var_type; 11013 int var_type;
11014#endif 11014#endif
11015 11015
11016 INT_OFF; 11016 INTOFF;
11017 ll = localvar_stack; 11017 ll = localvar_stack;
11018 localvar_stack = ll->next; 11018 localvar_stack = ll->next;
11019 11019
@@ -11068,7 +11068,7 @@ poplocalvars(int keep)
11068 } 11068 }
11069 free(lvp); 11069 free(lvp);
11070 } 11070 }
11071 INT_ON; 11071 INTON;
11072} 11072}
11073 11073
11074/* 11074/*
@@ -11084,12 +11084,12 @@ pushlocalvars(int push)
11084 if (!push) 11084 if (!push)
11085 goto out; 11085 goto out;
11086 11086
11087 INT_OFF; 11087 INTOFF;
11088 ll = ckzalloc(sizeof(*ll)); 11088 ll = ckzalloc(sizeof(*ll));
11089 /*ll->lv = NULL; - zalloc did it */ 11089 /*ll->lv = NULL; - zalloc did it */
11090 ll->next = top; 11090 ll->next = top;
11091 localvar_stack = ll; 11091 localvar_stack = ll;
11092 INT_ON; 11092 INTON;
11093 out: 11093 out:
11094 return top; 11094 return top;
11095} 11095}
@@ -11126,13 +11126,13 @@ evalfun(struct funcnode *func, int argc, char **argv, int flags)
11126 if (e) { 11126 if (e) {
11127 goto funcdone; 11127 goto funcdone;
11128 } 11128 }
11129 INT_OFF; 11129 INTOFF;
11130 exception_handler = &jmploc; 11130 exception_handler = &jmploc;
11131 shellparam.malloced = 0; 11131 shellparam.malloced = 0;
11132 func->count++; 11132 func->count++;
11133 funcname = func->n.ndefun.text; 11133 funcname = func->n.ndefun.text;
11134 funcline = func->n.ndefun.linno; 11134 funcline = func->n.ndefun.linno;
11135 INT_ON; 11135 INTON;
11136 shellparam.nparam = argc - 1; 11136 shellparam.nparam = argc - 1;
11137 shellparam.p = argv + 1; 11137 shellparam.p = argv + 1;
11138#if ENABLE_ASH_GETOPTS 11138#if ENABLE_ASH_GETOPTS
@@ -11141,7 +11141,7 @@ evalfun(struct funcnode *func, int argc, char **argv, int flags)
11141#endif 11141#endif
11142 evaltree(func->n.ndefun.body, flags & EV_TESTED); 11142 evaltree(func->n.ndefun.body, flags & EV_TESTED);
11143 funcdone: 11143 funcdone:
11144 INT_OFF; 11144 INTOFF;
11145 funcname = savefuncname; 11145 funcname = savefuncname;
11146 if (savetrap) { 11146 if (savetrap) {
11147 if (!trap[NTRAP_ERR]) 11147 if (!trap[NTRAP_ERR])
@@ -11155,7 +11155,7 @@ evalfun(struct funcnode *func, int argc, char **argv, int flags)
11155 freeparam(&shellparam); 11155 freeparam(&shellparam);
11156 shellparam = saveparam; 11156 shellparam = saveparam;
11157 exception_handler = savehandler; 11157 exception_handler = savehandler;
11158 INT_ON; 11158 INTON;
11159 evalskip &= ~(SKIPFUNC | SKIPFUNCDEF); 11159 evalskip &= ~(SKIPFUNC | SKIPFUNCDEF);
11160 return e; 11160 return e;
11161} 11161}
@@ -11174,7 +11174,7 @@ mklocal(char *name, int flags)
11174 struct var *vp; 11174 struct var *vp;
11175 char *eq = strchr(name, '='); 11175 char *eq = strchr(name, '=');
11176 11176
11177 INT_OFF; 11177 INTOFF;
11178 /* Cater for duplicate "local". Examples: 11178 /* Cater for duplicate "local". Examples:
11179 * x=0; f() { local x=1; echo $x; local x; echo $x; }; f; echo $x 11179 * x=0; f() { local x=1; echo $x; local x; echo $x; }; f; echo $x
11180 * x=0; f() { local x=1; echo $x; local x=2; echo $x; }; f; echo $x 11180 * x=0; f() { local x=1; echo $x; local x=2; echo $x; }; f; echo $x
@@ -11225,7 +11225,7 @@ mklocal(char *name, int flags)
11225 lvp->next = localvar_stack->lv; 11225 lvp->next = localvar_stack->lv;
11226 localvar_stack->lv = lvp; 11226 localvar_stack->lv = lvp;
11227 ret: 11227 ret:
11228 INT_ON; 11228 INTON;
11229} 11229}
11230 11230
11231/* 11231/*
@@ -11783,7 +11783,7 @@ evalcommand(union node *cmd, int flags)
11783 char *sv_argv0; 11783 char *sv_argv0;
11784#endif 11784#endif
11785 11785
11786 INT_OFF; 11786 INTOFF;
11787 sv_environ = environ; 11787 sv_environ = environ;
11788 environ = listvars(VEXPORT, VUNSET, varlist.list, /*end:*/ NULL); 11788 environ = listvars(VEXPORT, VUNSET, varlist.list, /*end:*/ NULL);
11789 /* 11789 /*
@@ -11813,7 +11813,7 @@ evalcommand(union node *cmd, int flags)
11813 * our signals to SA_RESTART? 11813 * our signals to SA_RESTART?
11814 */ 11814 */
11815 /*clearerr(stdout);*/ 11815 /*clearerr(stdout);*/
11816 INT_ON; 11816 INTON;
11817 break; 11817 break;
11818 } 11818 }
11819#endif 11819#endif
@@ -11826,7 +11826,7 @@ evalcommand(union node *cmd, int flags)
11826 /* No, forking off a child is necessary */ 11826 /* No, forking off a child is necessary */
11827 struct forkshell fs; 11827 struct forkshell fs;
11828 11828
11829 INT_OFF; 11829 INTOFF;
11830 memset(&fs, 0, sizeof(fs)); 11830 memset(&fs, 0, sizeof(fs));
11831 fs.fpid = FS_SHELLEXEC; 11831 fs.fpid = FS_SHELLEXEC;
11832 fs.argv = argv; 11832 fs.argv = argv;
@@ -11839,7 +11839,7 @@ evalcommand(union node *cmd, int flags)
11839#else 11839#else
11840 if (!(flags & EV_EXIT) || may_have_traps) { 11840 if (!(flags & EV_EXIT) || may_have_traps) {
11841 /* No, forking off a child is necessary */ 11841 /* No, forking off a child is necessary */
11842 INT_OFF; 11842 INTOFF;
11843 get_tty_state(); 11843 get_tty_state();
11844 jp = makejob(1); 11844 jp = makejob(1);
11845 if (forkshell(jp, cmd, FORK_FG) != 0) { 11845 if (forkshell(jp, cmd, FORK_FG) != 0) {
@@ -11847,7 +11847,7 @@ evalcommand(union node *cmd, int flags)
11847 break; 11847 break;
11848 } 11848 }
11849 /* child */ 11849 /* child */
11850 FORCE_INT_ON; 11850 FORCEINTON;
11851 /* fall through to exec'ing external program */ 11851 /* fall through to exec'ing external program */
11852 } 11852 }
11853#endif 11853#endif
@@ -11872,7 +11872,7 @@ evalcommand(union node *cmd, int flags)
11872 status = waitforjob(jp); 11872 status = waitforjob(jp);
11873 if (jp) 11873 if (jp)
11874 TRACE(("forked child exited with %d\n", status)); 11874 TRACE(("forked child exited with %d\n", status));
11875 FORCE_INT_ON; 11875 FORCEINTON;
11876 11876
11877 out: 11877 out:
11878 if (cmd->ncmd.redirect) 11878 if (cmd->ncmd.redirect)
@@ -12009,7 +12009,7 @@ pushstring(char *s, struct alias *ap)
12009 int len; 12009 int len;
12010 12010
12011 len = strlen(s); 12011 len = strlen(s);
12012 INT_OFF; 12012 INTOFF;
12013 if (g_parsefile->strpush || g_parsefile->spfree) { 12013 if (g_parsefile->strpush || g_parsefile->spfree) {
12014 sp = ckzalloc(sizeof(*sp)); 12014 sp = ckzalloc(sizeof(*sp));
12015 sp->prev = g_parsefile->strpush; 12015 sp->prev = g_parsefile->strpush;
@@ -12033,14 +12033,14 @@ pushstring(char *s, struct alias *ap)
12033 g_parsefile->left_in_line = len; 12033 g_parsefile->left_in_line = len;
12034 g_parsefile->unget = 0; 12034 g_parsefile->unget = 0;
12035 g_parsefile->spfree = NULL; 12035 g_parsefile->spfree = NULL;
12036 INT_ON; 12036 INTON;
12037} 12037}
12038 12038
12039static void popstring(void) 12039static void popstring(void)
12040{ 12040{
12041 struct strpush *sp = g_parsefile->strpush; 12041 struct strpush *sp = g_parsefile->strpush;
12042 12042
12043 INT_OFF; 12043 INTOFF;
12044#if ENABLE_ASH_ALIAS 12044#if ENABLE_ASH_ALIAS
12045 if (sp->ap) { 12045 if (sp->ap) {
12046 if (g_parsefile->next_to_pgetc[-1] == ' ' 12046 if (g_parsefile->next_to_pgetc[-1] == ' '
@@ -12059,7 +12059,7 @@ static void popstring(void)
12059 memcpy(g_parsefile->lastc, sp->lastc, sizeof(sp->lastc)); 12059 memcpy(g_parsefile->lastc, sp->lastc, sizeof(sp->lastc));
12060 g_parsefile->strpush = sp->prev; 12060 g_parsefile->strpush = sp->prev;
12061 g_parsefile->spfree = sp; 12061 g_parsefile->spfree = sp;
12062 INT_ON; 12062 INTON;
12063} 12063}
12064 12064
12065#if ENABLE_PLATFORM_MINGW32 12065#if ENABLE_PLATFORM_MINGW32
@@ -12156,11 +12156,11 @@ preadfd(void)
12156 * #(bash 5.0.17 exits after first "T", looks like a bug) 12156 * #(bash 5.0.17 exits after first "T", looks like a bug)
12157 */ 12157 */
12158 bb_got_signal = 0; 12158 bb_got_signal = 0;
12159 INT_OFF; /* no longjmp'ing out of read_line_input please */ 12159 INTOFF; /* no longjmp'ing out of read_line_input please */
12160 nr = read_line_input(line_input_state, cmdedit_prompt, buf, IBUFSIZ); 12160 nr = read_line_input(line_input_state, cmdedit_prompt, buf, IBUFSIZ);
12161 if (bb_got_signal == SIGINT) 12161 if (bb_got_signal == SIGINT)
12162 write(STDOUT_FILENO, "^C\n", 3); 12162 write(STDOUT_FILENO, "^C\n", 3);
12163 INT_ON; /* here non-blocked SIGINT will longjmp */ 12163 INTON; /* here non-blocked SIGINT will longjmp */
12164 if (nr == 0) { 12164 if (nr == 0) {
12165 /* ^C pressed, "convert" to SIGINT */ 12165 /* ^C pressed, "convert" to SIGINT */
12166# if !ENABLE_PLATFORM_MINGW32 12166# if !ENABLE_PLATFORM_MINGW32
@@ -12326,7 +12326,7 @@ nlnoprompt(void)
12326 12326
12327static void freestrings(struct strpush *sp) 12327static void freestrings(struct strpush *sp)
12328{ 12328{
12329 INT_OFF; 12329 INTOFF;
12330 do { 12330 do {
12331 struct strpush *psp; 12331 struct strpush *psp;
12332#if ENABLE_ASH_ALIAS 12332#if ENABLE_ASH_ALIAS
@@ -12345,7 +12345,7 @@ static void freestrings(struct strpush *sp)
12345 } while (sp); 12345 } while (sp);
12346 12346
12347 g_parsefile->spfree = NULL; 12347 g_parsefile->spfree = NULL;
12348 INT_ON; 12348 INTON;
12349} 12349}
12350 12350
12351static int __pgetc(void) 12351static int __pgetc(void)
@@ -12478,7 +12478,7 @@ popfile(void)
12478 if (pf == &basepf) 12478 if (pf == &basepf)
12479 return; 12479 return;
12480 12480
12481 INT_OFF; 12481 INTOFF;
12482 if (pf->pf_fd >= 0) 12482 if (pf->pf_fd >= 0)
12483 close(pf->pf_fd); 12483 close(pf->pf_fd);
12484 free(pf->buf); 12484 free(pf->buf);
@@ -12490,7 +12490,7 @@ popfile(void)
12490 } 12490 }
12491 g_parsefile = pf->prev; 12491 g_parsefile = pf->prev;
12492 free(pf); 12492 free(pf);
12493 INT_ON; 12493 INTON;
12494} 12494}
12495 12495
12496static void 12496static void
@@ -12553,7 +12553,7 @@ setinputfile(const char *fname, int flags)
12553{ 12553{
12554 int fd; 12554 int fd;
12555 12555
12556 INT_OFF; 12556 INTOFF;
12557 fd = open(fname, O_RDONLY | O_CLOEXEC); 12557 fd = open(fname, O_RDONLY | O_CLOEXEC);
12558 if (fd < 0) { 12558 if (fd < 0) {
12559 if (flags & INPUT_NOFILE_OK) 12559 if (flags & INPUT_NOFILE_OK)
@@ -12568,7 +12568,7 @@ setinputfile(const char *fname, int flags)
12568 12568
12569 setinputfd(fd, flags & INPUT_PUSH_FILE); 12569 setinputfd(fd, flags & INPUT_PUSH_FILE);
12570 out: 12570 out:
12571 INT_ON; 12571 INTON;
12572 return fd; 12572 return fd;
12573} 12573}
12574 12574
@@ -12578,13 +12578,13 @@ setinputfile(const char *fname, int flags)
12578static void 12578static void
12579setinputstring(char *string) 12579setinputstring(char *string)
12580{ 12580{
12581 INT_OFF; 12581 INTOFF;
12582 pushfile(); 12582 pushfile();
12583 g_parsefile->next_to_pgetc = string; 12583 g_parsefile->next_to_pgetc = string;
12584 g_parsefile->left_in_line = strlen(string); 12584 g_parsefile->left_in_line = strlen(string);
12585 g_parsefile->buf = NULL; 12585 g_parsefile->buf = NULL;
12586 g_parsefile->linno = lineno; 12586 g_parsefile->linno = lineno;
12587 INT_ON; 12587 INTON;
12588} 12588}
12589 12589
12590 12590
@@ -12880,7 +12880,7 @@ shiftcmd(int argc UNUSED_PARAM, char **argv)
12880 n = number(argv[1]); 12880 n = number(argv[1]);
12881 if (n > shellparam.nparam) 12881 if (n > shellparam.nparam)
12882 return 1; 12882 return 1;
12883 INT_OFF; 12883 INTOFF;
12884 shellparam.nparam -= n; 12884 shellparam.nparam -= n;
12885 for (ap1 = shellparam.p; --n >= 0; ap1++) { 12885 for (ap1 = shellparam.p; --n >= 0; ap1++) {
12886 if (shellparam.malloced) 12886 if (shellparam.malloced)
@@ -12893,7 +12893,7 @@ shiftcmd(int argc UNUSED_PARAM, char **argv)
12893 shellparam.optind = 1; 12893 shellparam.optind = 1;
12894 shellparam.optoff = -1; 12894 shellparam.optoff = -1;
12895#endif 12895#endif
12896 INT_ON; 12896 INTON;
12897 return 0; 12897 return 0;
12898} 12898}
12899 12899
@@ -12947,7 +12947,7 @@ setcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
12947 if (!argv[1]) 12947 if (!argv[1])
12948 return showvars(nullstr, 0, VUNSET); 12948 return showvars(nullstr, 0, VUNSET);
12949 12949
12950 INT_OFF; 12950 INTOFF;
12951 retval = options(/*login_sh:*/ NULL); 12951 retval = options(/*login_sh:*/ NULL);
12952 if (retval == 0) { /* if no parse error... */ 12952 if (retval == 0) { /* if no parse error... */
12953 optschanged(); 12953 optschanged();
@@ -12955,7 +12955,7 @@ setcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
12955 setparam(argptr); 12955 setparam(argptr);
12956 } 12956 }
12957 } 12957 }
12958 INT_ON; 12958 INTON;
12959 return retval; 12959 return retval;
12960} 12960}
12961 12961
@@ -14957,7 +14957,7 @@ cmdloop(int top)
14957 14957
14958 setstackmark(&smark); 14958 setstackmark(&smark);
14959#if JOBS || JOBS_WIN32 14959#if JOBS || JOBS_WIN32
14960 if (doing_jobctl) 14960 if (jobctl)
14961 showjobs(SHOW_CHANGED|SHOW_STDERR); 14961 showjobs(SHOW_CHANGED|SHOW_STDERR);
14962#endif 14962#endif
14963 inter = 0; 14963 inter = 0;
@@ -15369,11 +15369,11 @@ find_command(char *name, struct cmdentry *entry, int act, const char *path)
15369 entry->u.index = idx; 15369 entry->u.index = idx;
15370 return; 15370 return;
15371 } 15371 }
15372 INT_OFF; 15372 INTOFF;
15373 cmdp = cmdlookup(name, 1); 15373 cmdp = cmdlookup(name, 1);
15374 cmdp->cmdtype = CMDNORMAL; 15374 cmdp->cmdtype = CMDNORMAL;
15375 cmdp->param.index = idx; 15375 cmdp->param.index = idx;
15376 INT_ON; 15376 INTON;
15377 goto success; 15377 goto success;
15378 } 15378 }
15379 15379
@@ -15405,11 +15405,11 @@ find_command(char *name, struct cmdentry *entry, int act, const char *path)
15405 entry->u.cmd = bcmd; 15405 entry->u.cmd = bcmd;
15406 return; 15406 return;
15407 } 15407 }
15408 INT_OFF; 15408 INTOFF;
15409 cmdp = cmdlookup(name, 1); 15409 cmdp = cmdlookup(name, 1);
15410 cmdp->cmdtype = CMDBUILTIN; 15410 cmdp->cmdtype = CMDBUILTIN;
15411 cmdp->param.cmd = bcmd; 15411 cmdp->param.cmd = bcmd;
15412 INT_ON; 15412 INTON;
15413 success: 15413 success:
15414 cmdp->rehash = 0; 15414 cmdp->rehash = 0;
15415 entry->cmdtype = cmdp->cmdtype; 15415 entry->cmdtype = cmdp->cmdtype;
@@ -15471,7 +15471,7 @@ trapcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
15471 exitcode = 1; 15471 exitcode = 1;
15472 goto next; 15472 goto next;
15473 } 15473 }
15474 INT_OFF; 15474 INTOFF;
15475 if (action) { 15475 if (action) {
15476 if (LONE_DASH(action)) 15476 if (LONE_DASH(action))
15477 action = NULL; 15477 action = NULL;
@@ -15508,7 +15508,7 @@ trapcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
15508 if (signo != 0 && signo < NSIG) 15508 if (signo != 0 && signo < NSIG)
15509 setsignal(signo); 15509 setsignal(signo);
15510#endif 15510#endif
15511 INT_ON; 15511 INTON;
15512 next: 15512 next:
15513 ap++; 15513 ap++;
15514 } 15514 }
@@ -15821,9 +15821,9 @@ readcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
15821 * to jump out of it. 15821 * to jump out of it.
15822 */ 15822 */
15823 again: 15823 again:
15824 INT_OFF; 15824 INTOFF;
15825 r = shell_builtin_read(&params); 15825 r = shell_builtin_read(&params);
15826 INT_ON; 15826 INTON;
15827 15827
15828#if !ENABLE_PLATFORM_MINGW32 15828#if !ENABLE_PLATFORM_MINGW32
15829 if ((uintptr_t)r == 1 && errno == EINTR) { 15829 if ((uintptr_t)r == 1 && errno == EINTR) {
@@ -15880,10 +15880,10 @@ umaskcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
15880 symbolic_mode = 1; 15880 symbolic_mode = 1;
15881 } 15881 }
15882 15882
15883 INT_OFF; 15883 INTOFF;
15884 mask = umask(0); 15884 mask = umask(0);
15885 umask(mask); 15885 umask(mask);
15886 INT_ON; 15886 INTON;
15887 15887
15888 if (*argptr == NULL) { 15888 if (*argptr == NULL) {
15889 if (symbolic_mode) { 15889 if (symbolic_mode) {
@@ -16372,7 +16372,7 @@ int ash_main(int argc UNUSED_PARAM, char **argv)
16372 } 16372 }
16373 16373
16374 popstackmark(&smark); 16374 popstackmark(&smark);
16375 FORCE_INT_ON; /* enable interrupts */ 16375 FORCEINTON; /* enable interrupts */
16376 if (s == 1) 16376 if (s == 1)
16377 goto state1; 16377 goto state1;
16378 if (s == 2) 16378 if (s == 2)
@@ -16499,11 +16499,11 @@ int ash_main(int argc UNUSED_PARAM, char **argv)
16499 if (!hp) { 16499 if (!hp) {
16500 hp = lookupvar("HOME"); 16500 hp = lookupvar("HOME");
16501 if (hp) { 16501 if (hp) {
16502 INT_OFF; 16502 INTOFF;
16503 hp = concat_path_file(hp, ".ash_history"); 16503 hp = concat_path_file(hp, ".ash_history");
16504 setvar0("HISTFILE", hp); 16504 setvar0("HISTFILE", hp);
16505 free((char*)hp); 16505 free((char*)hp);
16506 INT_ON; 16506 INTON;
16507 hp = lookupvar("HISTFILE"); 16507 hp = lookupvar("HISTFILE");
16508 } 16508 }
16509 } 16509 }
@@ -16578,7 +16578,7 @@ forkshell_evalbackcmd(struct forkshell *fs)
16578 pip[ip] = fs->fd[ip]; 16578 pip[ip] = fs->fd[ip];
16579 pip[ic] = fs->fd[ic]; 16579 pip[ic] = fs->fd[ic];
16580 16580
16581 FORCE_INT_ON; 16581 FORCEINTON;
16582 close(pip[ip]); 16582 close(pip[ip]);
16583 if (pip[ic] != ic) { 16583 if (pip[ic] != ic) {
16584 /*close(ic);*/ 16584 /*close(ic);*/
@@ -16598,7 +16598,7 @@ forkshell_evalsubshell(struct forkshell *fs)
16598 int flags = fs->flags; 16598 int flags = fs->flags;
16599 16599
16600 TRACE(("ash: subshell: %s\n",__PRETTY_FUNCTION__)); 16600 TRACE(("ash: subshell: %s\n",__PRETTY_FUNCTION__));
16601 INT_ON; 16601 INTON;
16602 flags |= EV_EXIT; 16602 flags |= EV_EXIT;
16603 if (fs->mode) 16603 if (fs->mode)
16604 flags &= ~EV_TESTED; 16604 flags &= ~EV_TESTED;
@@ -16617,7 +16617,7 @@ forkshell_evalpipe(struct forkshell *fs)
16617 int pip[2] = {fs->fd[0], fs->fd[1]}; 16617 int pip[2] = {fs->fd[0], fs->fd[1]};
16618 16618
16619 TRACE(("ash: subshell: %s\n",__PRETTY_FUNCTION__)); 16619 TRACE(("ash: subshell: %s\n",__PRETTY_FUNCTION__));
16620 INT_ON; 16620 INTON;
16621 if (pip[1] >= 0) { 16621 if (pip[1] >= 0) {
16622 close(pip[0]); 16622 close(pip[0]);
16623 } 16623 }
@@ -16639,7 +16639,7 @@ forkshell_shellexec(struct forkshell *fs)
16639 char **argv = fs->argv; 16639 char **argv = fs->argv;
16640 char *path = fs->path; 16640 char *path = fs->path;
16641 16641
16642 FORCE_INT_ON; 16642 FORCEINTON;
16643 shellexec(argv[0], argv, path, idx, TRUE); 16643 shellexec(argv[0], argv, path, idx, TRUE);
16644} 16644}
16645 16645
@@ -17607,7 +17607,7 @@ forkshell_init(const char *idstr)
17607 clear_traps(); 17607 clear_traps();
17608#if JOBS_WIN32 17608#if JOBS_WIN32
17609 /* do job control only in root shell */ 17609 /* do job control only in root shell */
17610 doing_jobctl = 0; 17610 jobctl = 0;
17611 17611
17612 if (fs->n && fs->n->type == NCMD && fs->n->ncmd.args && 17612 if (fs->n && fs->n->type == NCMD && fs->n->ncmd.args &&
17613 strcmp(fs->n->ncmd.args->narg.text, "jobs") == 0) { 17613 strcmp(fs->n->ncmd.args->narg.text, "jobs") == 0) {