diff options
Diffstat (limited to '')
-rw-r--r-- | shell/ash.c | 49 |
1 files changed, 31 insertions, 18 deletions
diff --git a/shell/ash.c b/shell/ash.c index 9173b8608..9cacdff64 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -329,7 +329,7 @@ typedef long arith_t; | |||
329 | 329 | ||
330 | /* ============ Shell options */ | 330 | /* ============ Shell options */ |
331 | 331 | ||
332 | /* If you add/change options hare, update --help text too */ | 332 | /* If you add/change options here, update --help text too */ |
333 | static const char *const optletters_optnames[] ALIGN_PTR = { | 333 | static const char *const optletters_optnames[] ALIGN_PTR = { |
334 | "e" "errexit", | 334 | "e" "errexit", |
335 | "f" "noglob", | 335 | "f" "noglob", |
@@ -1596,7 +1596,6 @@ struct stackmark { | |||
1596 | size_t stacknleft; | 1596 | size_t stacknleft; |
1597 | }; | 1597 | }; |
1598 | 1598 | ||
1599 | |||
1600 | struct globals_memstack { | 1599 | struct globals_memstack { |
1601 | struct stack_block *g_stackp; // = &stackbase; | 1600 | struct stack_block *g_stackp; // = &stackbase; |
1602 | char *g_stacknxt; // = stackbase.space; | 1601 | char *g_stacknxt; // = stackbase.space; |
@@ -1619,7 +1618,6 @@ extern struct globals_memstack *BB_GLOBAL_CONST ash_ptr_to_globals_memstack; | |||
1619 | sstrend = stackbase.space + MINSIZE; \ | 1618 | sstrend = stackbase.space + MINSIZE; \ |
1620 | } while (0) | 1619 | } while (0) |
1621 | 1620 | ||
1622 | |||
1623 | #define stackblock() ((void *)g_stacknxt) | 1621 | #define stackblock() ((void *)g_stacknxt) |
1624 | #define stackblocksize() g_stacknleft | 1622 | #define stackblocksize() g_stacknleft |
1625 | 1623 | ||
@@ -2121,7 +2119,6 @@ struct localvar { | |||
2121 | # define VDYNAMIC 0 | 2119 | # define VDYNAMIC 0 |
2122 | #endif | 2120 | #endif |
2123 | 2121 | ||
2124 | |||
2125 | /* Need to be before varinit_data[] */ | 2122 | /* Need to be before varinit_data[] */ |
2126 | #if ENABLE_LOCALE_SUPPORT | 2123 | #if ENABLE_LOCALE_SUPPORT |
2127 | static void FAST_FUNC | 2124 | static void FAST_FUNC |
@@ -3007,7 +3004,6 @@ pwdcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | |||
3007 | 3004 | ||
3008 | /* ============ ... */ | 3005 | /* ============ ... */ |
3009 | 3006 | ||
3010 | |||
3011 | #define IBUFSIZ (ENABLE_FEATURE_EDITING ? CONFIG_FEATURE_EDITING_MAX_LEN : 1024) | 3007 | #define IBUFSIZ (ENABLE_FEATURE_EDITING ? CONFIG_FEATURE_EDITING_MAX_LEN : 1024) |
3012 | 3008 | ||
3013 | /* Syntax classes */ | 3009 | /* Syntax classes */ |
@@ -3414,13 +3410,11 @@ struct alias { | |||
3414 | int flag; | 3410 | int flag; |
3415 | }; | 3411 | }; |
3416 | 3412 | ||
3417 | |||
3418 | static struct alias **atab; // [ATABSIZE]; | 3413 | static struct alias **atab; // [ATABSIZE]; |
3419 | #define INIT_G_alias() do { \ | 3414 | #define INIT_G_alias() do { \ |
3420 | atab = xzalloc(ATABSIZE * sizeof(atab[0])); \ | 3415 | atab = xzalloc(ATABSIZE * sizeof(atab[0])); \ |
3421 | } while (0) | 3416 | } while (0) |
3422 | 3417 | ||
3423 | |||
3424 | static struct alias ** | 3418 | static struct alias ** |
3425 | __lookupalias(const char *name) | 3419 | __lookupalias(const char *name) |
3426 | { | 3420 | { |
@@ -3602,7 +3596,6 @@ unaliascmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | |||
3602 | 3596 | ||
3603 | #endif /* ASH_ALIAS */ | 3597 | #endif /* ASH_ALIAS */ |
3604 | 3598 | ||
3605 | |||
3606 | /* Mode argument to forkshell. Don't change FORK_FG or FORK_BG. */ | 3599 | /* Mode argument to forkshell. Don't change FORK_FG or FORK_BG. */ |
3607 | #define FORK_FG 0 | 3600 | #define FORK_FG 0 |
3608 | #define FORK_BG 1 | 3601 | #define FORK_BG 1 |
@@ -3687,7 +3680,7 @@ signal_handler(int signo) | |||
3687 | return; | 3680 | return; |
3688 | } | 3681 | } |
3689 | #if ENABLE_FEATURE_EDITING | 3682 | #if ENABLE_FEATURE_EDITING |
3690 | bb_got_signal = signo; /* for read_line_input: "we got a signal" */ | 3683 | bb_got_signal = signo; /* for read_line_input / read builtin: "we got a signal" */ |
3691 | #endif | 3684 | #endif |
3692 | gotsig[signo - 1] = 1; | 3685 | gotsig[signo - 1] = 1; |
3693 | pending_sig = signo; | 3686 | pending_sig = signo; |
@@ -5462,7 +5455,6 @@ stoppedjobs(void) | |||
5462 | return retval; | 5455 | return retval; |
5463 | } | 5456 | } |
5464 | 5457 | ||
5465 | |||
5466 | /* | 5458 | /* |
5467 | * Code for dealing with input/output redirection. | 5459 | * Code for dealing with input/output redirection. |
5468 | */ | 5460 | */ |
@@ -8935,7 +8927,6 @@ commandcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | |||
8935 | } | 8927 | } |
8936 | #endif | 8928 | #endif |
8937 | 8929 | ||
8938 | |||
8939 | /*static int funcblocksize; // size of structures in function */ | 8930 | /*static int funcblocksize; // size of structures in function */ |
8940 | /*static int funcstringsize; // size of strings in node */ | 8931 | /*static int funcstringsize; // size of strings in node */ |
8941 | static void *funcblock; /* block to allocate function from */ | 8932 | static void *funcblock; /* block to allocate function from */ |
@@ -10698,7 +10689,6 @@ goodname(const char *p) | |||
10698 | return endofname(p)[0] == '\0'; | 10689 | return endofname(p)[0] == '\0'; |
10699 | } | 10690 | } |
10700 | 10691 | ||
10701 | |||
10702 | /* | 10692 | /* |
10703 | * Search for a command. This is called before we fork so that the | 10693 | * Search for a command. This is called before we fork so that the |
10704 | * location of the command will be available in the parent as well as | 10694 | * location of the command will be available in the parent as well as |
@@ -13448,7 +13438,6 @@ parseheredoc(void) | |||
13448 | } | 13438 | } |
13449 | } | 13439 | } |
13450 | 13440 | ||
13451 | |||
13452 | static const char * | 13441 | static const char * |
13453 | expandstr(const char *ps, int syntax_type) | 13442 | expandstr(const char *ps, int syntax_type) |
13454 | { | 13443 | { |
@@ -14037,7 +14026,6 @@ find_command(char *name, struct cmdentry *entry, int act, const char *path) | |||
14037 | entry->u = cmdp->param; | 14026 | entry->u = cmdp->param; |
14038 | } | 14027 | } |
14039 | 14028 | ||
14040 | |||
14041 | /* | 14029 | /* |
14042 | * The trap builtin. | 14030 | * The trap builtin. |
14043 | */ | 14031 | */ |
@@ -14395,6 +14383,11 @@ readcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | |||
14395 | goto again; | 14383 | goto again; |
14396 | } | 14384 | } |
14397 | 14385 | ||
14386 | if ((uintptr_t)r == 2) /* -t SEC timeout? */ | ||
14387 | /* bash: "The exit status is greater than 128 if the timeout is exceeded." */ | ||
14388 | /* The actual value observed with bash 5.2.15: */ | ||
14389 | return 128 + SIGALRM; | ||
14390 | |||
14398 | if ((uintptr_t)r > 1) | 14391 | if ((uintptr_t)r > 1) |
14399 | ash_msg_and_raise_error(r); | 14392 | ash_msg_and_raise_error(r); |
14400 | 14393 | ||
@@ -14520,8 +14513,25 @@ exitshell(void) | |||
14520 | char *p; | 14513 | char *p; |
14521 | 14514 | ||
14522 | #if ENABLE_FEATURE_EDITING_SAVE_ON_EXIT | 14515 | #if ENABLE_FEATURE_EDITING_SAVE_ON_EXIT |
14523 | save_history(line_input_state); /* may be NULL */ | 14516 | if (line_input_state) { |
14517 | const char *hp; | ||
14518 | # if ENABLE_FEATURE_SH_HISTFILESIZE | ||
14519 | // in bash: | ||
14520 | // HISTFILESIZE controls the on-disk history file size (in lines, 0=no history): | ||
14521 | // "When this variable is assigned a value, the history file is truncated, if necessary" | ||
14522 | // but we do it only at exit, not on assignment: | ||
14523 | /* Use HISTFILESIZE to limit file size */ | ||
14524 | hp = lookupvar("HISTFILESIZE"); | ||
14525 | if (hp) | ||
14526 | line_input_state->max_history = size_from_HISTFILESIZE(hp); | ||
14527 | # endif | ||
14528 | /* HISTFILE: "If unset, the command history is not saved when a shell exits." */ | ||
14529 | hp = lookupvar("HISTFILE"); | ||
14530 | line_input_state->hist_file = hp; | ||
14531 | save_history(line_input_state); /* no-op if hist_file is NULL or "" */ | ||
14532 | } | ||
14524 | #endif | 14533 | #endif |
14534 | |||
14525 | savestatus = exitstatus; | 14535 | savestatus = exitstatus; |
14526 | TRACE(("pid %d, exitshell(%d)\n", getpid(), savestatus)); | 14536 | TRACE(("pid %d, exitshell(%d)\n", getpid(), savestatus)); |
14527 | if (setjmp(loc.loc)) | 14537 | if (setjmp(loc.loc)) |
@@ -14609,7 +14619,6 @@ init(void) | |||
14609 | } | 14619 | } |
14610 | } | 14620 | } |
14611 | 14621 | ||
14612 | |||
14613 | //usage:#define ash_trivial_usage | 14622 | //usage:#define ash_trivial_usage |
14614 | //usage: "[-il] [-|+Cabefmnuvx] [-|+o OPT]... [-c 'SCRIPT' [ARG0 ARGS] | FILE ARGS | -s ARGS]" | 14623 | //usage: "[-il] [-|+Cabefmnuvx] [-|+o OPT]... [-c 'SCRIPT' [ARG0 ARGS] | FILE ARGS | -s ARGS]" |
14615 | //////// comes from ^^^^^^^^^^optletters | 14624 | //////// comes from ^^^^^^^^^^optletters |
@@ -14862,7 +14871,12 @@ int ash_main(int argc UNUSED_PARAM, char **argv) | |||
14862 | if (hp) | 14871 | if (hp) |
14863 | line_input_state->hist_file = xstrdup(hp); | 14872 | line_input_state->hist_file = xstrdup(hp); |
14864 | # if ENABLE_FEATURE_SH_HISTFILESIZE | 14873 | # if ENABLE_FEATURE_SH_HISTFILESIZE |
14865 | hp = lookupvar("HISTFILESIZE"); | 14874 | hp = lookupvar("HISTSIZE"); |
14875 | /* Using HISTFILESIZE above to limit max_history would be WRONG: | ||
14876 | * users may set HISTFILESIZE=0 in their profile scripts | ||
14877 | * to prevent _saving_ of history files, but still want to have | ||
14878 | * non-zero history limit for in-memory list. | ||
14879 | */ | ||
14866 | line_input_state->max_history = size_from_HISTFILESIZE(hp); | 14880 | line_input_state->max_history = size_from_HISTFILESIZE(hp); |
14867 | # endif | 14881 | # endif |
14868 | } | 14882 | } |
@@ -14884,7 +14898,6 @@ int ash_main(int argc UNUSED_PARAM, char **argv) | |||
14884 | /* NOTREACHED */ | 14898 | /* NOTREACHED */ |
14885 | } | 14899 | } |
14886 | 14900 | ||
14887 | |||
14888 | /*- | 14901 | /*- |
14889 | * Copyright (c) 1989, 1991, 1993, 1994 | 14902 | * Copyright (c) 1989, 1991, 1993, 1994 |
14890 | * The Regents of the University of California. All rights reserved. | 14903 | * The Regents of the University of California. All rights reserved. |