aboutsummaryrefslogtreecommitdiff
path: root/shell/ash.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--shell/ash.c54
1 files changed, 36 insertions, 18 deletions
diff --git a/shell/ash.c b/shell/ash.c
index 3919118f0..605215e41 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -461,7 +461,7 @@ static void forkshell_print(FILE *fp0, struct forkshell *fs, const char **notes)
461 461
462/* ============ Shell options */ 462/* ============ Shell options */
463 463
464/* If you add/change options hare, update --help text too */ 464/* If you add/change options here, update --help text too */
465static const char *const optletters_optnames[] ALIGN_PTR = { 465static const char *const optletters_optnames[] ALIGN_PTR = {
466 "e" "errexit", 466 "e" "errexit",
467 "f" "noglob", 467 "f" "noglob",
@@ -929,6 +929,7 @@ raise_interrupt(void)
929 raise(SIGINT); 929 raise(SIGINT);
930#else 930#else
931 fflush_all(); 931 fflush_all();
932 kill(-getpid(), SIGINT);
932 _exit(SIGINT << 24); 933 _exit(SIGINT << 24);
933#endif 934#endif
934 } 935 }
@@ -1821,7 +1822,6 @@ struct stackmark {
1821 size_t stacknleft; 1822 size_t stacknleft;
1822}; 1823};
1823 1824
1824
1825struct globals_memstack { 1825struct globals_memstack {
1826 struct stack_block *g_stackp; // = &stackbase; 1826 struct stack_block *g_stackp; // = &stackbase;
1827 char *g_stacknxt; // = stackbase.space; 1827 char *g_stacknxt; // = stackbase.space;
@@ -1844,7 +1844,6 @@ extern struct globals_memstack *BB_GLOBAL_CONST ash_ptr_to_globals_memstack;
1844 sstrend = stackbase.space + MINSIZE; \ 1844 sstrend = stackbase.space + MINSIZE; \
1845} while (0) 1845} while (0)
1846 1846
1847
1848#define stackblock() ((void *)g_stacknxt) 1847#define stackblock() ((void *)g_stacknxt)
1849#define stackblocksize() g_stacknleft 1848#define stackblocksize() g_stacknleft
1850 1849
@@ -2361,7 +2360,6 @@ struct localvar {
2361# define VIMPORT 0x400 /* variable was imported from environment */ 2360# define VIMPORT 0x400 /* variable was imported from environment */
2362#endif 2361#endif
2363 2362
2364
2365/* Need to be before varinit_data[] */ 2363/* Need to be before varinit_data[] */
2366#if ENABLE_LOCALE_SUPPORT 2364#if ENABLE_LOCALE_SUPPORT
2367static void FAST_FUNC 2365static void FAST_FUNC
@@ -3581,7 +3579,6 @@ pwdcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
3581 3579
3582/* ============ ... */ 3580/* ============ ... */
3583 3581
3584
3585#define IBUFSIZ (ENABLE_FEATURE_EDITING ? CONFIG_FEATURE_EDITING_MAX_LEN : 1024) 3582#define IBUFSIZ (ENABLE_FEATURE_EDITING ? CONFIG_FEATURE_EDITING_MAX_LEN : 1024)
3586 3583
3587/* Syntax classes */ 3584/* Syntax classes */
@@ -3988,13 +3985,11 @@ struct alias {
3988 int flag; 3985 int flag;
3989}; 3986};
3990 3987
3991
3992static struct alias **atab; // [ATABSIZE]; 3988static struct alias **atab; // [ATABSIZE];
3993#define INIT_G_alias() do { \ 3989#define INIT_G_alias() do { \
3994 atab = xzalloc(ATABSIZE * sizeof(atab[0])); \ 3990 atab = xzalloc(ATABSIZE * sizeof(atab[0])); \
3995} while (0) 3991} while (0)
3996 3992
3997
3998static struct alias ** 3993static struct alias **
3999__lookupalias(const char *name) 3994__lookupalias(const char *name)
4000{ 3995{
@@ -4176,7 +4171,6 @@ unaliascmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
4176 4171
4177#endif /* ASH_ALIAS */ 4172#endif /* ASH_ALIAS */
4178 4173
4179
4180/* Mode argument to forkshell. Don't change FORK_FG or FORK_BG. */ 4174/* Mode argument to forkshell. Don't change FORK_FG or FORK_BG. */
4181#define FORK_FG 0 4175#define FORK_FG 0
4182#define FORK_BG 1 4176#define FORK_BG 1
@@ -4274,7 +4268,7 @@ signal_handler(int signo)
4274 return; 4268 return;
4275 } 4269 }
4276#if ENABLE_FEATURE_EDITING 4270#if ENABLE_FEATURE_EDITING
4277 bb_got_signal = signo; /* for read_line_input: "we got a signal" */ 4271 bb_got_signal = signo; /* for read_line_input / read builtin: "we got a signal" */
4278#endif 4272#endif
4279 gotsig[signo - 1] = 1; 4273 gotsig[signo - 1] = 1;
4280 pending_sig = signo; 4274 pending_sig = signo;
@@ -6193,7 +6187,6 @@ stoppedjobs(void)
6193} 6187}
6194#endif 6188#endif
6195 6189
6196
6197/* 6190/*
6198 * Code for dealing with input/output redirection. 6191 * Code for dealing with input/output redirection.
6199 */ 6192 */
@@ -9903,7 +9896,6 @@ commandcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
9903} 9896}
9904#endif 9897#endif
9905 9898
9906
9907/*static int funcblocksize; // size of structures in function */ 9899/*static int funcblocksize; // size of structures in function */
9908/*static int funcstringsize; // size of strings in node */ 9900/*static int funcstringsize; // size of strings in node */
9909static void *funcblock; /* block to allocate function from */ 9901static void *funcblock; /* block to allocate function from */
@@ -11919,7 +11911,6 @@ goodname(const char *p)
11919 return endofname(p)[0] == '\0'; 11911 return endofname(p)[0] == '\0';
11920} 11912}
11921 11913
11922
11923/* 11914/*
11924 * Search for a command. This is called before we fork so that the 11915 * Search for a command. This is called before we fork so that the
11925 * location of the command will be available in the parent as well as 11916 * location of the command will be available in the parent as well as
@@ -14772,7 +14763,6 @@ parseheredoc(void)
14772 } 14763 }
14773} 14764}
14774 14765
14775
14776static const char * 14766static const char *
14777expandstr(const char *ps, int syntax_type) 14767expandstr(const char *ps, int syntax_type)
14778{ 14768{
@@ -15402,7 +15392,6 @@ find_command(char *name, struct cmdentry *entry, int act, const char *path)
15402 entry->u = cmdp->param; 15392 entry->u = cmdp->param;
15403} 15393}
15404 15394
15405
15406/* 15395/*
15407 * The trap builtin. 15396 * The trap builtin.
15408 */ 15397 */
@@ -15812,6 +15801,7 @@ readcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
15812 r = shell_builtin_read(&params); 15801 r = shell_builtin_read(&params);
15813 INT_ON; 15802 INT_ON;
15814 15803
15804#if !ENABLE_PLATFORM_MINGW32
15815 if ((uintptr_t)r == 1 && errno == EINTR) { 15805 if ((uintptr_t)r == 1 && errno == EINTR) {
15816 /* To get SIGCHLD: sleep 1 & read x; echo $x 15806 /* To get SIGCHLD: sleep 1 & read x; echo $x
15817 * Correct behavior is to not exit "read" 15807 * Correct behavior is to not exit "read"
@@ -15820,8 +15810,15 @@ readcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
15820 goto again; 15810 goto again;
15821 } 15811 }
15822 15812
15823#if ENABLE_PLATFORM_MINGW32 15813 if ((uintptr_t)r == 2) /* -t SEC timeout? */
15814 /* bash: "The exit status is greater than 128 if the timeout is exceeded." */
15815 /* The actual value observed with bash 5.2.15: */
15816 return 128 + SIGALRM;
15817#else /* ENABLE_PLATFORM_MINGW32 */
15824 if ((uintptr_t)r == 2) { 15818 if ((uintptr_t)r == 2) {
15819 /* Timeout, return 128 + SIGALRM */
15820 return 142;
15821 } else if ((uintptr_t)r == 3) {
15825 /* ^C pressed, propagate event */ 15822 /* ^C pressed, propagate event */
15826 if (trap[SIGINT]) { 15823 if (trap[SIGINT]) {
15827 write(STDOUT_FILENO, "^C", 2); 15824 write(STDOUT_FILENO, "^C", 2);
@@ -15969,8 +15966,25 @@ exitshell(void)
15969 char *p; 15966 char *p;
15970 15967
15971#if ENABLE_FEATURE_EDITING_SAVE_ON_EXIT 15968#if ENABLE_FEATURE_EDITING_SAVE_ON_EXIT
15972 save_history(line_input_state); /* may be NULL */ 15969 if (line_input_state) {
15970 const char *hp;
15971# if ENABLE_FEATURE_SH_HISTFILESIZE
15972// in bash:
15973// HISTFILESIZE controls the on-disk history file size (in lines, 0=no history):
15974// "When this variable is assigned a value, the history file is truncated, if necessary"
15975// but we do it only at exit, not on assignment:
15976 /* Use HISTFILESIZE to limit file size */
15977 hp = lookupvar("HISTFILESIZE");
15978 if (hp)
15979 line_input_state->max_history = size_from_HISTFILESIZE(hp);
15980# endif
15981 /* HISTFILE: "If unset, the command history is not saved when a shell exits." */
15982 hp = lookupvar("HISTFILE");
15983 line_input_state->hist_file = hp;
15984 save_history(line_input_state); /* no-op if hist_file is NULL or "" */
15985 }
15973#endif 15986#endif
15987
15974 savestatus = exitstatus; 15988 savestatus = exitstatus;
15975 TRACE(("pid %d, exitshell(%d)\n", getpid(), savestatus)); 15989 TRACE(("pid %d, exitshell(%d)\n", getpid(), savestatus));
15976 if (setjmp(loc.loc)) 15990 if (setjmp(loc.loc))
@@ -16144,7 +16158,6 @@ init(void)
16144 } 16158 }
16145} 16159}
16146 16160
16147
16148//usage:#define ash_trivial_usage 16161//usage:#define ash_trivial_usage
16149//usage: "[-il] [-|+Cabefmnuvx] [-|+o OPT]... [-c 'SCRIPT' [ARG0 ARGS] | FILE ARGS | -s ARGS]" 16162//usage: "[-il] [-|+Cabefmnuvx] [-|+o OPT]... [-c 'SCRIPT' [ARG0 ARGS] | FILE ARGS | -s ARGS]"
16150//////// comes from ^^^^^^^^^^optletters 16163//////// comes from ^^^^^^^^^^optletters
@@ -16474,7 +16487,12 @@ int ash_main(int argc UNUSED_PARAM, char **argv)
16474 if (hp) 16487 if (hp)
16475 line_input_state->hist_file = xstrdup(hp); 16488 line_input_state->hist_file = xstrdup(hp);
16476# if ENABLE_FEATURE_SH_HISTFILESIZE 16489# if ENABLE_FEATURE_SH_HISTFILESIZE
16477 hp = lookupvar("HISTFILESIZE"); 16490 hp = lookupvar("HISTSIZE");
16491 /* Using HISTFILESIZE above to limit max_history would be WRONG:
16492 * users may set HISTFILESIZE=0 in their profile scripts
16493 * to prevent _saving_ of history files, but still want to have
16494 * non-zero history limit for in-memory list.
16495 */
16478 line_input_state->max_history = size_from_HISTFILESIZE(hp); 16496 line_input_state->max_history = size_from_HISTFILESIZE(hp);
16479# endif 16497# endif
16480 } 16498 }