hush: make SIGINT handling visually less confusing
authorDenys Vlasenko <vda.linux@googlemail.com>
Wed, 2 Aug 2017 14:52:12 +0000 (16:52 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Wed, 2 Aug 2017 14:52:12 +0000 (16:52 +0200)
$ echo $$
18448
$ echo $? <wait here, run "kill -INT 18448" in other shell><press enter>
   <=== NOTHING??
$

That empty line does not look right. After this patch:

$ echo $$
18448
$ echo $? <wait here, run "kill -INT 18448" in other shell><press enter>
^C
$

function                                             old     new   delta
fgetc_interactive                                    245     246      +1

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
shell/hush.c

index cfefb7324e269831b8acadd5318e3f62ccfdedb2..93ed0bc0b74f584c9a88ade63b56d5ae4b92243f 100644 (file)
@@ -2415,14 +2415,14 @@ static int get_user_input(struct in_str *i)
                                /*timeout*/ -1
                );
                /* read_line_input intercepts ^C, "convert" it to SIGINT */
-               if (r == 0) {
-                       write(STDOUT_FILENO, "^C", 2);
+               if (r == 0)
                        raise(SIGINT);
-               }
                check_and_run_traps();
                if (r != 0 && !G.flag_SIGINT)
                        break;
                /* ^C or SIGINT: repeat */
+               /* bash prints ^C even on real SIGINT (non-kbd generated) */
+               write(STDOUT_FILENO, "^C", 2);
                G.last_exitcode = 128 + SIGINT;
        }
        if (r < 0) {