diff options
Diffstat (limited to 'src/w32proc.c')
| -rw-r--r-- | src/w32proc.c | 270 |
1 files changed, 212 insertions, 58 deletions
diff --git a/src/w32proc.c b/src/w32proc.c index 9b111b40e36..84589388cd7 100644 --- a/src/w32proc.c +++ b/src/w32proc.c | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* Process support for GNU Emacs on the Microsoft Windows API. | 1 | /* Process support for GNU Emacs on the Microsoft Windows API. |
| 2 | Copyright (C) 1992, 1995, 1999-2012 Free Software Foundation, Inc. | 2 | Copyright (C) 1992, 1995, 1999-2013 Free Software Foundation, Inc. |
| 3 | 3 | ||
| 4 | This file is part of GNU Emacs. | 4 | This file is part of GNU Emacs. |
| 5 | 5 | ||
| @@ -800,18 +800,68 @@ new_child (void) | |||
| 800 | DWORD id; | 800 | DWORD id; |
| 801 | 801 | ||
| 802 | for (cp = child_procs + (child_proc_count-1); cp >= child_procs; cp--) | 802 | for (cp = child_procs + (child_proc_count-1); cp >= child_procs; cp--) |
| 803 | if (!CHILD_ACTIVE (cp)) | 803 | if (!CHILD_ACTIVE (cp) && cp->procinfo.hProcess == NULL) |
| 804 | goto Initialize; | 804 | goto Initialize; |
| 805 | if (child_proc_count == MAX_CHILDREN) | 805 | if (child_proc_count == MAX_CHILDREN) |
| 806 | { | ||
| 807 | int i = 0; | ||
| 808 | child_process *dead_cp = NULL; | ||
| 809 | |||
| 810 | DebPrint (("new_child: No vacant slots, looking for dead processes\n")); | ||
| 811 | for (cp = child_procs + (child_proc_count-1); cp >= child_procs; cp--) | ||
| 812 | if (!CHILD_ACTIVE (cp) && cp->procinfo.hProcess) | ||
| 813 | { | ||
| 814 | DWORD status = 0; | ||
| 815 | |||
| 816 | if (!GetExitCodeProcess (cp->procinfo.hProcess, &status)) | ||
| 817 | { | ||
| 818 | DebPrint (("new_child.GetExitCodeProcess: error %lu for PID %lu\n", | ||
| 819 | GetLastError (), cp->procinfo.dwProcessId)); | ||
| 820 | status = STILL_ACTIVE; | ||
| 821 | } | ||
| 822 | if (status != STILL_ACTIVE | ||
| 823 | || WaitForSingleObject (cp->procinfo.hProcess, 0) == WAIT_OBJECT_0) | ||
| 824 | { | ||
| 825 | DebPrint (("new_child: Freeing slot of dead process %d, fd %d\n", | ||
| 826 | cp->procinfo.dwProcessId, cp->fd)); | ||
| 827 | CloseHandle (cp->procinfo.hProcess); | ||
| 828 | cp->procinfo.hProcess = NULL; | ||
| 829 | CloseHandle (cp->procinfo.hThread); | ||
| 830 | cp->procinfo.hThread = NULL; | ||
| 831 | /* Free up to 2 dead slots at a time, so that if we | ||
| 832 | have a lot of them, they will eventually all be | ||
| 833 | freed when the tornado ends. */ | ||
| 834 | if (i == 0) | ||
| 835 | dead_cp = cp; | ||
| 836 | else | ||
| 837 | break; | ||
| 838 | i++; | ||
| 839 | } | ||
| 840 | } | ||
| 841 | if (dead_cp) | ||
| 842 | { | ||
| 843 | cp = dead_cp; | ||
| 844 | goto Initialize; | ||
| 845 | } | ||
| 846 | } | ||
| 847 | if (child_proc_count == MAX_CHILDREN) | ||
| 806 | return NULL; | 848 | return NULL; |
| 807 | cp = &child_procs[child_proc_count++]; | 849 | cp = &child_procs[child_proc_count++]; |
| 808 | 850 | ||
| 809 | Initialize: | 851 | Initialize: |
| 852 | /* Last opportunity to avoid leaking handles before we forget them | ||
| 853 | for good. */ | ||
| 854 | if (cp->procinfo.hProcess) | ||
| 855 | CloseHandle (cp->procinfo.hProcess); | ||
| 856 | if (cp->procinfo.hThread) | ||
| 857 | CloseHandle (cp->procinfo.hThread); | ||
| 810 | memset (cp, 0, sizeof (*cp)); | 858 | memset (cp, 0, sizeof (*cp)); |
| 811 | cp->fd = -1; | 859 | cp->fd = -1; |
| 812 | cp->pid = -1; | 860 | cp->pid = -1; |
| 813 | cp->procinfo.hProcess = NULL; | 861 | cp->procinfo.hProcess = NULL; |
| 814 | cp->status = STATUS_READ_ERROR; | 862 | cp->status = STATUS_READ_ERROR; |
| 863 | cp->input_file = NULL; | ||
| 864 | cp->pending_deletion = 0; | ||
| 815 | 865 | ||
| 816 | /* use manual reset event so that select() will function properly */ | 866 | /* use manual reset event so that select() will function properly */ |
| 817 | cp->char_avail = CreateEvent (NULL, TRUE, FALSE, NULL); | 867 | cp->char_avail = CreateEvent (NULL, TRUE, FALSE, NULL); |
| @@ -857,9 +907,24 @@ delete_child (child_process *cp) | |||
| 857 | if (fd_info[i].cp == cp) | 907 | if (fd_info[i].cp == cp) |
| 858 | emacs_abort (); | 908 | emacs_abort (); |
| 859 | 909 | ||
| 860 | if (!CHILD_ACTIVE (cp)) | 910 | if (!CHILD_ACTIVE (cp) && cp->procinfo.hProcess == NULL) |
| 861 | return; | 911 | return; |
| 862 | 912 | ||
| 913 | /* Delete the child's temporary input file, if any, that is pending | ||
| 914 | deletion. */ | ||
| 915 | if (cp->input_file) | ||
| 916 | { | ||
| 917 | if (cp->pending_deletion) | ||
| 918 | { | ||
| 919 | if (unlink (cp->input_file)) | ||
| 920 | DebPrint (("delete_child.unlink (%s) failed, errno: %d\n", | ||
| 921 | cp->input_file, errno)); | ||
| 922 | cp->pending_deletion = 0; | ||
| 923 | } | ||
| 924 | xfree (cp->input_file); | ||
| 925 | cp->input_file = NULL; | ||
| 926 | } | ||
| 927 | |||
| 863 | /* reap thread if necessary */ | 928 | /* reap thread if necessary */ |
| 864 | if (cp->thrd) | 929 | if (cp->thrd) |
| 865 | { | 930 | { |
| @@ -901,7 +966,8 @@ delete_child (child_process *cp) | |||
| 901 | if (cp == child_procs + child_proc_count - 1) | 966 | if (cp == child_procs + child_proc_count - 1) |
| 902 | { | 967 | { |
| 903 | for (i = child_proc_count-1; i >= 0; i--) | 968 | for (i = child_proc_count-1; i >= 0; i--) |
| 904 | if (CHILD_ACTIVE (&child_procs[i])) | 969 | if (CHILD_ACTIVE (&child_procs[i]) |
| 970 | || child_procs[i].procinfo.hProcess != NULL) | ||
| 905 | { | 971 | { |
| 906 | child_proc_count = i + 1; | 972 | child_proc_count = i + 1; |
| 907 | break; | 973 | break; |
| @@ -918,7 +984,8 @@ find_child_pid (DWORD pid) | |||
| 918 | child_process *cp; | 984 | child_process *cp; |
| 919 | 985 | ||
| 920 | for (cp = child_procs + (child_proc_count-1); cp >= child_procs; cp--) | 986 | for (cp = child_procs + (child_proc_count-1); cp >= child_procs; cp--) |
| 921 | if (CHILD_ACTIVE (cp) && pid == cp->pid) | 987 | if ((CHILD_ACTIVE (cp) || cp->procinfo.hProcess != NULL) |
| 988 | && pid == cp->pid) | ||
| 922 | return cp; | 989 | return cp; |
| 923 | return NULL; | 990 | return NULL; |
| 924 | } | 991 | } |
| @@ -946,17 +1013,23 @@ reader_thread (void *arg) | |||
| 946 | { | 1013 | { |
| 947 | int rc; | 1014 | int rc; |
| 948 | 1015 | ||
| 949 | if (fd_info[cp->fd].flags & FILE_LISTEN) | 1016 | if (cp->fd >= 0 && fd_info[cp->fd].flags & FILE_LISTEN) |
| 950 | rc = _sys_wait_accept (cp->fd); | 1017 | rc = _sys_wait_accept (cp->fd); |
| 951 | else | 1018 | else |
| 952 | rc = _sys_read_ahead (cp->fd); | 1019 | rc = _sys_read_ahead (cp->fd); |
| 953 | 1020 | ||
| 1021 | /* Don't bother waiting for the event if we already have been | ||
| 1022 | told to exit by delete_child. */ | ||
| 1023 | if (cp->status == STATUS_READ_ERROR || !cp->char_avail) | ||
| 1024 | break; | ||
| 1025 | |||
| 954 | /* The name char_avail is a misnomer - it really just means the | 1026 | /* The name char_avail is a misnomer - it really just means the |
| 955 | read-ahead has completed, whether successfully or not. */ | 1027 | read-ahead has completed, whether successfully or not. */ |
| 956 | if (!SetEvent (cp->char_avail)) | 1028 | if (!SetEvent (cp->char_avail)) |
| 957 | { | 1029 | { |
| 958 | DebPrint (("reader_thread.SetEvent failed with %lu for fd %ld\n", | 1030 | DebPrint (("reader_thread.SetEvent(0x%x) failed with %lu for fd %ld (PID %d)\n", |
| 959 | GetLastError (), cp->fd)); | 1031 | (DWORD_PTR)cp->char_avail, GetLastError (), |
| 1032 | cp->fd, cp->pid)); | ||
| 960 | return 1; | 1033 | return 1; |
| 961 | } | 1034 | } |
| 962 | 1035 | ||
| @@ -967,6 +1040,11 @@ reader_thread (void *arg) | |||
| 967 | if (rc == STATUS_READ_FAILED) | 1040 | if (rc == STATUS_READ_FAILED) |
| 968 | break; | 1041 | break; |
| 969 | 1042 | ||
| 1043 | /* Don't bother waiting for the acknowledge if we already have | ||
| 1044 | been told to exit by delete_child. */ | ||
| 1045 | if (cp->status == STATUS_READ_ERROR || !cp->char_consumed) | ||
| 1046 | break; | ||
| 1047 | |||
| 970 | /* Wait until our input is acknowledged before reading again */ | 1048 | /* Wait until our input is acknowledged before reading again */ |
| 971 | if (WaitForSingleObject (cp->char_consumed, INFINITE) != WAIT_OBJECT_0) | 1049 | if (WaitForSingleObject (cp->char_consumed, INFINITE) != WAIT_OBJECT_0) |
| 972 | { | 1050 | { |
| @@ -974,6 +1052,10 @@ reader_thread (void *arg) | |||
| 974 | "%lu for fd %ld\n", GetLastError (), cp->fd)); | 1052 | "%lu for fd %ld\n", GetLastError (), cp->fd)); |
| 975 | break; | 1053 | break; |
| 976 | } | 1054 | } |
| 1055 | /* delete_child sets status to STATUS_READ_ERROR when it wants | ||
| 1056 | us to exit. */ | ||
| 1057 | if (cp->status == STATUS_READ_ERROR) | ||
| 1058 | break; | ||
| 977 | } | 1059 | } |
| 978 | return 0; | 1060 | return 0; |
| 979 | } | 1061 | } |
| @@ -1056,11 +1138,11 @@ create_child (char *exe, char *cmdline, char *env, int is_gui_app, | |||
| 1056 | This way the select emulator knows how to match file handles with | 1138 | This way the select emulator knows how to match file handles with |
| 1057 | entries in child_procs. */ | 1139 | entries in child_procs. */ |
| 1058 | void | 1140 | void |
| 1059 | register_child (int pid, int fd) | 1141 | register_child (pid_t pid, int fd) |
| 1060 | { | 1142 | { |
| 1061 | child_process *cp; | 1143 | child_process *cp; |
| 1062 | 1144 | ||
| 1063 | cp = find_child_pid (pid); | 1145 | cp = find_child_pid ((DWORD)pid); |
| 1064 | if (cp == NULL) | 1146 | if (cp == NULL) |
| 1065 | { | 1147 | { |
| 1066 | DebPrint (("register_child unable to find pid %lu\n", pid)); | 1148 | DebPrint (("register_child unable to find pid %lu\n", pid)); |
| @@ -1087,10 +1169,46 @@ register_child (int pid, int fd) | |||
| 1087 | fd_info[fd].cp = cp; | 1169 | fd_info[fd].cp = cp; |
| 1088 | } | 1170 | } |
| 1089 | 1171 | ||
| 1090 | /* When a process dies its pipe will break so the reader thread will | 1172 | /* Record INFILE as an input file for process PID. */ |
| 1091 | signal failure to the select emulator. | 1173 | void |
| 1092 | The select emulator then calls this routine to clean up. | 1174 | record_infile (pid_t pid, char *infile) |
| 1093 | Since the thread signaled failure we can assume it is exiting. */ | 1175 | { |
| 1176 | child_process *cp; | ||
| 1177 | |||
| 1178 | /* INFILE should never be NULL, since xstrdup would have signaled | ||
| 1179 | memory full condition in that case, see callproc.c where this | ||
| 1180 | function is called. */ | ||
| 1181 | eassert (infile); | ||
| 1182 | |||
| 1183 | cp = find_child_pid ((DWORD)pid); | ||
| 1184 | if (cp == NULL) | ||
| 1185 | { | ||
| 1186 | DebPrint (("record_infile is unable to find pid %lu\n", pid)); | ||
| 1187 | return; | ||
| 1188 | } | ||
| 1189 | |||
| 1190 | cp->input_file = infile; | ||
| 1191 | } | ||
| 1192 | |||
| 1193 | /* Mark the input file INFILE of the corresponding subprocess as | ||
| 1194 | temporary, to be deleted when the subprocess exits. */ | ||
| 1195 | void | ||
| 1196 | record_pending_deletion (char *infile) | ||
| 1197 | { | ||
| 1198 | child_process *cp; | ||
| 1199 | |||
| 1200 | eassert (infile); | ||
| 1201 | |||
| 1202 | for (cp = child_procs + (child_proc_count-1); cp >= child_procs; cp--) | ||
| 1203 | if (CHILD_ACTIVE (cp) | ||
| 1204 | && cp->input_file && xstrcasecmp (cp->input_file, infile) == 0) | ||
| 1205 | { | ||
| 1206 | cp->pending_deletion = 1; | ||
| 1207 | break; | ||
| 1208 | } | ||
| 1209 | } | ||
| 1210 | |||
| 1211 | /* Called from waitpid when a process exits. */ | ||
| 1094 | static void | 1212 | static void |
| 1095 | reap_subprocess (child_process *cp) | 1213 | reap_subprocess (child_process *cp) |
| 1096 | { | 1214 | { |
| @@ -1100,7 +1218,7 @@ reap_subprocess (child_process *cp) | |||
| 1100 | #ifdef FULL_DEBUG | 1218 | #ifdef FULL_DEBUG |
| 1101 | /* Process should have already died before we are called. */ | 1219 | /* Process should have already died before we are called. */ |
| 1102 | if (WaitForSingleObject (cp->procinfo.hProcess, 0) != WAIT_OBJECT_0) | 1220 | if (WaitForSingleObject (cp->procinfo.hProcess, 0) != WAIT_OBJECT_0) |
| 1103 | DebPrint (("reap_subprocess: child fpr fd %d has not died yet!", cp->fd)); | 1221 | DebPrint (("reap_subprocess: child for fd %d has not died yet!", cp->fd)); |
| 1104 | #endif | 1222 | #endif |
| 1105 | CloseHandle (cp->procinfo.hProcess); | 1223 | CloseHandle (cp->procinfo.hProcess); |
| 1106 | cp->procinfo.hProcess = NULL; | 1224 | cp->procinfo.hProcess = NULL; |
| @@ -1108,11 +1226,11 @@ reap_subprocess (child_process *cp) | |||
| 1108 | cp->procinfo.hThread = NULL; | 1226 | cp->procinfo.hThread = NULL; |
| 1109 | } | 1227 | } |
| 1110 | 1228 | ||
| 1111 | /* For asynchronous children, the child_proc resources will be freed | 1229 | /* If cp->fd was not closed yet, we might be still reading the |
| 1112 | when the last pipe read descriptor is closed; for synchronous | 1230 | process output, so don't free its resources just yet. The call |
| 1113 | children, we must explicitly free the resources now because | 1231 | to delete_child on behalf of this subprocess will be made by |
| 1114 | register_child has not been called. */ | 1232 | sys_read when the subprocess output is fully read. */ |
| 1115 | if (cp->fd == -1) | 1233 | if (cp->fd < 0) |
| 1116 | delete_child (cp); | 1234 | delete_child (cp); |
| 1117 | } | 1235 | } |
| 1118 | 1236 | ||
| @@ -1220,13 +1338,22 @@ waitpid (pid_t pid, int *status, int options) | |||
| 1220 | { | 1338 | { |
| 1221 | QUIT; | 1339 | QUIT; |
| 1222 | active = WaitForMultipleObjects (nh, wait_hnd, FALSE, timeout_ms); | 1340 | active = WaitForMultipleObjects (nh, wait_hnd, FALSE, timeout_ms); |
| 1223 | } while (active == WAIT_TIMEOUT); | 1341 | } while (active == WAIT_TIMEOUT && !dont_wait); |
| 1224 | 1342 | ||
| 1225 | if (active == WAIT_FAILED) | 1343 | if (active == WAIT_FAILED) |
| 1226 | { | 1344 | { |
| 1227 | errno = EBADF; | 1345 | errno = EBADF; |
| 1228 | return -1; | 1346 | return -1; |
| 1229 | } | 1347 | } |
| 1348 | else if (active == WAIT_TIMEOUT && dont_wait) | ||
| 1349 | { | ||
| 1350 | /* PID specifies our subprocess, but it didn't exit yet, so its | ||
| 1351 | status is not yet available. */ | ||
| 1352 | #ifdef FULL_DEBUG | ||
| 1353 | DebPrint (("Wait: PID %d not reap yet\n", cp->pid)); | ||
| 1354 | #endif | ||
| 1355 | return 0; | ||
| 1356 | } | ||
| 1230 | else if (active >= WAIT_OBJECT_0 | 1357 | else if (active >= WAIT_OBJECT_0 |
| 1231 | && active < WAIT_OBJECT_0+MAXIMUM_WAIT_OBJECTS) | 1358 | && active < WAIT_OBJECT_0+MAXIMUM_WAIT_OBJECTS) |
| 1232 | { | 1359 | { |
| @@ -1274,33 +1401,7 @@ waitpid (pid_t pid, int *status, int options) | |||
| 1274 | #endif | 1401 | #endif |
| 1275 | 1402 | ||
| 1276 | if (status) | 1403 | if (status) |
| 1277 | { | 1404 | *status = retval; |
| 1278 | *status = retval; | ||
| 1279 | } | ||
| 1280 | else if (synch_process_alive) | ||
| 1281 | { | ||
| 1282 | synch_process_alive = 0; | ||
| 1283 | |||
| 1284 | /* Report the status of the synchronous process. */ | ||
| 1285 | if (WIFEXITED (retval)) | ||
| 1286 | synch_process_retcode = WEXITSTATUS (retval); | ||
| 1287 | else if (WIFSIGNALED (retval)) | ||
| 1288 | { | ||
| 1289 | int code = WTERMSIG (retval); | ||
| 1290 | const char *signame; | ||
| 1291 | |||
| 1292 | synchronize_system_messages_locale (); | ||
| 1293 | signame = strsignal (code); | ||
| 1294 | |||
| 1295 | if (signame == 0) | ||
| 1296 | signame = "unknown"; | ||
| 1297 | |||
| 1298 | synch_process_death = signame; | ||
| 1299 | } | ||
| 1300 | |||
| 1301 | reap_subprocess (cp); | ||
| 1302 | } | ||
| 1303 | |||
| 1304 | reap_subprocess (cp); | 1405 | reap_subprocess (cp); |
| 1305 | 1406 | ||
| 1306 | return pid; | 1407 | return pid; |
| @@ -1485,11 +1586,10 @@ sys_spawnve (int mode, char *cmdname, char **argv, char **envp) | |||
| 1485 | Lisp_Object program, full; | 1586 | Lisp_Object program, full; |
| 1486 | char *cmdline, *env, *parg, **targ; | 1587 | char *cmdline, *env, *parg, **targ; |
| 1487 | int arglen, numenv; | 1588 | int arglen, numenv; |
| 1488 | int pid; | 1589 | pid_t pid; |
| 1489 | child_process *cp; | 1590 | child_process *cp; |
| 1490 | int is_dos_app, is_cygnus_app, is_gui_app; | 1591 | int is_dos_app, is_cygnus_app, is_gui_app; |
| 1491 | int do_quoting = 0; | 1592 | int do_quoting = 0; |
| 1492 | char escape_char; | ||
| 1493 | /* We pass our process ID to our children by setting up an environment | 1593 | /* We pass our process ID to our children by setting up an environment |
| 1494 | variable in their environment. */ | 1594 | variable in their environment. */ |
| 1495 | char ppid_env_var_buffer[64]; | 1595 | char ppid_env_var_buffer[64]; |
| @@ -1502,6 +1602,8 @@ sys_spawnve (int mode, char *cmdname, char **argv, char **envp) | |||
| 1502 | Some extra whitespace characters need quoting in Cygwin programs, | 1602 | Some extra whitespace characters need quoting in Cygwin programs, |
| 1503 | so this list is conditionally modified below. */ | 1603 | so this list is conditionally modified below. */ |
| 1504 | char *sepchars = " \t*?"; | 1604 | char *sepchars = " \t*?"; |
| 1605 | /* This is for native w32 apps; modified below for Cygwin apps. */ | ||
| 1606 | char escape_char = '\\'; | ||
| 1505 | 1607 | ||
| 1506 | /* We don't care about the other modes */ | 1608 | /* We don't care about the other modes */ |
| 1507 | if (mode != _P_NOWAIT) | 1609 | if (mode != _P_NOWAIT) |
| @@ -1874,7 +1976,7 @@ sys_select (int nfds, SELECT_TYPE *rfds, SELECT_TYPE *wfds, SELECT_TYPE *efds, | |||
| 1874 | } | 1976 | } |
| 1875 | else | 1977 | else |
| 1876 | { | 1978 | { |
| 1877 | /* Child process and socket input */ | 1979 | /* Child process and socket/comm port input. */ |
| 1878 | cp = fd_info[i].cp; | 1980 | cp = fd_info[i].cp; |
| 1879 | if (cp) | 1981 | if (cp) |
| 1880 | { | 1982 | { |
| @@ -1887,7 +1989,7 @@ sys_select (int nfds, SELECT_TYPE *rfds, SELECT_TYPE *wfds, SELECT_TYPE *efds, | |||
| 1887 | /* Wake up the reader thread for this process */ | 1989 | /* Wake up the reader thread for this process */ |
| 1888 | cp->status = STATUS_READ_READY; | 1990 | cp->status = STATUS_READ_READY; |
| 1889 | if (!SetEvent (cp->char_consumed)) | 1991 | if (!SetEvent (cp->char_consumed)) |
| 1890 | DebPrint (("nt_select.SetEvent failed with " | 1992 | DebPrint (("sys_select.SetEvent failed with " |
| 1891 | "%lu for fd %ld\n", GetLastError (), i)); | 1993 | "%lu for fd %ld\n", GetLastError (), i)); |
| 1892 | } | 1994 | } |
| 1893 | 1995 | ||
| @@ -1955,7 +2057,7 @@ count_children: | |||
| 1955 | /* Some child_procs might be sockets; ignore them. Also some | 2057 | /* Some child_procs might be sockets; ignore them. Also some |
| 1956 | children may have died already, but we haven't finished reading | 2058 | children may have died already, but we haven't finished reading |
| 1957 | the process output; ignore them too. */ | 2059 | the process output; ignore them too. */ |
| 1958 | if (CHILD_ACTIVE (cp) && cp->procinfo.hProcess | 2060 | if ((CHILD_ACTIVE (cp) && cp->procinfo.hProcess) |
| 1959 | && (cp->fd < 0 | 2061 | && (cp->fd < 0 |
| 1960 | || (fd_info[cp->fd].flags & FILE_SEND_SIGCHLD) == 0 | 2062 | || (fd_info[cp->fd].flags & FILE_SEND_SIGCHLD) == 0 |
| 1961 | || (fd_info[cp->fd].flags & FILE_AT_EOF) != 0) | 2063 | || (fd_info[cp->fd].flags & FILE_AT_EOF) != 0) |
| @@ -2035,7 +2137,24 @@ count_children: | |||
| 2035 | (*) Note that MsgWaitForMultipleObjects above is an | 2137 | (*) Note that MsgWaitForMultipleObjects above is an |
| 2036 | internal dispatch point for messages that are sent to | 2138 | internal dispatch point for messages that are sent to |
| 2037 | windows created by this thread. */ | 2139 | windows created by this thread. */ |
| 2038 | drain_message_queue (); | 2140 | if (drain_message_queue () |
| 2141 | /* If drain_message_queue returns non-zero, that means | ||
| 2142 | we received a WM_EMACS_FILENOTIFY message. If this | ||
| 2143 | is a TTY frame, we must signal the caller that keyboard | ||
| 2144 | input is available, so that w32_console_read_socket | ||
| 2145 | will be called to pick up the notifications. If we | ||
| 2146 | don't do that, file notifications will only work when | ||
| 2147 | the Emacs TTY frame has focus. */ | ||
| 2148 | && FRAME_TERMCAP_P (SELECTED_FRAME ()) | ||
| 2149 | /* they asked for stdin reads */ | ||
| 2150 | && FD_ISSET (0, &orfds) | ||
| 2151 | /* the stdin handle is valid */ | ||
| 2152 | && keyboard_handle) | ||
| 2153 | { | ||
| 2154 | FD_SET (0, rfds); | ||
| 2155 | if (nr == 0) | ||
| 2156 | nr = 1; | ||
| 2157 | } | ||
| 2039 | } | 2158 | } |
| 2040 | else if (active >= nh) | 2159 | else if (active >= nh) |
| 2041 | { | 2160 | { |
| @@ -2132,20 +2251,54 @@ find_child_console (HWND hwnd, LPARAM arg) | |||
| 2132 | 2251 | ||
| 2133 | /* Emulate 'kill', but only for other processes. */ | 2252 | /* Emulate 'kill', but only for other processes. */ |
| 2134 | int | 2253 | int |
| 2135 | sys_kill (int pid, int sig) | 2254 | sys_kill (pid_t pid, int sig) |
| 2136 | { | 2255 | { |
| 2137 | child_process *cp; | 2256 | child_process *cp; |
| 2138 | HANDLE proc_hand; | 2257 | HANDLE proc_hand; |
| 2139 | int need_to_free = 0; | 2258 | int need_to_free = 0; |
| 2140 | int rc = 0; | 2259 | int rc = 0; |
| 2141 | 2260 | ||
| 2261 | /* Each process is in its own process group. */ | ||
| 2262 | if (pid < 0) | ||
| 2263 | pid = -pid; | ||
| 2264 | |||
| 2142 | /* Only handle signals that will result in the process dying */ | 2265 | /* Only handle signals that will result in the process dying */ |
| 2143 | if (sig != SIGINT && sig != SIGKILL && sig != SIGQUIT && sig != SIGHUP) | 2266 | if (sig != 0 |
| 2267 | && sig != SIGINT && sig != SIGKILL && sig != SIGQUIT && sig != SIGHUP) | ||
| 2144 | { | 2268 | { |
| 2145 | errno = EINVAL; | 2269 | errno = EINVAL; |
| 2146 | return -1; | 2270 | return -1; |
| 2147 | } | 2271 | } |
| 2148 | 2272 | ||
| 2273 | if (sig == 0) | ||
| 2274 | { | ||
| 2275 | /* It will take _some_ time before PID 4 or less on Windows will | ||
| 2276 | be Emacs... */ | ||
| 2277 | if (pid <= 4) | ||
| 2278 | { | ||
| 2279 | errno = EPERM; | ||
| 2280 | return -1; | ||
| 2281 | } | ||
| 2282 | proc_hand = OpenProcess (PROCESS_QUERY_INFORMATION, 0, pid); | ||
| 2283 | if (proc_hand == NULL) | ||
| 2284 | { | ||
| 2285 | DWORD err = GetLastError (); | ||
| 2286 | |||
| 2287 | switch (err) | ||
| 2288 | { | ||
| 2289 | case ERROR_ACCESS_DENIED: /* existing process, but access denied */ | ||
| 2290 | errno = EPERM; | ||
| 2291 | return -1; | ||
| 2292 | case ERROR_INVALID_PARAMETER: /* process PID does not exist */ | ||
| 2293 | errno = ESRCH; | ||
| 2294 | return -1; | ||
| 2295 | } | ||
| 2296 | } | ||
| 2297 | else | ||
| 2298 | CloseHandle (proc_hand); | ||
| 2299 | return 0; | ||
| 2300 | } | ||
| 2301 | |||
| 2149 | cp = find_child_pid (pid); | 2302 | cp = find_child_pid (pid); |
| 2150 | if (cp == NULL) | 2303 | if (cp == NULL) |
| 2151 | { | 2304 | { |
| @@ -2484,8 +2637,9 @@ All path elements in FILENAME are converted to their short names. */) | |||
| 2484 | if (GetShortPathName (SDATA (ENCODE_FILE (filename)), shortname, MAX_PATH) == 0) | 2637 | if (GetShortPathName (SDATA (ENCODE_FILE (filename)), shortname, MAX_PATH) == 0) |
| 2485 | return Qnil; | 2638 | return Qnil; |
| 2486 | 2639 | ||
| 2487 | dostounix_filename (shortname); | 2640 | dostounix_filename (shortname, 0); |
| 2488 | 2641 | ||
| 2642 | /* No need to DECODE_FILE, because 8.3 names are pure ASCII. */ | ||
| 2489 | return build_string (shortname); | 2643 | return build_string (shortname); |
| 2490 | } | 2644 | } |
| 2491 | 2645 | ||
| @@ -2512,7 +2666,7 @@ All path elements in FILENAME are converted to their long names. */) | |||
| 2512 | if (!w32_get_long_filename (SDATA (ENCODE_FILE (filename)), longname, MAX_PATH)) | 2666 | if (!w32_get_long_filename (SDATA (ENCODE_FILE (filename)), longname, MAX_PATH)) |
| 2513 | return Qnil; | 2667 | return Qnil; |
| 2514 | 2668 | ||
| 2515 | dostounix_filename (longname); | 2669 | dostounix_filename (longname, 0); |
| 2516 | 2670 | ||
| 2517 | /* If we were passed only a drive, make sure that a slash is not appended | 2671 | /* If we were passed only a drive, make sure that a slash is not appended |
| 2518 | for consistency with directories. Allow for drive mapping via SUBST | 2672 | for consistency with directories. Allow for drive mapping via SUBST |