diff options
| -rw-r--r-- | include/mingw.h | 2 | ||||
| -rw-r--r-- | win32/process.c | 34 |
2 files changed, 22 insertions, 14 deletions
diff --git a/include/mingw.h b/include/mingw.h index bc0772574..2dba6c402 100644 --- a/include/mingw.h +++ b/include/mingw.h | |||
| @@ -438,6 +438,8 @@ const char * next_path_sep(const char *path); | |||
| 438 | #define has_dos_drive_prefix(path) (isalpha(*(path)) && (path)[1] == ':') | 438 | #define has_dos_drive_prefix(path) (isalpha(*(path)) && (path)[1] == ':') |
| 439 | #define is_absolute_path(path) ((path)[0] == '/' || (path)[0] == '\\' || has_dos_drive_prefix(path)) | 439 | #define is_absolute_path(path) ((path)[0] == '/' || (path)[0] == '\\' || has_dos_drive_prefix(path)) |
| 440 | 440 | ||
| 441 | int kill_SIGTERM_by_handle(HANDLE process, int exit_code); | ||
| 442 | |||
| 441 | #define find_mount_point(n, s) find_mount_point(n) | 443 | #define find_mount_point(n, s) find_mount_point(n) |
| 442 | 444 | ||
| 443 | /* | 445 | /* |
diff --git a/win32/process.c b/win32/process.c index 8842e0dee..84613cfdb 100644 --- a/win32/process.c +++ b/win32/process.c | |||
| @@ -580,19 +580,11 @@ static inline int process_architecture_matches_current(HANDLE process) | |||
| 580 | * http://www.drdobbs.com/a-safer-alternative-to-terminateprocess/184416547 | 580 | * http://www.drdobbs.com/a-safer-alternative-to-terminateprocess/184416547 |
| 581 | * | 581 | * |
| 582 | */ | 582 | */ |
| 583 | static int exit_process(pid_t pid, int exit_code) | 583 | int kill_SIGTERM_by_handle(HANDLE process, int exit_code) |
| 584 | { | 584 | { |
| 585 | HANDLE process; | ||
| 586 | DWORD code; | 585 | DWORD code; |
| 587 | int ret = 0; | 586 | int ret = 0; |
| 588 | 587 | ||
| 589 | if (!(process = OpenProcess(SYNCHRONIZE | PROCESS_CREATE_THREAD | | ||
| 590 | PROCESS_QUERY_INFORMATION | | ||
| 591 | PROCESS_VM_OPERATION | PROCESS_VM_WRITE | | ||
| 592 | PROCESS_VM_READ, FALSE, pid))) { | ||
| 593 | return -1; | ||
| 594 | } | ||
| 595 | |||
| 596 | if (GetExitCodeProcess(process, &code) && code == STILL_ACTIVE) { | 588 | if (GetExitCodeProcess(process, &code) && code == STILL_ACTIVE) { |
| 597 | static int initialized; | 589 | static int initialized; |
| 598 | static LPTHREAD_START_ROUTINE exit_process_address; | 590 | static LPTHREAD_START_ROUTINE exit_process_address; |
| @@ -629,12 +621,26 @@ static int exit_process(pid_t pid, int exit_code) | |||
| 629 | return ret; | 621 | return ret; |
| 630 | } | 622 | } |
| 631 | 623 | ||
| 624 | static int kill_SIGTERM(pid_t pid, int exit_code) | ||
| 625 | { | ||
| 626 | HANDLE process; | ||
| 627 | |||
| 628 | if (!(process = OpenProcess(SYNCHRONIZE | PROCESS_CREATE_THREAD | | ||
| 629 | PROCESS_QUERY_INFORMATION | | ||
| 630 | PROCESS_VM_OPERATION | PROCESS_VM_WRITE | | ||
| 631 | PROCESS_VM_READ, FALSE, pid))) { | ||
| 632 | return -1; | ||
| 633 | } | ||
| 634 | |||
| 635 | return kill_SIGTERM_by_handle(process, exit_code); | ||
| 636 | } | ||
| 637 | |||
| 632 | /* | 638 | /* |
| 633 | * This way of terminating processes is not gentle: they get no chance to | 639 | * This way of terminating processes is not gentle: they get no chance to |
| 634 | * clean up after themselves (closing file handles, removing .lock files, | 640 | * clean up after themselves (closing file handles, removing .lock files, |
| 635 | * terminating spawned processes (if any), etc). | 641 | * terminating spawned processes (if any), etc). |
| 636 | */ | 642 | */ |
| 637 | static int terminate_process(pid_t pid, int exit_code) | 643 | static int kill_SIGKILL(pid_t pid, int exit_code) |
| 638 | { | 644 | { |
| 639 | HANDLE process; | 645 | HANDLE process; |
| 640 | int ret; | 646 | int ret; |
| @@ -649,7 +655,7 @@ static int terminate_process(pid_t pid, int exit_code) | |||
| 649 | return ret; | 655 | return ret; |
| 650 | } | 656 | } |
| 651 | 657 | ||
| 652 | static int test_process(pid_t pid, int exit_code UNUSED_PARAM) | 658 | static int kill_SIGTEST(pid_t pid, int exit_code UNUSED_PARAM) |
| 653 | { | 659 | { |
| 654 | HANDLE process; | 660 | HANDLE process; |
| 655 | 661 | ||
| @@ -664,13 +670,13 @@ static int test_process(pid_t pid, int exit_code UNUSED_PARAM) | |||
| 664 | int kill(pid_t pid, int sig) | 670 | int kill(pid_t pid, int sig) |
| 665 | { | 671 | { |
| 666 | if (sig == SIGTERM) { | 672 | if (sig == SIGTERM) { |
| 667 | return kill_pids(pid, 128+sig, exit_process); | 673 | return kill_pids(pid, 128+sig, kill_SIGTERM); |
| 668 | } | 674 | } |
| 669 | else if (sig == SIGKILL) { | 675 | else if (sig == SIGKILL) { |
| 670 | return kill_pids(pid, 128+sig, terminate_process); | 676 | return kill_pids(pid, 128+sig, kill_SIGKILL); |
| 671 | } | 677 | } |
| 672 | else if (sig == 0) { | 678 | else if (sig == 0) { |
| 673 | return kill_pids(pid, 128+sig, test_process); | 679 | return kill_pids(pid, 128+sig, kill_SIGTEST); |
| 674 | } | 680 | } |
| 675 | 681 | ||
| 676 | errno = EINVAL; | 682 | errno = EINVAL; |
