aboutsummaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2021-09-17 11:36:53 +0100
committerRon Yorston <rmy@pobox.com>2021-09-17 11:38:52 +0100
commit46299d0c4f4c9a4bbad38bbbe26f196e1bccdc52 (patch)
tree6194cdabc0858ae3bed0276679b3b80a722f4150 /shell
parentcf91de46997888b7096352805c05401e7ebae01e (diff)
parent9fe1548bbfde548d54acaab113656a56ea0ccc72 (diff)
downloadbusybox-w32-46299d0c4f4c9a4bbad38bbbe26f196e1bccdc52.tar.gz
busybox-w32-46299d0c4f4c9a4bbad38bbbe26f196e1bccdc52.tar.bz2
busybox-w32-46299d0c4f4c9a4bbad38bbbe26f196e1bccdc52.zip
Merge branch 'busybox' into merge
Disable FEATURE_TIMEZONE for now.
Diffstat (limited to 'shell')
-rw-r--r--shell/ash.c58
1 files changed, 32 insertions, 26 deletions
diff --git a/shell/ash.c b/shell/ash.c
index 7544204d1..5adb95bc5 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -2355,6 +2355,7 @@ static const struct {
2355 { VSTRFIXED|VTEXTFIXED , defoptindvar, getoptsreset }, 2355 { VSTRFIXED|VTEXTFIXED , defoptindvar, getoptsreset },
2356#endif 2356#endif
2357 { VSTRFIXED|VTEXTFIXED , NULL /* inited to linenovar */, NULL }, 2357 { VSTRFIXED|VTEXTFIXED , NULL /* inited to linenovar */, NULL },
2358 { VSTRFIXED|VTEXTFIXED , NULL /* inited to funcnamevar */, NULL },
2358#if ENABLE_ASH_RANDOM_SUPPORT 2359#if ENABLE_ASH_RANDOM_SUPPORT
2359 { VSTRFIXED|VTEXTFIXED|VUNSET|VDYNAMIC, "RANDOM", change_random }, 2360 { VSTRFIXED|VTEXTFIXED|VUNSET|VDYNAMIC, "RANDOM", change_random },
2360#endif 2361#endif
@@ -2384,6 +2385,8 @@ struct globals_var {
2384 struct var varinit[ARRAY_SIZE(varinit_data)]; 2385 struct var varinit[ARRAY_SIZE(varinit_data)];
2385 int lineno; 2386 int lineno;
2386 char linenovar[sizeof("LINENO=") + sizeof(int)*3]; 2387 char linenovar[sizeof("LINENO=") + sizeof(int)*3];
2388 char funcnamevar[sizeof("FUNCNAME=") + 64];
2389 char *funcname;
2387 unsigned trap_depth; 2390 unsigned trap_depth;
2388 bool in_trap_ERR; /* ERR cannot recurse, no need to be a counter */ 2391 bool in_trap_ERR; /* ERR cannot recurse, no need to be a counter */
2389}; 2392};
@@ -2396,6 +2399,8 @@ extern struct globals_var *BB_GLOBAL_CONST ash_ptr_to_globals_var;
2396#define varinit (G_var.varinit ) 2399#define varinit (G_var.varinit )
2397#define lineno (G_var.lineno ) 2400#define lineno (G_var.lineno )
2398#define linenovar (G_var.linenovar ) 2401#define linenovar (G_var.linenovar )
2402#define funcnamevar (G_var.funcnamevar )
2403#define funcname (G_var.funcname )
2399#define trap_depth (G_var.trap_depth ) 2404#define trap_depth (G_var.trap_depth )
2400#define in_trap_ERR (G_var.in_trap_ERR ) 2405#define in_trap_ERR (G_var.in_trap_ERR )
2401#define vifs varinit[0] 2406#define vifs varinit[0]
@@ -2413,13 +2418,14 @@ extern struct globals_var *BB_GLOBAL_CONST ash_ptr_to_globals_var;
2413#endif 2418#endif
2414#define VAR_OFFSET2 (VAR_OFFSET1 + ENABLE_ASH_GETOPTS) 2419#define VAR_OFFSET2 (VAR_OFFSET1 + ENABLE_ASH_GETOPTS)
2415#define vlineno varinit[VAR_OFFSET2 + 5] 2420#define vlineno varinit[VAR_OFFSET2 + 5]
2421#define vfuncname varinit[VAR_OFFSET2 + 6]
2416#if ENABLE_ASH_RANDOM_SUPPORT 2422#if ENABLE_ASH_RANDOM_SUPPORT
2417# define vrandom varinit[VAR_OFFSET2 + 6] 2423# define vrandom varinit[VAR_OFFSET2 + 7]
2418#endif 2424#endif
2419#define VAR_OFFSET3 (VAR_OFFSET2 + ENABLE_ASH_RANDOM_SUPPORT) 2425#define VAR_OFFSET3 (VAR_OFFSET2 + ENABLE_ASH_RANDOM_SUPPORT)
2420#if BASH_EPOCH_VARS 2426#if BASH_EPOCH_VARS
2421# define vepochs varinit[VAR_OFFSET3 + 6] 2427# define vepochs varinit[VAR_OFFSET3 + 7]
2422# define vepochr varinit[VAR_OFFSET3 + 7] 2428# define vepochr varinit[VAR_OFFSET3 + 8]
2423#endif 2429#endif
2424#define INIT_G_var() do { \ 2430#define INIT_G_var() do { \
2425 unsigned i; \ 2431 unsigned i; \
@@ -2432,6 +2438,8 @@ extern struct globals_var *BB_GLOBAL_CONST ash_ptr_to_globals_var;
2432 } \ 2438 } \
2433 strcpy(linenovar, "LINENO="); \ 2439 strcpy(linenovar, "LINENO="); \
2434 vlineno.var_text = linenovar; \ 2440 vlineno.var_text = linenovar; \
2441 strcpy(funcnamevar, "FUNCNAME="); \
2442 vfuncname.var_text = funcnamevar; \
2435} while (0) 2443} while (0)
2436 2444
2437/* 2445/*
@@ -2571,6 +2579,9 @@ lookupvar(const char *name)
2571 if (!(v->flags & VUNSET)) { 2579 if (!(v->flags & VUNSET)) {
2572 if (v->var_text == linenovar) { 2580 if (v->var_text == linenovar) {
2573 fmtstr(linenovar+7, sizeof(linenovar)-7, "%d", lineno); 2581 fmtstr(linenovar+7, sizeof(linenovar)-7, "%d", lineno);
2582 } else
2583 if (v->var_text == funcnamevar) {
2584 safe_strncpy(funcnamevar+9, funcname ? funcname : "", sizeof(funcnamevar)-9);
2574 } 2585 }
2575 return var_end(v->var_text); 2586 return var_end(v->var_text);
2576 } 2587 }
@@ -6015,7 +6026,7 @@ stoppedjobs(void)
6015 int retval; 6026 int retval;
6016 6027
6017 retval = 0; 6028 retval = 0;
6018 if (job_warning) 6029 if (!iflag || job_warning)
6019 goto out; 6030 goto out;
6020 jp = curjob; 6031 jp = curjob;
6021 if (jp && jp->state == JOBSTOPPED) { 6032 if (jp && jp->state == JOBSTOPPED) {
@@ -10654,6 +10665,7 @@ evalfun(struct funcnode *func, int argc, char **argv, int flags)
10654 int e; 10665 int e;
10655 int savelineno; 10666 int savelineno;
10656 int savefuncline; 10667 int savefuncline;
10668 char *savefuncname;
10657 char *savetrap = NULL; 10669 char *savetrap = NULL;
10658 10670
10659 if (!Eflag) { 10671 if (!Eflag) {
@@ -10663,6 +10675,7 @@ evalfun(struct funcnode *func, int argc, char **argv, int flags)
10663 savelineno = lineno; 10675 savelineno = lineno;
10664 saveparam = shellparam; 10676 saveparam = shellparam;
10665 savefuncline = funcline; 10677 savefuncline = funcline;
10678 savefuncname = funcname;
10666 savehandler = exception_handler; 10679 savehandler = exception_handler;
10667 e = setjmp(jmploc.loc); 10680 e = setjmp(jmploc.loc);
10668 if (e) { 10681 if (e) {
@@ -10672,6 +10685,7 @@ evalfun(struct funcnode *func, int argc, char **argv, int flags)
10672 exception_handler = &jmploc; 10685 exception_handler = &jmploc;
10673 shellparam.malloced = 0; 10686 shellparam.malloced = 0;
10674 func->count++; 10687 func->count++;
10688 funcname = func->n.ndefun.text;
10675 funcline = func->n.ndefun.linno; 10689 funcline = func->n.ndefun.linno;
10676 INT_ON; 10690 INT_ON;
10677 shellparam.nparam = argc - 1; 10691 shellparam.nparam = argc - 1;
@@ -10683,6 +10697,7 @@ evalfun(struct funcnode *func, int argc, char **argv, int flags)
10683 evaltree(func->n.ndefun.body, flags & EV_TESTED); 10697 evaltree(func->n.ndefun.body, flags & EV_TESTED);
10684 funcdone: 10698 funcdone:
10685 INT_OFF; 10699 INT_OFF;
10700 funcname = savefuncname;
10686 if (savetrap) { 10701 if (savetrap) {
10687 if (!trap[NTRAP_ERR]) 10702 if (!trap[NTRAP_ERR])
10688 trap[NTRAP_ERR] = savetrap; 10703 trap[NTRAP_ERR] = savetrap;
@@ -11650,9 +11665,7 @@ preadfd(void)
11650 * Refill the input buffer and return the next input character: 11665 * Refill the input buffer and return the next input character:
11651 * 11666 *
11652 * 1) If a string was pushed back on the input, pop it; 11667 * 1) If a string was pushed back on the input, pop it;
11653 * 2) If an EOF was pushed back (g_parsefile->left_in_line < -BIGNUM) 11668 * 2) If we are reading from a string we can't refill the buffer, return EOF.
11654 * or we are reading from a string so we can't refill the buffer,
11655 * return EOF.
11656 * 3) If there is more stuff in this buffer, use it else call read to fill it. 11669 * 3) If there is more stuff in this buffer, use it else call read to fill it.
11657 * 4) Process input up to the next newline, deleting nul characters. 11670 * 4) Process input up to the next newline, deleting nul characters.
11658 */ 11671 */
@@ -11669,21 +11682,9 @@ preadbuffer(void)
11669 popstring(); 11682 popstring();
11670 return __pgetc(); 11683 return __pgetc();
11671 } 11684 }
11672 /* on both branches above g_parsefile->left_in_line < 0.
11673 * "pgetc" needs refilling.
11674 */
11675 11685
11676 /* -90 is our -BIGNUM. Below we use -99 to mark "EOF on read", 11686 if (g_parsefile->buf == NULL) {
11677 * pungetc() may increment it a few times.
11678 * Assuming it won't increment it to less than -90.
11679 */
11680 if (g_parsefile->left_in_line < -90 || g_parsefile->buf == NULL) {
11681 pgetc_debug("preadbuffer PEOF1"); 11687 pgetc_debug("preadbuffer PEOF1");
11682 /* even in failure keep left_in_line and next_to_pgetc
11683 * in lock step, for correct multi-layer pungetc.
11684 * left_in_line was decremented before preadbuffer(),
11685 * must inc next_to_pgetc: */
11686 g_parsefile->next_to_pgetc++;
11687 return PEOF; 11688 return PEOF;
11688 } 11689 }
11689 11690
@@ -11693,10 +11694,8 @@ preadbuffer(void)
11693 again: 11694 again:
11694 more = preadfd(); 11695 more = preadfd();
11695 if (more <= 0) { 11696 if (more <= 0) {
11696 /* don't try reading again */ 11697 g_parsefile->left_in_buffer = g_parsefile->left_in_line = 0;
11697 g_parsefile->left_in_line = -99;
11698 pgetc_debug("preadbuffer PEOF2"); 11698 pgetc_debug("preadbuffer PEOF2");
11699 g_parsefile->next_to_pgetc++;
11700 return PEOF; 11699 return PEOF;
11701 } 11700 }
11702 } 11701 }
@@ -14376,12 +14375,13 @@ cmdloop(int top)
14376 if (!top || numeof >= 50) 14375 if (!top || numeof >= 50)
14377 break; 14376 break;
14378 if (!stoppedjobs()) { 14377 if (!stoppedjobs()) {
14378 if (!iflag)
14379 break;
14379 if (!Iflag) { 14380 if (!Iflag) {
14380 if (iflag) { 14381 newline_and_flush(stderr);
14381 newline_and_flush(stderr);
14382 }
14383 break; 14382 break;
14384 } 14383 }
14384 /* "set -o ignoreeof" active, do not exit command loop on ^D */
14385 out2str("\nUse \"exit\" to leave shell.\n"); 14385 out2str("\nUse \"exit\" to leave shell.\n");
14386 } 14386 }
14387 numeof++; 14387 numeof++;
@@ -14508,6 +14508,12 @@ exitcmd(int argc UNUSED_PARAM, char **argv)
14508 if (argv[1]) 14508 if (argv[1])
14509 savestatus = number(argv[1]); 14509 savestatus = number(argv[1]);
14510 14510
14511//TODO: this script
14512// trap 'echo trap:$FUNCNAME' EXIT
14513// f() { exit; }
14514// f
14515//prints "trap:f" in bash. We can call exitshell() here to achieve this.
14516//For now, keeping dash code:
14511 raise_exception(EXEXIT); 14517 raise_exception(EXEXIT);
14512 /* NOTREACHED */ 14518 /* NOTREACHED */
14513} 14519}