diff options
| author | Eli Zaretskii | 2024-06-13 11:03:52 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2024-06-13 11:03:52 +0300 |
| commit | 72e6b05221502cf722f7bddf2d100e5eff424dd8 (patch) | |
| tree | 7a865e733d300d0e02c14d87180adfe88ecb8b16 /src/w32proc.c | |
| parent | 8eeb159b95130a0dc29040ffa9f330874576964e (diff) | |
| download | emacs-72e6b05221502cf722f7bddf2d100e5eff424dd8.tar.gz emacs-72e6b05221502cf722f7bddf2d100e5eff424dd8.zip | |
; * src/w32proc.c (sys_kill): Handle negative PID when sig == 0.
Diffstat (limited to 'src/w32proc.c')
| -rw-r--r-- | src/w32proc.c | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/src/w32proc.c b/src/w32proc.c index 4d237992b14..40181e09830 100644 --- a/src/w32proc.c +++ b/src/w32proc.c | |||
| @@ -2727,6 +2727,7 @@ sys_kill (pid_t pid, int sig) | |||
| 2727 | HANDLE proc_hand; | 2727 | HANDLE proc_hand; |
| 2728 | int need_to_free = 0; | 2728 | int need_to_free = 0; |
| 2729 | int rc = 0; | 2729 | int rc = 0; |
| 2730 | pid_t orig_pid = pid; | ||
| 2730 | 2731 | ||
| 2731 | /* Each process is in its own process group. */ | 2732 | /* Each process is in its own process group. */ |
| 2732 | if (pid < 0) | 2733 | if (pid < 0) |
| @@ -2734,7 +2735,8 @@ sys_kill (pid_t pid, int sig) | |||
| 2734 | 2735 | ||
| 2735 | /* Only handle signals that can be mapped to a similar behavior on Windows */ | 2736 | /* Only handle signals that can be mapped to a similar behavior on Windows */ |
| 2736 | if (sig != 0 | 2737 | if (sig != 0 |
| 2737 | && sig != SIGINT && sig != SIGKILL && sig != SIGQUIT && sig != SIGHUP && sig != SIGTRAP) | 2738 | && sig != SIGINT && sig != SIGKILL && sig != SIGQUIT |
| 2739 | && sig != SIGHUP && sig != SIGTRAP) | ||
| 2738 | { | 2740 | { |
| 2739 | errno = EINVAL; | 2741 | errno = EINVAL; |
| 2740 | return -1; | 2742 | return -1; |
| @@ -2760,11 +2762,34 @@ sys_kill (pid_t pid, int sig) | |||
| 2760 | errno = EPERM; | 2762 | errno = EPERM; |
| 2761 | return -1; | 2763 | return -1; |
| 2762 | case ERROR_INVALID_PARAMETER: /* process PID does not exist */ | 2764 | case ERROR_INVALID_PARAMETER: /* process PID does not exist */ |
| 2763 | errno = ESRCH; | 2765 | { |
| 2764 | return -1; | 2766 | if (orig_pid == pid) |
| 2767 | { | ||
| 2768 | errno = ESRCH; | ||
| 2769 | return -1; | ||
| 2770 | } | ||
| 2771 | /* If we received a negative value, try again with the | ||
| 2772 | original one we received. */ | ||
| 2773 | proc_hand = OpenProcess (PROCESS_QUERY_INFORMATION, | ||
| 2774 | 0, orig_pid); | ||
| 2775 | if (proc_hand == NULL) | ||
| 2776 | { | ||
| 2777 | err = GetLastError (); | ||
| 2778 | switch (err) | ||
| 2779 | { | ||
| 2780 | case ERROR_ACCESS_DENIED: | ||
| 2781 | errno = EPERM; | ||
| 2782 | return -1; | ||
| 2783 | case ERROR_INVALID_PARAMETER: | ||
| 2784 | errno = ESRCH; | ||
| 2785 | return -1; | ||
| 2786 | } | ||
| 2787 | } | ||
| 2788 | break; | ||
| 2789 | } | ||
| 2765 | } | 2790 | } |
| 2766 | } | 2791 | } |
| 2767 | else | 2792 | if (proc_hand != NULL) |
| 2768 | CloseHandle (proc_hand); | 2793 | CloseHandle (proc_hand); |
| 2769 | return 0; | 2794 | return 0; |
| 2770 | } | 2795 | } |