diff options
author | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2010-09-23 10:14:53 +1000 |
---|---|---|
committer | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2010-09-23 10:14:53 +1000 |
commit | fdc69a4b0eadfefaf1247f868953a896aa73e2f2 (patch) | |
tree | 05dabd8519bcdd7bad8c7a1153f471675a1ca676 | |
parent | f4f8fa6f4a41df8f9e41ad562bbff7d18032de07 (diff) | |
download | busybox-w32-fdc69a4b0eadfefaf1247f868953a896aa73e2f2.tar.gz busybox-w32-fdc69a4b0eadfefaf1247f868953a896aa73e2f2.tar.bz2 busybox-w32-fdc69a4b0eadfefaf1247f868953a896aa73e2f2.zip |
win32: ash: implement ^C (and Ctrl+Break)
^C sometimes does not work while Ctrl+Break seems to always work
-rw-r--r-- | BUGS | 3 | ||||
-rw-r--r-- | shell/ash.c | 25 |
2 files changed, 28 insertions, 0 deletions
@@ -10,6 +10,9 @@ | |||
10 | 10 | ||
11 | ^Z can be used while ^D does not work | 11 | ^Z can be used while ^D does not work |
12 | 12 | ||
13 | ^C sometimes does not work (Ctrl-Break always works though). | ||
14 | This may have something to do with read_key()? | ||
15 | |||
13 | ** $HOME not set | 16 | ** $HOME not set |
14 | 17 | ||
15 | $HOMEPATH should probably be used | 18 | $HOMEPATH should probably be used |
diff --git a/shell/ash.c b/shell/ash.c index c3b497938..5c24762f2 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -4050,6 +4050,18 @@ sprint_status(char *s, int status, int sigonly) | |||
4050 | } | 4050 | } |
4051 | 4051 | ||
4052 | #if ENABLE_PLATFORM_MINGW32 | 4052 | #if ENABLE_PLATFORM_MINGW32 |
4053 | |||
4054 | HANDLE hSIGINT; /* Ctrl-C is pressed */ | ||
4055 | |||
4056 | static BOOL WINAPI ctrl_handler(DWORD dwCtrlType) | ||
4057 | { | ||
4058 | if (dwCtrlType == CTRL_C_EVENT || dwCtrlType == CTRL_BREAK_EVENT) { | ||
4059 | SetEvent(hSIGINT); | ||
4060 | return TRUE; | ||
4061 | } | ||
4062 | return FALSE; | ||
4063 | } | ||
4064 | |||
4053 | /* | 4065 | /* |
4054 | * Windows does not know about parent-child relationship | 4066 | * Windows does not know about parent-child relationship |
4055 | * They don't support waitpid(-1) | 4067 | * They don't support waitpid(-1) |
@@ -4081,7 +4093,9 @@ waitpid_child(int *status) | |||
4081 | LOOP(pid_nr++); | 4093 | LOOP(pid_nr++); |
4082 | if (!pid_nr) | 4094 | if (!pid_nr) |
4083 | return -1; | 4095 | return -1; |
4096 | pid_nr++; | ||
4084 | pidp = pidlist = ckmalloc(sizeof(*pidlist)*pid_nr); | 4097 | pidp = pidlist = ckmalloc(sizeof(*pidlist)*pid_nr); |
4098 | *pidp++ = hSIGINT; | ||
4085 | LOOP(*pidp++ = (HANDLE)ps->ps_pid); | 4099 | LOOP(*pidp++ = (HANDLE)ps->ps_pid); |
4086 | #undef LOOP | 4100 | #undef LOOP |
4087 | 4101 | ||
@@ -4090,6 +4104,15 @@ waitpid_child(int *status) | |||
4090 | free(pidlist); | 4104 | free(pidlist); |
4091 | return -1; | 4105 | return -1; |
4092 | } | 4106 | } |
4107 | if (!idx) { /* hSIGINT */ | ||
4108 | int i; | ||
4109 | ResetEvent(hSIGINT); | ||
4110 | for (i = 1; i < pid_nr; i++) | ||
4111 | TerminateProcess(pidlist[i], 1); | ||
4112 | free(pidlist); | ||
4113 | *status = 260; /* terminated by a signal */ | ||
4114 | return pidlist[1]; | ||
4115 | } | ||
4093 | GetExitCodeProcess(pidlist[idx], &win_status); | 4116 | GetExitCodeProcess(pidlist[idx], &win_status); |
4094 | pid = (int)pidlist[idx]; | 4117 | pid = (int)pidlist[idx]; |
4095 | free(pidlist); | 4118 | free(pidlist); |
@@ -13593,6 +13616,8 @@ int ash_main(int argc UNUSED_PARAM, char **argv) | |||
13593 | setstackmark(&smark); | 13616 | setstackmark(&smark); |
13594 | 13617 | ||
13595 | #if ENABLE_PLATFORM_MINGW32 | 13618 | #if ENABLE_PLATFORM_MINGW32 |
13619 | hSIGINT = CreateEvent(NULL, TRUE, FALSE, NULL); | ||
13620 | SetConsoleCtrlHandler(ctrl_handler, TRUE); | ||
13596 | if (argc == 3 && !strcmp(argv[1], "--forkshell")) { | 13621 | if (argc == 3 && !strcmp(argv[1], "--forkshell")) { |
13597 | forkshell_init(argv[2]); | 13622 | forkshell_init(argv[2]); |
13598 | 13623 | ||