diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2019-06-03 12:21:04 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2019-06-03 12:21:04 +0200 |
commit | f3634584d0fdeb4ae9e2fe0f5971d45b77e40296 (patch) | |
tree | 28a97129b30b28106b4f9fae7ddfbc5be12ba0f6 /shell/hush.c | |
parent | 897475ab023040efed9f199af5daffe43451c1d2 (diff) | |
download | busybox-w32-f3634584d0fdeb4ae9e2fe0f5971d45b77e40296.tar.gz busybox-w32-f3634584d0fdeb4ae9e2fe0f5971d45b77e40296.tar.bz2 busybox-w32-f3634584d0fdeb4ae9e2fe0f5971d45b77e40296.zip |
ash,hush: show 'c' in $- if run in "sh -c CMD"
function old new delta
options 552 599 +47
expand_one_var 2375 2385 +10
optletters_optnames 60 64 +4
hush_main 1108 1111 +3
ash_main 1150 1152 +2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 5/0 up/down: 66/0) Total: 66 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to '')
-rw-r--r-- | shell/hush.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/shell/hush.c b/shell/hush.c index 4b08232a4..f82747f74 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -903,6 +903,7 @@ struct globals { | |||
903 | # define G_x_mode 0 | 903 | # define G_x_mode 0 |
904 | #endif | 904 | #endif |
905 | char opt_s; | 905 | char opt_s; |
906 | char opt_c; | ||
906 | #if ENABLE_HUSH_INTERACTIVE | 907 | #if ENABLE_HUSH_INTERACTIVE |
907 | smallint promptmode; /* 0: PS1, 1: PS2 */ | 908 | smallint promptmode; /* 0: PS1, 1: PS2 */ |
908 | #endif | 909 | #endif |
@@ -1009,7 +1010,7 @@ struct globals { | |||
1009 | int debug_indent; | 1010 | int debug_indent; |
1010 | #endif | 1011 | #endif |
1011 | struct sigaction sa; | 1012 | struct sigaction sa; |
1012 | char optstring_buf[sizeof("eixs")]; | 1013 | char optstring_buf[sizeof("eixcs")]; |
1013 | #if BASH_EPOCH_VARS | 1014 | #if BASH_EPOCH_VARS |
1014 | char epoch_buf[sizeof("%lu.nnnnnn") + sizeof(long)*3]; | 1015 | char epoch_buf[sizeof("%lu.nnnnnn") + sizeof(long)*3]; |
1015 | #endif | 1016 | #endif |
@@ -6414,9 +6415,10 @@ static NOINLINE int expand_one_var(o_string *output, int n, | |||
6414 | * commands read but are not executed, | 6415 | * commands read but are not executed, |
6415 | * so $- can not execute too, 'n' is never seen in $-. | 6416 | * so $- can not execute too, 'n' is never seen in $-. |
6416 | */ | 6417 | */ |
6418 | if (G.opt_c) | ||
6419 | *cp++ = 'c'; | ||
6417 | if (G.opt_s) | 6420 | if (G.opt_s) |
6418 | *cp++ = 's'; | 6421 | *cp++ = 's'; |
6419 | //TODO: show 'c' if executed via "hush -c 'CMDS'" (bash only, not ash) | ||
6420 | *cp = '\0'; | 6422 | *cp = '\0'; |
6421 | break; | 6423 | break; |
6422 | } | 6424 | } |
@@ -9859,7 +9861,6 @@ int hush_main(int argc, char **argv) | |||
9859 | { | 9861 | { |
9860 | enum { | 9862 | enum { |
9861 | OPT_login = (1 << 0), | 9863 | OPT_login = (1 << 0), |
9862 | OPT_s = (1 << 1), | ||
9863 | }; | 9864 | }; |
9864 | unsigned flags; | 9865 | unsigned flags; |
9865 | unsigned builtin_argc; | 9866 | unsigned builtin_argc; |
@@ -10029,6 +10030,7 @@ int hush_main(int argc, char **argv) | |||
10029 | } | 10030 | } |
10030 | goto final_return; | 10031 | goto final_return; |
10031 | } | 10032 | } |
10033 | G.opt_c = 1; | ||
10032 | if (!G.global_argv[0]) { | 10034 | if (!G.global_argv[0]) { |
10033 | /* -c 'script' (no params): prevent empty $0 */ | 10035 | /* -c 'script' (no params): prevent empty $0 */ |
10034 | G.global_argv--; /* points to argv[i] of 'script' */ | 10036 | G.global_argv--; /* points to argv[i] of 'script' */ |
@@ -10044,7 +10046,7 @@ int hush_main(int argc, char **argv) | |||
10044 | /* G_interactive_fd++; */ | 10046 | /* G_interactive_fd++; */ |
10045 | break; | 10047 | break; |
10046 | case 's': | 10048 | case 's': |
10047 | flags |= OPT_s; | 10049 | G.opt_s = 1; |
10048 | break; | 10050 | break; |
10049 | case 'l': | 10051 | case 'l': |
10050 | flags |= OPT_login; | 10052 | flags |= OPT_login; |
@@ -10154,7 +10156,7 @@ int hush_main(int argc, char **argv) | |||
10154 | } | 10156 | } |
10155 | 10157 | ||
10156 | /* -s is: hush -s ARGV1 ARGV2 (no SCRIPT) */ | 10158 | /* -s is: hush -s ARGV1 ARGV2 (no SCRIPT) */ |
10157 | if (!(flags & OPT_s) && G.global_argv[1]) { | 10159 | if (!G.opt_s && G.global_argv[1]) { |
10158 | HFILE *input; | 10160 | HFILE *input; |
10159 | /* | 10161 | /* |
10160 | * "bash <script>" (which is never interactive (unless -i?)) | 10162 | * "bash <script>" (which is never interactive (unless -i?)) |
@@ -10178,6 +10180,7 @@ int hush_main(int argc, char **argv) | |||
10178 | #endif | 10180 | #endif |
10179 | goto final_return; | 10181 | goto final_return; |
10180 | } | 10182 | } |
10183 | /* "implicit" -s: bare interactive hush shows 's' in $- */ | ||
10181 | G.opt_s = 1; | 10184 | G.opt_s = 1; |
10182 | 10185 | ||
10183 | /* Up to here, shell was non-interactive. Now it may become one. | 10186 | /* Up to here, shell was non-interactive. Now it may become one. |