From 004cefa918483513a9eca13e7701c74dff160e95 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Wed, 12 Jan 2022 17:21:14 +0100 Subject: reset: better --help text function old new delta packed_usage 34175 34233 +58 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- shell/ash.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'shell') diff --git a/shell/ash.c b/shell/ash.c index 4a8ec0c03..4c5dd1298 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -11358,7 +11358,7 @@ options(int *login_sh) int val; int c; - if (login_sh) + if (login_sh != NULL) /* if we came from startup code */ minusc = NULL; while ((p = *argptr) != NULL) { c = *p++; @@ -11369,7 +11369,7 @@ options(int *login_sh) if (c == '-') { val = 1; if (p[0] == '\0' || LONE_DASH(p)) { - if (!login_sh) { + if (login_sh == NULL) { /* we came from setcmd() */ /* "-" means turn off -x and -v */ if (p[0] == '\0') xflag = vflag = 0; @@ -11382,7 +11382,7 @@ options(int *login_sh) } /* first char was + or - */ while ((c = *p++) != '\0') { - if (login_sh) { + if (login_sh != NULL) { /* if we came from startup code */ /* bash 3.2 indeed handles -c CMD and +c CMD the same */ if (c == 'c') { minusc = p; /* command is after shell args */ @@ -11406,6 +11406,9 @@ options(int *login_sh) if (strcmp(p, "login") == 0) { *login_sh = 1; } +/* TODO: --noprofile: e.g. if I want to run emergency shell from sulogin, + * I want minimal/no shell init scripts - but it insists on running it as "-ash"... + */ break; } } -- cgit v1.2.3-55-g6feb From 68b402ee51f12f8c3b11638b042f57e025359faf Mon Sep 17 00:00:00 2001 From: Denys Vlasenko <vda.linux@googlemail.com> Date: Thu, 13 Jan 2022 01:05:03 +0100 Subject: ash: ^C with SIG_INGed SIGINT should not exit the shell function old new delta __pgetc 501 522 +21 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> --- loginutils/login.c | 4 +++- loginutils/sulogin.c | 5 +++++ shell/ash.c | 8 +++++++- 3 files changed, 15 insertions(+), 2 deletions(-) (limited to 'shell') diff --git a/loginutils/login.c b/loginutils/login.c index 569053c12..cac4349b2 100644 --- a/loginutils/login.c +++ b/loginutils/login.c @@ -608,7 +608,9 @@ int login_main(int argc UNUSED_PARAM, char **argv) * But without this, bash 3.0 will not enable ctrl-c either. * Maybe bash is buggy? * Need to find out what standards say about /bin/login - - * should we leave SIGINT etc enabled or disabled? */ + * should we leave SIGINT etc enabled or disabled? + * Also note: sulogin does not do it! Why? + */ signal(SIGINT, SIG_DFL); /* Exec login shell with no additional parameters */ diff --git a/loginutils/sulogin.c b/loginutils/sulogin.c index 5f1c1178f..2f87c77c0 100644 --- a/loginutils/sulogin.c +++ b/loginutils/sulogin.c @@ -111,6 +111,11 @@ int sulogin_main(int argc UNUSED_PARAM, char **argv) } } + /* + * Note: login does this (should we do it too?): + */ + /*signal(SIGINT, SIG_DFL);*/ + /* Exec login shell with no additional parameters. Never returns. */ exec_login_shell(shell); } diff --git a/shell/ash.c b/shell/ash.c index 4c5dd1298..12b2db3a9 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -10784,18 +10784,24 @@ preadfd(void) line_input_state->path_lookup = pathval(); # endif reinit_unicode_for_ash(); + again: nr = read_line_input(line_input_state, cmdedit_prompt, buf, IBUFSIZ); if (nr == 0) { /* ^C pressed, "convert" to SIGINT */ write(STDOUT_FILENO, "^C", 2); raise(SIGINT); + /* raise(SIGINT) did not work! (e.g. if SIGINT + * is SIG_INGed on startup, it stays SIG_IGNed) + */ if (trap[SIGINT]) { buf[0] = '\n'; buf[1] = '\0'; return 1; } exitstatus = 128 + SIGINT; - return -1; + /* bash behavior on ^C + ignored SIGINT: */ + write(STDOUT_FILENO, "\n", 1); + goto again; } if (nr < 0) { if (errno == 0) { -- cgit v1.2.3-55-g6feb