Mercurial > emacs
annotate src/w32proc.c @ 22786:b1418bc30131 libc-980720
(R4000:UNIX_SV:*:*): Recognize this for Mips machines.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sun, 19 Jul 1998 22:11:47 +0000 |
parents | e509b80a17a2 |
children | b2480e274f42 |
rev | line source |
---|---|
16884
36babc489b0c
Change all uses of win95, winnt, and win32
Geoff Voelker <voelker@cs.washington.edu>
parents:
16826
diff
changeset
|
1 /* Process support for GNU Emacs on the Microsoft W32 API. |
11388
96fa39ad9403
(win32_wait): Reap synchronous subprocesses, and place
Karl Heuer <kwzh@gnu.org>
parents:
9907
diff
changeset
|
2 Copyright (C) 1992, 1995 Free Software Foundation, Inc. |
9907 | 3 |
14186
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
14036
diff
changeset
|
4 This file is part of GNU Emacs. |
9907 | 5 |
14186
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
14036
diff
changeset
|
6 GNU Emacs is free software; you can redistribute it and/or modify |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
14036
diff
changeset
|
7 it under the terms of the GNU General Public License as published by |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
14036
diff
changeset
|
8 the Free Software Foundation; either version 2, or (at your option) |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
14036
diff
changeset
|
9 any later version. |
9907 | 10 |
14186
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
14036
diff
changeset
|
11 GNU Emacs is distributed in the hope that it will be useful, |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
14036
diff
changeset
|
12 but WITHOUT ANY WARRANTY; without even the implied warranty of |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
14036
diff
changeset
|
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
14036
diff
changeset
|
14 GNU General Public License for more details. |
9907 | 15 |
14186
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
14036
diff
changeset
|
16 You should have received a copy of the GNU General Public License |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
14036
diff
changeset
|
17 along with GNU Emacs; see the file COPYING. If not, write to |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
14036
diff
changeset
|
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
14036
diff
changeset
|
19 Boston, MA 02111-1307, USA. |
9907 | 20 |
21 Drew Bliss Oct 14, 1993 | |
22 Adapted from alarm.c by Tim Fleehart | |
23 */ | |
24 | |
25 #include <stdio.h> | |
26 #include <stdlib.h> | |
27 #include <errno.h> | |
28 #include <io.h> | |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
29 #include <fcntl.h> |
9907 | 30 #include <signal.h> |
31 | |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
32 /* must include CRT headers *before* config.h */ |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
33 #include "config.h" |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
34 #undef signal |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
35 #undef wait |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
36 #undef spawnve |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
37 #undef select |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
38 #undef kill |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
39 |
9907 | 40 #include <windows.h> |
41 | |
42 #include "lisp.h" | |
16593
4ed80eda6fac
Use new names for w32 files
Geoff Voelker <voelker@cs.washington.edu>
parents:
16588
diff
changeset
|
43 #include "w32.h" |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
44 #include "w32heap.h" |
9907 | 45 #include "systime.h" |
13931
c80fb27c183b
(win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents:
13425
diff
changeset
|
46 #include "syswait.h" |
c80fb27c183b
(win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents:
13425
diff
changeset
|
47 #include "process.h" |
21613
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
48 #include "w32term.h" |
13931
c80fb27c183b
(win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents:
13425
diff
changeset
|
49 |
15201
43551ec4b69d
(Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
15145
diff
changeset
|
50 /* Control whether spawnve quotes arguments as necessary to ensure |
43551ec4b69d
(Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
15145
diff
changeset
|
51 correct parsing by child process. Because not all uses of spawnve |
43551ec4b69d
(Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
15145
diff
changeset
|
52 are careful about constructing argv arrays, we make this behaviour |
43551ec4b69d
(Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
15145
diff
changeset
|
53 conditional (off by default). */ |
16588
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16000
diff
changeset
|
54 Lisp_Object Vw32_quote_process_args; |
15201
43551ec4b69d
(Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
15145
diff
changeset
|
55 |
16000
b5ecd5022991
(Vwin32_start_process_show_window): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
15419
diff
changeset
|
56 /* Control whether create_child causes the process' window to be |
b5ecd5022991
(Vwin32_start_process_show_window): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
15419
diff
changeset
|
57 hidden. The default is nil. */ |
16588
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16000
diff
changeset
|
58 Lisp_Object Vw32_start_process_show_window; |
16000
b5ecd5022991
(Vwin32_start_process_show_window): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
15419
diff
changeset
|
59 |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
60 /* Control whether create_child causes the process to inherit Emacs' |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
61 console window, or be given a new one of its own. The default is |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
62 nil, to allow multiple DOS programs to run on Win95. Having separate |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
63 consoles also allows Emacs to cleanly terminate process groups. */ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
64 Lisp_Object Vw32_start_process_share_console; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
65 |
15247
874a66251747
(Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents:
15201
diff
changeset
|
66 /* Time to sleep before reading from a subprocess output pipe - this |
874a66251747
(Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents:
15201
diff
changeset
|
67 avoids the inefficiency of frequently reading small amounts of data. |
874a66251747
(Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents:
15201
diff
changeset
|
68 This is primarily necessary for handling DOS processes on Windows 95, |
16884
36babc489b0c
Change all uses of win95, winnt, and win32
Geoff Voelker <voelker@cs.washington.edu>
parents:
16826
diff
changeset
|
69 but is useful for W32 processes on both Windows 95 and NT as well. */ |
16588
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16000
diff
changeset
|
70 Lisp_Object Vw32_pipe_read_delay; |
15247
874a66251747
(Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents:
15201
diff
changeset
|
71 |
15325
5c8e4ef3137c
(Vwin32_downcase_file_names): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
15247
diff
changeset
|
72 /* Control conversion of upper case file names to lower case. |
5c8e4ef3137c
(Vwin32_downcase_file_names): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
15247
diff
changeset
|
73 nil means no, t means yes. */ |
16588
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16000
diff
changeset
|
74 Lisp_Object Vw32_downcase_file_names; |
15325
5c8e4ef3137c
(Vwin32_downcase_file_names): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
15247
diff
changeset
|
75 |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
76 /* Control whether stat() attempts to generate fake but hopefully |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
77 "accurate" inode values, by hashing the absolute truenames of files. |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
78 This should detect aliasing between long and short names, but still |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
79 allows the possibility of hash collisions. */ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
80 Lisp_Object Vw32_generate_fake_inodes; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
81 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
82 /* Control whether stat() attempts to determine file type and link count |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
83 exactly, at the expense of slower operation. Since true hard links |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
84 are supported on NTFS volumes, this is only relevant on NT. */ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
85 Lisp_Object Vw32_get_true_file_attributes; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
86 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
87 Lisp_Object Qhigh, Qlow; |
15247
874a66251747
(Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents:
15201
diff
changeset
|
88 |
13931
c80fb27c183b
(win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents:
13425
diff
changeset
|
89 #ifndef SYS_SIGLIST_DECLARED |
c80fb27c183b
(win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents:
13425
diff
changeset
|
90 extern char *sys_siglist[]; |
c80fb27c183b
(win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents:
13425
diff
changeset
|
91 #endif |
9907 | 92 |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
93 #ifdef EMACSDEBUG |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
94 void _DebPrint (const char *fmt, ...) |
9907 | 95 { |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
96 char buf[1024]; |
9907 | 97 va_list args; |
98 | |
99 va_start (args, fmt); | |
100 vsprintf (buf, fmt, args); | |
101 va_end (args); | |
102 OutputDebugString (buf); | |
103 } | |
104 #endif | |
105 | |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
106 typedef void (_CALLBACK_ *signal_handler)(int); |
9907 | 107 |
108 /* Signal handlers...SIG_DFL == 0 so this is initialized correctly. */ | |
109 static signal_handler sig_handlers[NSIG]; | |
110 | |
111 /* Fake signal implementation to record the SIGCHLD handler. */ | |
112 signal_handler | |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
113 sys_signal (int sig, signal_handler handler) |
9907 | 114 { |
115 signal_handler old; | |
116 | |
117 if (sig != SIGCHLD) | |
118 { | |
119 errno = EINVAL; | |
120 return SIG_ERR; | |
121 } | |
122 old = sig_handlers[sig]; | |
123 sig_handlers[sig] = handler; | |
124 return old; | |
125 } | |
126 | |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
127 /* Defined in <process.h> which conflicts with the local copy */ |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
128 #define _P_NOWAIT 1 |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
129 |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
130 /* Child process management list. */ |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
131 int child_proc_count = 0; |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
132 child_process child_procs[ MAX_CHILDREN ]; |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
133 child_process *dead_child = NULL; |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
134 |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
135 DWORD WINAPI reader_thread (void *arg); |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
136 |
9907 | 137 /* Find an unused process slot. */ |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
138 child_process * |
9907 | 139 new_child (void) |
140 { | |
141 child_process *cp; | |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
142 DWORD id; |
9907 | 143 |
144 for (cp = child_procs+(child_proc_count-1); cp >= child_procs; cp--) | |
145 if (!CHILD_ACTIVE (cp)) | |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
146 goto Initialise; |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
147 if (child_proc_count == MAX_CHILDREN) |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
148 return NULL; |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
149 cp = &child_procs[child_proc_count++]; |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
150 |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
151 Initialise: |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
152 memset (cp, 0, sizeof(*cp)); |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
153 cp->fd = -1; |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
154 cp->pid = -1; |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
155 cp->procinfo.hProcess = NULL; |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
156 cp->status = STATUS_READ_ERROR; |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
157 |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
158 /* use manual reset event so that select() will function properly */ |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
159 cp->char_avail = CreateEvent (NULL, TRUE, FALSE, NULL); |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
160 if (cp->char_avail) |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
161 { |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
162 cp->char_consumed = CreateEvent (NULL, FALSE, FALSE, NULL); |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
163 if (cp->char_consumed) |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
164 { |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
165 cp->thrd = CreateThread (NULL, 1024, reader_thread, cp, 0, &id); |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
166 if (cp->thrd) |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
167 return cp; |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
168 } |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
169 } |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
170 delete_child (cp); |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
171 return NULL; |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
172 } |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
173 |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
174 void |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
175 delete_child (child_process *cp) |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
176 { |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
177 int i; |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
178 |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
179 /* Should not be deleting a child that is still needed. */ |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
180 for (i = 0; i < MAXDESC; i++) |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
181 if (fd_info[i].cp == cp) |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
182 abort (); |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
183 |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
184 if (!CHILD_ACTIVE (cp)) |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
185 return; |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
186 |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
187 /* reap thread if necessary */ |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
188 if (cp->thrd) |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
189 { |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
190 DWORD rc; |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
191 |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
192 if (GetExitCodeThread (cp->thrd, &rc) && rc == STILL_ACTIVE) |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
193 { |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
194 /* let the thread exit cleanly if possible */ |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
195 cp->status = STATUS_READ_ERROR; |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
196 SetEvent (cp->char_consumed); |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
197 if (WaitForSingleObject (cp->thrd, 1000) != WAIT_OBJECT_0) |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
198 { |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
199 DebPrint (("delete_child.WaitForSingleObject (thread) failed " |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
200 "with %lu for fd %ld\n", GetLastError (), cp->fd)); |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
201 TerminateThread (cp->thrd, 0); |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
202 } |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
203 } |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
204 CloseHandle (cp->thrd); |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
205 cp->thrd = NULL; |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
206 } |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
207 if (cp->char_avail) |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
208 { |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
209 CloseHandle (cp->char_avail); |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
210 cp->char_avail = NULL; |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
211 } |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
212 if (cp->char_consumed) |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
213 { |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
214 CloseHandle (cp->char_consumed); |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
215 cp->char_consumed = NULL; |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
216 } |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
217 |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
218 /* update child_proc_count (highest numbered slot in use plus one) */ |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
219 if (cp == child_procs + child_proc_count - 1) |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
220 { |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
221 for (i = child_proc_count-1; i >= 0; i--) |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
222 if (CHILD_ACTIVE (&child_procs[i])) |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
223 { |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
224 child_proc_count = i + 1; |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
225 break; |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
226 } |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
227 } |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
228 if (i < 0) |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
229 child_proc_count = 0; |
9907 | 230 } |
231 | |
232 /* Find a child by pid. */ | |
233 static child_process * | |
234 find_child_pid (DWORD pid) | |
235 { | |
236 child_process *cp; | |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
237 |
9907 | 238 for (cp = child_procs+(child_proc_count-1); cp >= child_procs; cp--) |
239 if (CHILD_ACTIVE (cp) && pid == cp->pid) | |
240 return cp; | |
241 return NULL; | |
242 } | |
243 | |
244 | |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
245 /* Thread proc for child process and socket reader threads. Each thread |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
246 is normally blocked until woken by select() to check for input by |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
247 reading one char. When the read completes, char_avail is signalled |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
248 to wake up the select emulator and the thread blocks itself again. */ |
9907 | 249 DWORD WINAPI |
250 reader_thread (void *arg) | |
251 { | |
252 child_process *cp; | |
253 | |
254 /* Our identity */ | |
255 cp = (child_process *)arg; | |
256 | |
257 /* We have to wait for the go-ahead before we can start */ | |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
258 if (cp == NULL |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
259 || WaitForSingleObject (cp->char_consumed, INFINITE) != WAIT_OBJECT_0) |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
260 return 1; |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
261 |
9907 | 262 for (;;) |
263 { | |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
264 int rc; |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
265 |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
266 rc = _sys_read_ahead (cp->fd); |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
267 |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
268 /* The name char_avail is a misnomer - it really just means the |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
269 read-ahead has completed, whether successfully or not. */ |
9907 | 270 if (!SetEvent (cp->char_avail)) |
271 { | |
272 DebPrint (("reader_thread.SetEvent failed with %lu for fd %ld\n", | |
273 GetLastError (), cp->fd)); | |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
274 return 1; |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
275 } |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
276 |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
277 if (rc == STATUS_READ_ERROR) |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
278 return 1; |
9907 | 279 |
280 /* If the read died, the child has died so let the thread die */ | |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
281 if (rc == STATUS_READ_FAILED) |
9907 | 282 break; |
283 | |
284 /* Wait until our input is acknowledged before reading again */ | |
285 if (WaitForSingleObject (cp->char_consumed, INFINITE) != WAIT_OBJECT_0) | |
286 { | |
287 DebPrint (("reader_thread.WaitForSingleObject failed with " | |
288 "%lu for fd %ld\n", GetLastError (), cp->fd)); | |
289 break; | |
290 } | |
291 } | |
292 return 0; | |
293 } | |
294 | |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
295 /* To avoid Emacs changing directory, we just record here the directory |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
296 the new process should start in. This is set just before calling |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
297 sys_spawnve, and is not generally valid at any other time. */ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
298 static char * process_dir; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
299 |
9907 | 300 static BOOL |
301 create_child (char *exe, char *cmdline, char *env, | |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
302 int * pPid, child_process *cp) |
9907 | 303 { |
304 STARTUPINFO start; | |
305 SECURITY_ATTRIBUTES sec_attrs; | |
306 SECURITY_DESCRIPTOR sec_desc; | |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
307 char dir[ MAXPATHLEN ]; |
9907 | 308 |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
309 if (cp == NULL) abort (); |
9907 | 310 |
311 memset (&start, 0, sizeof (start)); | |
312 start.cb = sizeof (start); | |
313 | |
13425
b6eacb7da9f6
[HAVE_NTGUI] (create_child): Pass handles to children.
Geoff Voelker <voelker@cs.washington.edu>
parents:
12325
diff
changeset
|
314 #ifdef HAVE_NTGUI |
16588
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16000
diff
changeset
|
315 if (NILP (Vw32_start_process_show_window)) |
16000
b5ecd5022991
(Vwin32_start_process_show_window): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
15419
diff
changeset
|
316 start.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW; |
b5ecd5022991
(Vwin32_start_process_show_window): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
15419
diff
changeset
|
317 else |
b5ecd5022991
(Vwin32_start_process_show_window): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
15419
diff
changeset
|
318 start.dwFlags = STARTF_USESTDHANDLES; |
13425
b6eacb7da9f6
[HAVE_NTGUI] (create_child): Pass handles to children.
Geoff Voelker <voelker@cs.washington.edu>
parents:
12325
diff
changeset
|
319 start.wShowWindow = SW_HIDE; |
b6eacb7da9f6
[HAVE_NTGUI] (create_child): Pass handles to children.
Geoff Voelker <voelker@cs.washington.edu>
parents:
12325
diff
changeset
|
320 |
b6eacb7da9f6
[HAVE_NTGUI] (create_child): Pass handles to children.
Geoff Voelker <voelker@cs.washington.edu>
parents:
12325
diff
changeset
|
321 start.hStdInput = GetStdHandle (STD_INPUT_HANDLE); |
b6eacb7da9f6
[HAVE_NTGUI] (create_child): Pass handles to children.
Geoff Voelker <voelker@cs.washington.edu>
parents:
12325
diff
changeset
|
322 start.hStdOutput = GetStdHandle (STD_OUTPUT_HANDLE); |
b6eacb7da9f6
[HAVE_NTGUI] (create_child): Pass handles to children.
Geoff Voelker <voelker@cs.washington.edu>
parents:
12325
diff
changeset
|
323 start.hStdError = GetStdHandle (STD_ERROR_HANDLE); |
b6eacb7da9f6
[HAVE_NTGUI] (create_child): Pass handles to children.
Geoff Voelker <voelker@cs.washington.edu>
parents:
12325
diff
changeset
|
324 #endif /* HAVE_NTGUI */ |
b6eacb7da9f6
[HAVE_NTGUI] (create_child): Pass handles to children.
Geoff Voelker <voelker@cs.washington.edu>
parents:
12325
diff
changeset
|
325 |
9907 | 326 /* Explicitly specify no security */ |
327 if (!InitializeSecurityDescriptor (&sec_desc, SECURITY_DESCRIPTOR_REVISION)) | |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
328 goto EH_Fail; |
9907 | 329 if (!SetSecurityDescriptorDacl (&sec_desc, TRUE, NULL, FALSE)) |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
330 goto EH_Fail; |
9907 | 331 sec_attrs.nLength = sizeof (sec_attrs); |
332 sec_attrs.lpSecurityDescriptor = &sec_desc; | |
333 sec_attrs.bInheritHandle = FALSE; | |
334 | |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
335 strcpy (dir, process_dir); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
336 unixtodos_filename (dir); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
337 |
9907 | 338 if (!CreateProcess (exe, cmdline, &sec_attrs, NULL, TRUE, |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
339 (!NILP (Vw32_start_process_share_console) |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
340 ? CREATE_NEW_PROCESS_GROUP |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
341 : CREATE_NEW_CONSOLE), |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
342 env, dir, |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
343 &start, &cp->procinfo)) |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
344 goto EH_Fail; |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
345 |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
346 cp->pid = (int) cp->procinfo.dwProcessId; |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
347 |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
348 /* Hack for Windows 95, which assigns large (ie negative) pids */ |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
349 if (cp->pid < 0) |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
350 cp->pid = -cp->pid; |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
351 |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
352 /* pid must fit in a Lisp_Int */ |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
353 cp->pid = (cp->pid & VALMASK); |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
354 |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
355 *pPid = cp->pid; |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
356 |
9907 | 357 return TRUE; |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
358 |
9907 | 359 EH_Fail: |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
360 DebPrint (("create_child.CreateProcess failed: %ld\n", GetLastError());); |
9907 | 361 return FALSE; |
362 } | |
363 | |
364 /* create_child doesn't know what emacs' file handle will be for waiting | |
365 on output from the child, so we need to make this additional call | |
366 to register the handle with the process | |
367 This way the select emulator knows how to match file handles with | |
368 entries in child_procs. */ | |
369 void | |
370 register_child (int pid, int fd) | |
371 { | |
372 child_process *cp; | |
373 | |
374 cp = find_child_pid (pid); | |
375 if (cp == NULL) | |
376 { | |
377 DebPrint (("register_child unable to find pid %lu\n", pid)); | |
378 return; | |
379 } | |
380 | |
381 #ifdef FULL_DEBUG | |
382 DebPrint (("register_child registered fd %d with pid %lu\n", fd, pid)); | |
383 #endif | |
384 | |
385 cp->fd = fd; | |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
386 |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
387 /* thread is initially blocked until select is called; set status so |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
388 that select will release thread */ |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
389 cp->status = STATUS_READ_ACKNOWLEDGED; |
9907 | 390 |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
391 /* attach child_process to fd_info */ |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
392 if (fd_info[fd].cp != NULL) |
9907 | 393 { |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
394 DebPrint (("register_child: fd_info[%d] apparently in use!\n", fd)); |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
395 abort (); |
9907 | 396 } |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
397 |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
398 fd_info[fd].cp = cp; |
9907 | 399 } |
400 | |
401 /* When a process dies its pipe will break so the reader thread will | |
402 signal failure to the select emulator. | |
403 The select emulator then calls this routine to clean up. | |
404 Since the thread signaled failure we can assume it is exiting. */ | |
405 static void | |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
406 reap_subprocess (child_process *cp) |
9907 | 407 { |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
408 if (cp->procinfo.hProcess) |
9907 | 409 { |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
410 /* Reap the process */ |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
411 #ifdef FULL_DEBUG |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
412 /* Process should have already died before we are called. */ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
413 if (WaitForSingleObject (cp->procinfo.hProcess, 0) != WAIT_OBJECT_0) |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
414 DebPrint (("reap_subprocess: child fpr fd %d has not died yet!", cp->fd)); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
415 #endif |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
416 CloseHandle (cp->procinfo.hProcess); |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
417 cp->procinfo.hProcess = NULL; |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
418 CloseHandle (cp->procinfo.hThread); |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
419 cp->procinfo.hThread = NULL; |
9907 | 420 } |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
421 |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
422 /* For asynchronous children, the child_proc resources will be freed |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
423 when the last pipe read descriptor is closed; for synchronous |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
424 children, we must explicitly free the resources now because |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
425 register_child has not been called. */ |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
426 if (cp->fd == -1) |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
427 delete_child (cp); |
9907 | 428 } |
429 | |
430 /* Wait for any of our existing child processes to die | |
431 When it does, close its handle | |
432 Return the pid and fill in the status if non-NULL. */ | |
11388
96fa39ad9403
(win32_wait): Reap synchronous subprocesses, and place
Karl Heuer <kwzh@gnu.org>
parents:
9907
diff
changeset
|
433 |
9907 | 434 int |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
435 sys_wait (int *status) |
9907 | 436 { |
437 DWORD active, retval; | |
438 int nh; | |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
439 int pid; |
9907 | 440 child_process *cp, *cps[MAX_CHILDREN]; |
441 HANDLE wait_hnd[MAX_CHILDREN]; | |
442 | |
443 nh = 0; | |
444 if (dead_child != NULL) | |
445 { | |
446 /* We want to wait for a specific child */ | |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
447 wait_hnd[nh] = dead_child->procinfo.hProcess; |
9907 | 448 cps[nh] = dead_child; |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
449 if (!wait_hnd[nh]) abort (); |
9907 | 450 nh++; |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
451 active = 0; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
452 goto get_result; |
9907 | 453 } |
454 else | |
455 { | |
456 for (cp = child_procs+(child_proc_count-1); cp >= child_procs; cp--) | |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
457 /* some child_procs might be sockets; ignore them */ |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
458 if (CHILD_ACTIVE (cp) && cp->procinfo.hProcess) |
9907 | 459 { |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
460 wait_hnd[nh] = cp->procinfo.hProcess; |
9907 | 461 cps[nh] = cp; |
462 nh++; | |
463 } | |
464 } | |
465 | |
466 if (nh == 0) | |
467 { | |
468 /* Nothing to wait on, so fail */ | |
469 errno = ECHILD; | |
470 return -1; | |
471 } | |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
472 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
473 do |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
474 { |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
475 /* Check for quit about once a second. */ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
476 QUIT; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
477 active = WaitForMultipleObjects (nh, wait_hnd, FALSE, 1000); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
478 } while (active == WAIT_TIMEOUT); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
479 |
9907 | 480 if (active == WAIT_FAILED) |
481 { | |
482 errno = EBADF; | |
483 return -1; | |
484 } | |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
485 else if (active >= WAIT_OBJECT_0 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
486 && active < WAIT_OBJECT_0+MAXIMUM_WAIT_OBJECTS) |
9907 | 487 { |
488 active -= WAIT_OBJECT_0; | |
489 } | |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
490 else if (active >= WAIT_ABANDONED_0 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
491 && active < WAIT_ABANDONED_0+MAXIMUM_WAIT_OBJECTS) |
9907 | 492 { |
493 active -= WAIT_ABANDONED_0; | |
494 } | |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
495 else |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
496 abort (); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
497 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
498 get_result: |
9907 | 499 if (!GetExitCodeProcess (wait_hnd[active], &retval)) |
500 { | |
501 DebPrint (("Wait.GetExitCodeProcess failed with %lu\n", | |
502 GetLastError ())); | |
503 retval = 1; | |
504 } | |
505 if (retval == STILL_ACTIVE) | |
506 { | |
507 /* Should never happen */ | |
508 DebPrint (("Wait.WaitForMultipleObjects returned an active process\n")); | |
509 errno = EINVAL; | |
510 return -1; | |
511 } | |
12325
aa6fc4e97a28
(win32_wait): Massage retval into what is expected in Unix.
Richard M. Stallman <rms@gnu.org>
parents:
12239
diff
changeset
|
512 |
aa6fc4e97a28
(win32_wait): Massage retval into what is expected in Unix.
Richard M. Stallman <rms@gnu.org>
parents:
12239
diff
changeset
|
513 /* Massage the exit code from the process to match the format expected |
14036 | 514 by the WIFSTOPPED et al macros in syswait.h. Only WIFSIGNALED and |
12325
aa6fc4e97a28
(win32_wait): Massage retval into what is expected in Unix.
Richard M. Stallman <rms@gnu.org>
parents:
12239
diff
changeset
|
515 WIFEXITED are supported; WIFSTOPPED doesn't make sense under NT. */ |
aa6fc4e97a28
(win32_wait): Massage retval into what is expected in Unix.
Richard M. Stallman <rms@gnu.org>
parents:
12239
diff
changeset
|
516 |
aa6fc4e97a28
(win32_wait): Massage retval into what is expected in Unix.
Richard M. Stallman <rms@gnu.org>
parents:
12239
diff
changeset
|
517 if (retval == STATUS_CONTROL_C_EXIT) |
aa6fc4e97a28
(win32_wait): Massage retval into what is expected in Unix.
Richard M. Stallman <rms@gnu.org>
parents:
12239
diff
changeset
|
518 retval = SIGINT; |
aa6fc4e97a28
(win32_wait): Massage retval into what is expected in Unix.
Richard M. Stallman <rms@gnu.org>
parents:
12239
diff
changeset
|
519 else |
aa6fc4e97a28
(win32_wait): Massage retval into what is expected in Unix.
Richard M. Stallman <rms@gnu.org>
parents:
12239
diff
changeset
|
520 retval <<= 8; |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
521 |
9907 | 522 cp = cps[active]; |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
523 pid = cp->pid; |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
524 #ifdef FULL_DEBUG |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
525 DebPrint (("Wait signaled with process pid %d\n", cp->pid)); |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
526 #endif |
11388
96fa39ad9403
(win32_wait): Reap synchronous subprocesses, and place
Karl Heuer <kwzh@gnu.org>
parents:
9907
diff
changeset
|
527 |
9907 | 528 if (status) |
529 { | |
11388
96fa39ad9403
(win32_wait): Reap synchronous subprocesses, and place
Karl Heuer <kwzh@gnu.org>
parents:
9907
diff
changeset
|
530 *status = retval; |
96fa39ad9403
(win32_wait): Reap synchronous subprocesses, and place
Karl Heuer <kwzh@gnu.org>
parents:
9907
diff
changeset
|
531 } |
96fa39ad9403
(win32_wait): Reap synchronous subprocesses, and place
Karl Heuer <kwzh@gnu.org>
parents:
9907
diff
changeset
|
532 else if (synch_process_alive) |
96fa39ad9403
(win32_wait): Reap synchronous subprocesses, and place
Karl Heuer <kwzh@gnu.org>
parents:
9907
diff
changeset
|
533 { |
96fa39ad9403
(win32_wait): Reap synchronous subprocesses, and place
Karl Heuer <kwzh@gnu.org>
parents:
9907
diff
changeset
|
534 synch_process_alive = 0; |
96fa39ad9403
(win32_wait): Reap synchronous subprocesses, and place
Karl Heuer <kwzh@gnu.org>
parents:
9907
diff
changeset
|
535 |
13931
c80fb27c183b
(win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents:
13425
diff
changeset
|
536 /* Report the status of the synchronous process. */ |
c80fb27c183b
(win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents:
13425
diff
changeset
|
537 if (WIFEXITED (retval)) |
c80fb27c183b
(win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents:
13425
diff
changeset
|
538 synch_process_retcode = WRETCODE (retval); |
c80fb27c183b
(win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents:
13425
diff
changeset
|
539 else if (WIFSIGNALED (retval)) |
c80fb27c183b
(win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents:
13425
diff
changeset
|
540 { |
c80fb27c183b
(win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents:
13425
diff
changeset
|
541 int code = WTERMSIG (retval); |
c80fb27c183b
(win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents:
13425
diff
changeset
|
542 char *signame = 0; |
c80fb27c183b
(win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents:
13425
diff
changeset
|
543 |
c80fb27c183b
(win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents:
13425
diff
changeset
|
544 if (code < NSIG) |
c80fb27c183b
(win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents:
13425
diff
changeset
|
545 { |
c80fb27c183b
(win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents:
13425
diff
changeset
|
546 /* Suppress warning if the table has const char *. */ |
c80fb27c183b
(win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents:
13425
diff
changeset
|
547 signame = (char *) sys_siglist[code]; |
c80fb27c183b
(win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents:
13425
diff
changeset
|
548 } |
c80fb27c183b
(win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents:
13425
diff
changeset
|
549 if (signame == 0) |
c80fb27c183b
(win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents:
13425
diff
changeset
|
550 signame = "unknown"; |
c80fb27c183b
(win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents:
13425
diff
changeset
|
551 |
c80fb27c183b
(win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents:
13425
diff
changeset
|
552 synch_process_death = signame; |
c80fb27c183b
(win32_wait): fixed bad synch_process_retcode
Geoff Voelker <voelker@cs.washington.edu>
parents:
13425
diff
changeset
|
553 } |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
554 |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
555 reap_subprocess (cp); |
9907 | 556 } |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
557 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
558 reap_subprocess (cp); |
9907 | 559 |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
560 return pid; |
9907 | 561 } |
562 | |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
563 void |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
564 w32_executable_type (char * filename, int * is_dos_app, int * is_cygnus_app) |
15247
874a66251747
(Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents:
15201
diff
changeset
|
565 { |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
566 file_data executable; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
567 char * p; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
568 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
569 /* Default values in case we can't tell for sure. */ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
570 *is_dos_app = FALSE; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
571 *is_cygnus_app = FALSE; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
572 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
573 if (!open_input_file (&executable, filename)) |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
574 return; |
15247
874a66251747
(Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents:
15201
diff
changeset
|
575 |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
576 p = strrchr (filename, '.'); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
577 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
578 /* We can only identify DOS .com programs from the extension. */ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
579 if (p && stricmp (p, ".com") == 0) |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
580 *is_dos_app = TRUE; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
581 else if (p && (stricmp (p, ".bat") == 0 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
582 || stricmp (p, ".cmd") == 0)) |
15247
874a66251747
(Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents:
15201
diff
changeset
|
583 { |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
584 /* A DOS shell script - it appears that CreateProcess is happy to |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
585 accept this (somewhat surprisingly); presumably it looks at |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
586 COMSPEC to determine what executable to actually invoke. |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
587 Therefore, we have to do the same here as well. */ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
588 /* Actually, I think it uses the program association for that |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
589 extension, which is defined in the registry. */ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
590 p = egetenv ("COMSPEC"); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
591 if (p) |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
592 w32_executable_type (p, is_dos_app, is_cygnus_app); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
593 } |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
594 else |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
595 { |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
596 /* Look for DOS .exe signature - if found, we must also check that |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
597 it isn't really a 16- or 32-bit Windows exe, since both formats |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
598 start with a DOS program stub. Note that 16-bit Windows |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
599 executables use the OS/2 1.x format. */ |
15247
874a66251747
(Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents:
15201
diff
changeset
|
600 |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
601 IMAGE_DOS_HEADER * dos_header; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
602 IMAGE_NT_HEADERS * nt_header; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
603 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
604 dos_header = (PIMAGE_DOS_HEADER) executable.file_base; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
605 if (dos_header->e_magic != IMAGE_DOS_SIGNATURE) |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
606 goto unwind; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
607 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
608 nt_header = (PIMAGE_NT_HEADERS) ((char *) dos_header + dos_header->e_lfanew); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
609 |
21613
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
610 if ((char *) nt_header > (char *) dos_header + executable.size) |
15247
874a66251747
(Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents:
15201
diff
changeset
|
611 { |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
612 /* Some dos headers (pkunzip) have bogus e_lfanew fields. */ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
613 *is_dos_app = TRUE; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
614 } |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
615 else if (nt_header->Signature != IMAGE_NT_SIGNATURE |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
616 && LOWORD (nt_header->Signature) != IMAGE_OS2_SIGNATURE) |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
617 { |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
618 *is_dos_app = TRUE; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
619 } |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
620 else if (nt_header->Signature == IMAGE_NT_SIGNATURE) |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
621 { |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
622 /* Look for cygwin.dll in DLL import list. */ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
623 IMAGE_DATA_DIRECTORY import_dir = |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
624 nt_header->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT]; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
625 IMAGE_IMPORT_DESCRIPTOR * imports; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
626 IMAGE_SECTION_HEADER * section; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
627 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
628 section = rva_to_section (import_dir.VirtualAddress, nt_header); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
629 imports = RVA_TO_PTR (import_dir.VirtualAddress, section, executable); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
630 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
631 for ( ; imports->Name; imports++) |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
632 { |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
633 char * dllname = RVA_TO_PTR (imports->Name, section, executable); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
634 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
635 if (strcmp (dllname, "cygwin.dll") == 0) |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
636 { |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
637 *is_cygnus_app = TRUE; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
638 break; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
639 } |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
640 } |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
641 } |
15247
874a66251747
(Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents:
15201
diff
changeset
|
642 } |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
643 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
644 unwind: |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
645 close_file_data (&executable); |
15247
874a66251747
(Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents:
15201
diff
changeset
|
646 } |
874a66251747
(Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents:
15201
diff
changeset
|
647 |
16826
e7ad34b65d8e
(compare_env, merge_and_sort_env): New functions.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
648 int |
e7ad34b65d8e
(compare_env, merge_and_sort_env): New functions.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
649 compare_env (const char **strp1, const char **strp2) |
e7ad34b65d8e
(compare_env, merge_and_sort_env): New functions.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
650 { |
e7ad34b65d8e
(compare_env, merge_and_sort_env): New functions.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
651 const char *str1 = *strp1, *str2 = *strp2; |
e7ad34b65d8e
(compare_env, merge_and_sort_env): New functions.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
652 |
e7ad34b65d8e
(compare_env, merge_and_sort_env): New functions.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
653 while (*str1 && *str2 && *str1 != '=' && *str2 != '=') |
e7ad34b65d8e
(compare_env, merge_and_sort_env): New functions.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
654 { |
e7ad34b65d8e
(compare_env, merge_and_sort_env): New functions.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
655 if (tolower (*str1) > tolower (*str2)) |
e7ad34b65d8e
(compare_env, merge_and_sort_env): New functions.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
656 return 1; |
e7ad34b65d8e
(compare_env, merge_and_sort_env): New functions.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
657 else if (tolower (*str1) < tolower (*str2)) |
e7ad34b65d8e
(compare_env, merge_and_sort_env): New functions.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
658 return -1; |
e7ad34b65d8e
(compare_env, merge_and_sort_env): New functions.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
659 str1++, str2++; |
e7ad34b65d8e
(compare_env, merge_and_sort_env): New functions.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
660 } |
e7ad34b65d8e
(compare_env, merge_and_sort_env): New functions.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
661 |
e7ad34b65d8e
(compare_env, merge_and_sort_env): New functions.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
662 if (*str1 == '=' && *str2 == '=') |
e7ad34b65d8e
(compare_env, merge_and_sort_env): New functions.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
663 return 0; |
e7ad34b65d8e
(compare_env, merge_and_sort_env): New functions.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
664 else if (*str1 == '=') |
e7ad34b65d8e
(compare_env, merge_and_sort_env): New functions.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
665 return -1; |
e7ad34b65d8e
(compare_env, merge_and_sort_env): New functions.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
666 else |
e7ad34b65d8e
(compare_env, merge_and_sort_env): New functions.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
667 return 1; |
e7ad34b65d8e
(compare_env, merge_and_sort_env): New functions.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
668 } |
e7ad34b65d8e
(compare_env, merge_and_sort_env): New functions.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
669 |
e7ad34b65d8e
(compare_env, merge_and_sort_env): New functions.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
670 void |
e7ad34b65d8e
(compare_env, merge_and_sort_env): New functions.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
671 merge_and_sort_env (char **envp1, char **envp2, char **new_envp) |
e7ad34b65d8e
(compare_env, merge_and_sort_env): New functions.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
672 { |
e7ad34b65d8e
(compare_env, merge_and_sort_env): New functions.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
673 char **optr, **nptr; |
e7ad34b65d8e
(compare_env, merge_and_sort_env): New functions.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
674 int num; |
e7ad34b65d8e
(compare_env, merge_and_sort_env): New functions.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
675 |
e7ad34b65d8e
(compare_env, merge_and_sort_env): New functions.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
676 nptr = new_envp; |
e7ad34b65d8e
(compare_env, merge_and_sort_env): New functions.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
677 optr = envp1; |
e7ad34b65d8e
(compare_env, merge_and_sort_env): New functions.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
678 while (*optr) |
e7ad34b65d8e
(compare_env, merge_and_sort_env): New functions.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
679 *nptr++ = *optr++; |
e7ad34b65d8e
(compare_env, merge_and_sort_env): New functions.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
680 num = optr - envp1; |
e7ad34b65d8e
(compare_env, merge_and_sort_env): New functions.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
681 |
e7ad34b65d8e
(compare_env, merge_and_sort_env): New functions.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
682 optr = envp2; |
e7ad34b65d8e
(compare_env, merge_and_sort_env): New functions.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
683 while (*optr) |
e7ad34b65d8e
(compare_env, merge_and_sort_env): New functions.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
684 *nptr++ = *optr++; |
e7ad34b65d8e
(compare_env, merge_and_sort_env): New functions.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
685 num += optr - envp2; |
e7ad34b65d8e
(compare_env, merge_and_sort_env): New functions.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
686 |
e7ad34b65d8e
(compare_env, merge_and_sort_env): New functions.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
687 qsort (new_envp, num, sizeof (char *), compare_env); |
e7ad34b65d8e
(compare_env, merge_and_sort_env): New functions.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
688 |
e7ad34b65d8e
(compare_env, merge_and_sort_env): New functions.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
689 *nptr = NULL; |
e7ad34b65d8e
(compare_env, merge_and_sort_env): New functions.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
690 } |
9907 | 691 |
692 /* When a new child process is created we need to register it in our list, | |
693 so intercept spawn requests. */ | |
694 int | |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
695 sys_spawnve (int mode, char *cmdname, char **argv, char **envp) |
9907 | 696 { |
12239
ff7738cdbd99
(win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents:
12183
diff
changeset
|
697 Lisp_Object program, full; |
9907 | 698 char *cmdline, *env, *parg, **targ; |
16826
e7ad34b65d8e
(compare_env, merge_and_sort_env): New functions.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
699 int arglen, numenv; |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
700 int pid; |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
701 child_process *cp; |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
702 int is_dos_app, is_cygnus_app; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
703 int do_quoting = 0; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
704 char escape_char; |
16826
e7ad34b65d8e
(compare_env, merge_and_sort_env): New functions.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
705 /* We pass our process ID to our children by setting up an environment |
e7ad34b65d8e
(compare_env, merge_and_sort_env): New functions.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
706 variable in their environment. */ |
e7ad34b65d8e
(compare_env, merge_and_sort_env): New functions.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
707 char ppid_env_var_buffer[64]; |
e7ad34b65d8e
(compare_env, merge_and_sort_env): New functions.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
708 char *extra_env[] = {ppid_env_var_buffer, NULL}; |
e7ad34b65d8e
(compare_env, merge_and_sort_env): New functions.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
709 |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
710 /* We don't care about the other modes */ |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
711 if (mode != _P_NOWAIT) |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
712 { |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
713 errno = EINVAL; |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
714 return -1; |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
715 } |
12239
ff7738cdbd99
(win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents:
12183
diff
changeset
|
716 |
ff7738cdbd99
(win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents:
12183
diff
changeset
|
717 /* Handle executable names without an executable suffix. */ |
ff7738cdbd99
(win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents:
12183
diff
changeset
|
718 program = make_string (cmdname, strlen (cmdname)); |
ff7738cdbd99
(win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents:
12183
diff
changeset
|
719 if (NILP (Ffile_executable_p (program))) |
ff7738cdbd99
(win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents:
12183
diff
changeset
|
720 { |
ff7738cdbd99
(win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents:
12183
diff
changeset
|
721 struct gcpro gcpro1; |
ff7738cdbd99
(win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents:
12183
diff
changeset
|
722 |
ff7738cdbd99
(win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents:
12183
diff
changeset
|
723 full = Qnil; |
ff7738cdbd99
(win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents:
12183
diff
changeset
|
724 GCPRO1 (program); |
ff7738cdbd99
(win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents:
12183
diff
changeset
|
725 openp (Vexec_path, program, EXEC_SUFFIXES, &full, 1); |
ff7738cdbd99
(win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents:
12183
diff
changeset
|
726 UNGCPRO; |
ff7738cdbd99
(win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents:
12183
diff
changeset
|
727 if (NILP (full)) |
ff7738cdbd99
(win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents:
12183
diff
changeset
|
728 { |
ff7738cdbd99
(win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents:
12183
diff
changeset
|
729 errno = EINVAL; |
ff7738cdbd99
(win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents:
12183
diff
changeset
|
730 return -1; |
ff7738cdbd99
(win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents:
12183
diff
changeset
|
731 } |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
732 program = full; |
12239
ff7738cdbd99
(win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents:
12183
diff
changeset
|
733 } |
ff7738cdbd99
(win32_spawnve): Accept program names without executable suffixes.
Richard M. Stallman <rms@gnu.org>
parents:
12183
diff
changeset
|
734 |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
735 /* make sure argv[0] and cmdname are both in DOS format */ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
736 cmdname = XSTRING (program)->data; |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
737 unixtodos_filename (cmdname); |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
738 argv[0] = cmdname; |
15247
874a66251747
(Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents:
15201
diff
changeset
|
739 |
21613
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
740 /* Determine whether program is a 16-bit DOS executable, or a w32 |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
741 executable that is implicitly linked to the Cygnus dll (implying it |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
742 was compiled with the Cygnus GNU toolchain and hence relies on |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
743 cygwin.dll to parse the command line - we use this to decide how to |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
744 escape quote chars in command line args that must be quoted). */ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
745 w32_executable_type (cmdname, &is_dos_app, &is_cygnus_app); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
746 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
747 /* On Windows 95, if cmdname is a DOS app, we invoke a helper |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
748 application to start it by specifying the helper app as cmdname, |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
749 while leaving the real app name as argv[0]. */ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
750 if (is_dos_app) |
15247
874a66251747
(Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents:
15201
diff
changeset
|
751 { |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
752 cmdname = alloca (MAXPATHLEN); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
753 if (egetenv ("CMDPROXY")) |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
754 strcpy (cmdname, egetenv ("CMDPROXY")); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
755 else |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
756 { |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
757 strcpy (cmdname, XSTRING (Vinvocation_directory)->data); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
758 strcat (cmdname, "cmdproxy.exe"); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
759 } |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
760 unixtodos_filename (cmdname); |
15247
874a66251747
(Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents:
15201
diff
changeset
|
761 } |
9907 | 762 |
763 /* we have to do some conjuring here to put argv and envp into the | |
764 form CreateProcess wants... argv needs to be a space separated/null | |
765 terminated list of parameters, and envp is a null | |
766 separated/double-null terminated list of parameters. | |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
767 |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
768 Additionally, zero-length args and args containing whitespace or |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
769 quote chars need to be wrapped in double quotes - for this to work, |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
770 embedded quotes need to be escaped as well. The aim is to ensure |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
771 the child process reconstructs the argv array we start with |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
772 exactly, so we treat quotes at the beginning and end of arguments |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
773 as embedded quotes. |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
774 |
21613
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
775 The w32 GNU-based library from Cygnus doubles quotes to escape |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
776 them, while MSVC uses backslash for escaping. (Actually the MSVC |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
777 startup code does attempt to recognise doubled quotes and accept |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
778 them, but gets it wrong and ends up requiring three quotes to get a |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
779 single embedded quote!) So by default we decide whether to use |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
780 quote or backslash as the escape character based on whether the |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
781 binary is apparently a Cygnus compiled app. |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
782 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
783 Note that using backslash to escape embedded quotes requires |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
784 additional special handling if an embedded quote is already |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
785 preceeded by backslash, or if an arg requiring quoting ends with |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
786 backslash. In such cases, the run of escape characters needs to be |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
787 doubled. For consistency, we apply this special handling as long |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
788 as the escape character is not quote. |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
789 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
790 Since we have no idea how large argv and envp are likely to be we |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
791 figure out list lengths on the fly and allocate them. */ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
792 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
793 if (!NILP (Vw32_quote_process_args)) |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
794 { |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
795 do_quoting = 1; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
796 /* Override escape char by binding w32-quote-process-args to |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
797 desired character, or use t for auto-selection. */ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
798 if (INTEGERP (Vw32_quote_process_args)) |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
799 escape_char = XINT (Vw32_quote_process_args); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
800 else |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
801 escape_char = is_cygnus_app ? '"' : '\\'; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
802 } |
9907 | 803 |
804 /* do argv... */ | |
805 arglen = 0; | |
806 targ = argv; | |
807 while (*targ) | |
808 { | |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
809 char * p = *targ; |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
810 int need_quotes = 0; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
811 int escape_char_run = 0; |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
812 |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
813 if (*p == 0) |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
814 need_quotes = 1; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
815 for ( ; *p; p++) |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
816 { |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
817 if (*p == '"') |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
818 { |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
819 /* allow for embedded quotes to be escaped */ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
820 arglen++; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
821 need_quotes = 1; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
822 /* handle the case where the embedded quote is already escaped */ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
823 if (escape_char_run > 0) |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
824 { |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
825 /* To preserve the arg exactly, we need to double the |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
826 preceding escape characters (plus adding one to |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
827 escape the quote character itself). */ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
828 arglen += escape_char_run; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
829 } |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
830 } |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
831 else if (*p == ' ' || *p == '\t') |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
832 { |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
833 need_quotes = 1; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
834 } |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
835 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
836 if (*p == escape_char && escape_char != '"') |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
837 escape_char_run++; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
838 else |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
839 escape_char_run = 0; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
840 } |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
841 if (need_quotes) |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
842 { |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
843 arglen += 2; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
844 /* handle the case where the arg ends with an escape char - we |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
845 must not let the enclosing quote be escaped. */ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
846 if (escape_char_run > 0) |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
847 arglen += escape_char_run; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
848 } |
9907 | 849 arglen += strlen (*targ++) + 1; |
850 } | |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
851 cmdline = alloca (arglen); |
9907 | 852 targ = argv; |
853 parg = cmdline; | |
854 while (*targ) | |
855 { | |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
856 char * p = *targ; |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
857 int need_quotes = 0; |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
858 |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
859 if (*p == 0) |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
860 need_quotes = 1; |
15201
43551ec4b69d
(Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
15145
diff
changeset
|
861 |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
862 if (do_quoting) |
15201
43551ec4b69d
(Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
15145
diff
changeset
|
863 { |
43551ec4b69d
(Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
15145
diff
changeset
|
864 for ( ; *p; p++) |
43551ec4b69d
(Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
15145
diff
changeset
|
865 if (*p == ' ' || *p == '\t' || *p == '"') |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
866 need_quotes = 1; |
15201
43551ec4b69d
(Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
15145
diff
changeset
|
867 } |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
868 if (need_quotes) |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
869 { |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
870 int escape_char_run = 0; |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
871 char * first; |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
872 char * last; |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
873 |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
874 p = *targ; |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
875 first = p; |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
876 last = p + strlen (p) - 1; |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
877 *parg++ = '"'; |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
878 #if 0 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
879 /* This version does not escape quotes if they occur at the |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
880 beginning or end of the arg - this could lead to incorrect |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
881 behaviour when the arg itself represents a command line |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
882 containing quoted args. I believe this was originally done |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
883 as a hack to make some things work, before |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
884 `w32-quote-process-args' was added. */ |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
885 while (*p) |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
886 { |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
887 if (*p == '"' && p > first && p < last) |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
888 *parg++ = escape_char; /* escape embedded quotes */ |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
889 *parg++ = *p++; |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
890 } |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
891 #else |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
892 for ( ; *p; p++) |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
893 { |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
894 if (*p == '"') |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
895 { |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
896 /* double preceding escape chars if any */ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
897 while (escape_char_run > 0) |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
898 { |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
899 *parg++ = escape_char; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
900 escape_char_run--; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
901 } |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
902 /* escape all quote chars, even at beginning or end */ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
903 *parg++ = escape_char; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
904 } |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
905 *parg++ = *p; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
906 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
907 if (*p == escape_char && escape_char != '"') |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
908 escape_char_run++; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
909 else |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
910 escape_char_run = 0; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
911 } |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
912 /* double escape chars before enclosing quote */ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
913 while (escape_char_run > 0) |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
914 { |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
915 *parg++ = escape_char; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
916 escape_char_run--; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
917 } |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
918 #endif |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
919 *parg++ = '"'; |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
920 } |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
921 else |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
922 { |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
923 strcpy (parg, *targ); |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
924 parg += strlen (*targ); |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
925 } |
9907 | 926 *parg++ = ' '; |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
927 targ++; |
9907 | 928 } |
929 *--parg = '\0'; | |
930 | |
931 /* and envp... */ | |
932 arglen = 1; | |
933 targ = envp; | |
16826
e7ad34b65d8e
(compare_env, merge_and_sort_env): New functions.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
934 numenv = 1; /* for end null */ |
9907 | 935 while (*targ) |
936 { | |
937 arglen += strlen (*targ++) + 1; | |
16826
e7ad34b65d8e
(compare_env, merge_and_sort_env): New functions.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
938 numenv++; |
9907 | 939 } |
16826
e7ad34b65d8e
(compare_env, merge_and_sort_env): New functions.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
940 /* extra env vars... */ |
22298
e509b80a17a2
(sys_spawnve): Place Emacs pid in EM_PARENT_PROCESS_ID.
Geoff Voelker <voelker@cs.washington.edu>
parents:
22079
diff
changeset
|
941 sprintf (ppid_env_var_buffer, "EM_PARENT_PROCESS_ID=%d", |
9907 | 942 GetCurrentProcessId ()); |
943 arglen += strlen (ppid_env_var_buffer) + 1; | |
16826
e7ad34b65d8e
(compare_env, merge_and_sort_env): New functions.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
944 numenv++; |
9907 | 945 |
16826
e7ad34b65d8e
(compare_env, merge_and_sort_env): New functions.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
946 /* merge env passed in and extra env into one, and sort it. */ |
e7ad34b65d8e
(compare_env, merge_and_sort_env): New functions.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
947 targ = (char **) alloca (numenv * sizeof (char *)); |
e7ad34b65d8e
(compare_env, merge_and_sort_env): New functions.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
948 merge_and_sort_env (envp, extra_env, targ); |
e7ad34b65d8e
(compare_env, merge_and_sort_env): New functions.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
949 |
e7ad34b65d8e
(compare_env, merge_and_sort_env): New functions.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
950 /* concatenate env entries. */ |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
951 env = alloca (arglen); |
9907 | 952 parg = env; |
953 while (*targ) | |
954 { | |
955 strcpy (parg, *targ); | |
956 parg += strlen (*targ++); | |
957 *parg++ = '\0'; | |
958 } | |
959 *parg++ = '\0'; | |
960 *parg = '\0'; | |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
961 |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
962 cp = new_child (); |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
963 if (cp == NULL) |
9907 | 964 { |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
965 errno = EAGAIN; |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
966 return -1; |
9907 | 967 } |
968 | |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
969 /* Now create the process. */ |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
970 if (!create_child (cmdname, cmdline, env, &pid, cp)) |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
971 { |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
972 delete_child (cp); |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
973 errno = ENOEXEC; |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
974 return -1; |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
975 } |
9907 | 976 |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
977 return pid; |
9907 | 978 } |
979 | |
980 /* Emulate the select call | |
981 Wait for available input on any of the given rfds, or timeout if | |
982 a timeout is given and no input is detected | |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
983 wfds and efds are not supported and must be NULL. |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
984 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
985 For simplicity, we detect the death of child processes here and |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
986 synchronously call the SIGCHLD handler. Since it is possible for |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
987 children to be created without a corresponding pipe handle from which |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
988 to read output, we wait separately on the process handles as well as |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
989 the char_avail events for each process pipe. We only call |
22079
b7a2370ee82d
(sys_select): Always wait on interrupt_handle, so that
Richard M. Stallman <rms@gnu.org>
parents:
21742
diff
changeset
|
990 wait/reap_process when the process actually terminates. |
b7a2370ee82d
(sys_select): Always wait on interrupt_handle, so that
Richard M. Stallman <rms@gnu.org>
parents:
21742
diff
changeset
|
991 |
b7a2370ee82d
(sys_select): Always wait on interrupt_handle, so that
Richard M. Stallman <rms@gnu.org>
parents:
21742
diff
changeset
|
992 To reduce the number of places in which Emacs can be hung such that |
b7a2370ee82d
(sys_select): Always wait on interrupt_handle, so that
Richard M. Stallman <rms@gnu.org>
parents:
21742
diff
changeset
|
993 C-g is not able to interrupt it, we always wait on interrupt_handle |
b7a2370ee82d
(sys_select): Always wait on interrupt_handle, so that
Richard M. Stallman <rms@gnu.org>
parents:
21742
diff
changeset
|
994 (which is signalled by the input thread when C-g is detected). If we |
b7a2370ee82d
(sys_select): Always wait on interrupt_handle, so that
Richard M. Stallman <rms@gnu.org>
parents:
21742
diff
changeset
|
995 detect that we were woken up by C-g, we return -1 with errno set to |
b7a2370ee82d
(sys_select): Always wait on interrupt_handle, so that
Richard M. Stallman <rms@gnu.org>
parents:
21742
diff
changeset
|
996 EINTR as on Unix. */ |
9907 | 997 |
998 /* From ntterm.c */ | |
999 extern HANDLE keyboard_handle; | |
22079
b7a2370ee82d
(sys_select): Always wait on interrupt_handle, so that
Richard M. Stallman <rms@gnu.org>
parents:
21742
diff
changeset
|
1000 |
b7a2370ee82d
(sys_select): Always wait on interrupt_handle, so that
Richard M. Stallman <rms@gnu.org>
parents:
21742
diff
changeset
|
1001 /* From w32xfns.c */ |
b7a2370ee82d
(sys_select): Always wait on interrupt_handle, so that
Richard M. Stallman <rms@gnu.org>
parents:
21742
diff
changeset
|
1002 extern HANDLE interrupt_handle; |
b7a2370ee82d
(sys_select): Always wait on interrupt_handle, so that
Richard M. Stallman <rms@gnu.org>
parents:
21742
diff
changeset
|
1003 |
9907 | 1004 /* From process.c */ |
1005 extern int proc_buffered_char[]; | |
1006 | |
1007 int | |
11388
96fa39ad9403
(win32_wait): Reap synchronous subprocesses, and place
Karl Heuer <kwzh@gnu.org>
parents:
9907
diff
changeset
|
1008 sys_select (int nfds, SELECT_TYPE *rfds, SELECT_TYPE *wfds, SELECT_TYPE *efds, |
96fa39ad9403
(win32_wait): Reap synchronous subprocesses, and place
Karl Heuer <kwzh@gnu.org>
parents:
9907
diff
changeset
|
1009 EMACS_TIME *timeout) |
9907 | 1010 { |
1011 SELECT_TYPE orfds; | |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1012 DWORD timeout_ms, start_time; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1013 int i, nh, nc, nr; |
9907 | 1014 DWORD active; |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1015 child_process *cp, *cps[MAX_CHILDREN]; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1016 HANDLE wait_hnd[MAXDESC + MAX_CHILDREN]; |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1017 int fdindex[MAXDESC]; /* mapping from wait handles back to descriptors */ |
9907 | 1018 |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1019 timeout_ms = timeout ? (timeout->tv_sec * 1000 + timeout->tv_usec / 1000) : INFINITE; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1020 |
9907 | 1021 /* If the descriptor sets are NULL but timeout isn't, then just Sleep. */ |
1022 if (rfds == NULL && wfds == NULL && efds == NULL && timeout != NULL) | |
1023 { | |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1024 Sleep (timeout_ms); |
9907 | 1025 return 0; |
1026 } | |
1027 | |
1028 /* Otherwise, we only handle rfds, so fail otherwise. */ | |
1029 if (rfds == NULL || wfds != NULL || efds != NULL) | |
1030 { | |
1031 errno = EINVAL; | |
1032 return -1; | |
1033 } | |
1034 | |
1035 orfds = *rfds; | |
1036 FD_ZERO (rfds); | |
1037 nr = 0; | |
22079
b7a2370ee82d
(sys_select): Always wait on interrupt_handle, so that
Richard M. Stallman <rms@gnu.org>
parents:
21742
diff
changeset
|
1038 |
b7a2370ee82d
(sys_select): Always wait on interrupt_handle, so that
Richard M. Stallman <rms@gnu.org>
parents:
21742
diff
changeset
|
1039 /* Always wait on interrupt_handle, to detect C-g (quit). */ |
b7a2370ee82d
(sys_select): Always wait on interrupt_handle, so that
Richard M. Stallman <rms@gnu.org>
parents:
21742
diff
changeset
|
1040 wait_hnd[0] = interrupt_handle; |
b7a2370ee82d
(sys_select): Always wait on interrupt_handle, so that
Richard M. Stallman <rms@gnu.org>
parents:
21742
diff
changeset
|
1041 fdindex[0] = -1; |
9907 | 1042 |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1043 /* Build a list of pipe handles to wait on. */ |
22079
b7a2370ee82d
(sys_select): Always wait on interrupt_handle, so that
Richard M. Stallman <rms@gnu.org>
parents:
21742
diff
changeset
|
1044 nh = 1; |
9907 | 1045 for (i = 0; i < nfds; i++) |
1046 if (FD_ISSET (i, &orfds)) | |
1047 { | |
1048 if (i == 0) | |
1049 { | |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1050 if (keyboard_handle) |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1051 { |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1052 /* Handle stdin specially */ |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1053 wait_hnd[nh] = keyboard_handle; |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1054 fdindex[nh] = i; |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1055 nh++; |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1056 } |
9907 | 1057 |
1058 /* Check for any emacs-generated input in the queue since | |
1059 it won't be detected in the wait */ | |
1060 if (detect_input_pending ()) | |
1061 { | |
1062 FD_SET (i, rfds); | |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1063 return 1; |
9907 | 1064 } |
1065 } | |
1066 else | |
1067 { | |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1068 /* Child process and socket input */ |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1069 cp = fd_info[i].cp; |
9907 | 1070 if (cp) |
1071 { | |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1072 int current_status = cp->status; |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1073 |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1074 if (current_status == STATUS_READ_ACKNOWLEDGED) |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1075 { |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1076 /* Tell reader thread which file handle to use. */ |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1077 cp->fd = i; |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1078 /* Wake up the reader thread for this process */ |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1079 cp->status = STATUS_READ_READY; |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1080 if (!SetEvent (cp->char_consumed)) |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1081 DebPrint (("nt_select.SetEvent failed with " |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1082 "%lu for fd %ld\n", GetLastError (), i)); |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1083 } |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1084 |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1085 #ifdef CHECK_INTERLOCK |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1086 /* slightly crude cross-checking of interlock between threads */ |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1087 |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1088 current_status = cp->status; |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1089 if (WaitForSingleObject (cp->char_avail, 0) == WAIT_OBJECT_0) |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1090 { |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1091 /* char_avail has been signalled, so status (which may |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1092 have changed) should indicate read has completed |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1093 but has not been acknowledged. */ |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1094 current_status = cp->status; |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1095 if (current_status != STATUS_READ_SUCCEEDED |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1096 && current_status != STATUS_READ_FAILED) |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1097 DebPrint (("char_avail set, but read not completed: status %d\n", |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1098 current_status)); |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1099 } |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1100 else |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1101 { |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1102 /* char_avail has not been signalled, so status should |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1103 indicate that read is in progress; small possibility |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1104 that read has completed but event wasn't yet signalled |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1105 when we tested it (because a context switch occurred |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1106 or if running on separate CPUs). */ |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1107 if (current_status != STATUS_READ_READY |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1108 && current_status != STATUS_READ_IN_PROGRESS |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1109 && current_status != STATUS_READ_SUCCEEDED |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1110 && current_status != STATUS_READ_FAILED) |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1111 DebPrint (("char_avail reset, but read status is bad: %d\n", |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1112 current_status)); |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1113 } |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1114 #endif |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1115 wait_hnd[nh] = cp->char_avail; |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1116 fdindex[nh] = i; |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1117 if (!wait_hnd[nh]) abort (); |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1118 nh++; |
9907 | 1119 #ifdef FULL_DEBUG |
1120 DebPrint (("select waiting on child %d fd %d\n", | |
1121 cp-child_procs, i)); | |
1122 #endif | |
1123 } | |
1124 else | |
1125 { | |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1126 /* Unable to find something to wait on for this fd, skip */ |
21613
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1127 |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1128 /* Note that this is not a fatal error, and can in fact |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1129 happen in unusual circumstances. Specifically, if |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1130 sys_spawnve fails, eg. because the program doesn't |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1131 exist, and debug-on-error is t so Fsignal invokes a |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1132 nested input loop, then the process output pipe is |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1133 still included in input_wait_mask with no child_proc |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1134 associated with it. (It is removed when the debugger |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1135 exits the nested input loop and the error is thrown.) */ |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1136 |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1137 DebPrint (("sys_select: fd %ld is invalid! ignoring\n", i)); |
9907 | 1138 } |
1139 } | |
1140 } | |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1141 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1142 count_children: |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1143 /* Add handles of child processes. */ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1144 nc = 0; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1145 for (cp = child_procs+(child_proc_count-1); cp >= child_procs; cp--) |
21613
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1146 /* Some child_procs might be sockets; ignore them. Also some |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1147 children may have died already, but we haven't finished reading |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1148 the process output; ignore them too. */ |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1149 if (CHILD_ACTIVE (cp) && cp->procinfo.hProcess |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1150 && (cp->fd < 0 |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1151 || (fd_info[cp->fd].flags & FILE_SEND_SIGCHLD) == 0 |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1152 || (fd_info[cp->fd].flags & FILE_AT_EOF) != 0) |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1153 ) |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1154 { |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1155 wait_hnd[nh + nc] = cp->procinfo.hProcess; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1156 cps[nc] = cp; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1157 nc++; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1158 } |
9907 | 1159 |
1160 /* Nothing to look for, so we didn't find anything */ | |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1161 if (nh + nc == 0) |
9907 | 1162 { |
11388
96fa39ad9403
(win32_wait): Reap synchronous subprocesses, and place
Karl Heuer <kwzh@gnu.org>
parents:
9907
diff
changeset
|
1163 if (timeout) |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1164 Sleep (timeout_ms); |
9907 | 1165 return 0; |
1166 } | |
1167 | |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1168 /* Wait for input or child death to be signalled. */ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1169 start_time = GetTickCount (); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1170 active = WaitForMultipleObjects (nh + nc, wait_hnd, FALSE, timeout_ms); |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1171 |
9907 | 1172 if (active == WAIT_FAILED) |
1173 { | |
1174 DebPrint (("select.WaitForMultipleObjects (%d, %lu) failed with %lu\n", | |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1175 nh + nc, timeout_ms, GetLastError ())); |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1176 /* don't return EBADF - this causes wait_reading_process_input to |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1177 abort; WAIT_FAILED is returned when single-stepping under |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1178 Windows 95 after switching thread focus in debugger, and |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1179 possibly at other times. */ |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1180 errno = EINTR; |
9907 | 1181 return -1; |
1182 } | |
1183 else if (active == WAIT_TIMEOUT) | |
1184 { | |
1185 return 0; | |
1186 } | |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1187 else if (active >= WAIT_OBJECT_0 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1188 && active < WAIT_OBJECT_0+MAXIMUM_WAIT_OBJECTS) |
9907 | 1189 { |
1190 active -= WAIT_OBJECT_0; | |
1191 } | |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1192 else if (active >= WAIT_ABANDONED_0 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1193 && active < WAIT_ABANDONED_0+MAXIMUM_WAIT_OBJECTS) |
9907 | 1194 { |
1195 active -= WAIT_ABANDONED_0; | |
1196 } | |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1197 else |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1198 abort (); |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1199 |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1200 /* Loop over all handles after active (now officially documented as |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1201 being the first signalled handle in the array). We do this to |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1202 ensure fairness, so that all channels with data available will be |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1203 processed - otherwise higher numbered channels could be starved. */ |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1204 do |
9907 | 1205 { |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1206 if (active >= nh) |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1207 { |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1208 cp = cps[active - nh]; |
21613
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1209 |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1210 /* We cannot always signal SIGCHLD immediately; if we have not |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1211 finished reading the process output, we must delay sending |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1212 SIGCHLD until we do. */ |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1213 |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1214 if (cp->fd >= 0 && (fd_info[cp->fd].flags & FILE_AT_EOF) == 0) |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1215 fd_info[cp->fd].flags |= FILE_SEND_SIGCHLD; |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1216 /* SIG_DFL for SIGCHLD is ignore */ |
21613
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1217 else if (sig_handlers[SIGCHLD] != SIG_DFL && |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1218 sig_handlers[SIGCHLD] != SIG_IGN) |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1219 { |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1220 #ifdef FULL_DEBUG |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1221 DebPrint (("select calling SIGCHLD handler for pid %d\n", |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1222 cp->pid)); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1223 #endif |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1224 dead_child = cp; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1225 sig_handlers[SIGCHLD] (SIGCHLD); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1226 dead_child = NULL; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1227 } |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1228 } |
22079
b7a2370ee82d
(sys_select): Always wait on interrupt_handle, so that
Richard M. Stallman <rms@gnu.org>
parents:
21742
diff
changeset
|
1229 else if (fdindex[active] == -1) |
b7a2370ee82d
(sys_select): Always wait on interrupt_handle, so that
Richard M. Stallman <rms@gnu.org>
parents:
21742
diff
changeset
|
1230 { |
b7a2370ee82d
(sys_select): Always wait on interrupt_handle, so that
Richard M. Stallman <rms@gnu.org>
parents:
21742
diff
changeset
|
1231 /* Quit (C-g) was detected. */ |
b7a2370ee82d
(sys_select): Always wait on interrupt_handle, so that
Richard M. Stallman <rms@gnu.org>
parents:
21742
diff
changeset
|
1232 errno = EINTR; |
b7a2370ee82d
(sys_select): Always wait on interrupt_handle, so that
Richard M. Stallman <rms@gnu.org>
parents:
21742
diff
changeset
|
1233 return -1; |
b7a2370ee82d
(sys_select): Always wait on interrupt_handle, so that
Richard M. Stallman <rms@gnu.org>
parents:
21742
diff
changeset
|
1234 } |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1235 else if (fdindex[active] == 0) |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1236 { |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1237 /* Keyboard input available */ |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1238 FD_SET (0, rfds); |
9907 | 1239 nr++; |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1240 } |
9907 | 1241 else |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1242 { |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1243 /* must be a socket or pipe - read ahead should have |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1244 completed, either succeeding or failing. */ |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1245 FD_SET (fdindex[active], rfds); |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1246 nr++; |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1247 } |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1248 |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1249 /* Even though wait_reading_process_output only reads from at most |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1250 one channel, we must process all channels here so that we reap |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1251 all children that have died. */ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1252 while (++active < nh + nc) |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1253 if (WaitForSingleObject (wait_hnd[active], 0) == WAIT_OBJECT_0) |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1254 break; |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1255 } while (active < nh + nc); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1256 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1257 /* If no input has arrived and timeout hasn't expired, wait again. */ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1258 if (nr == 0) |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1259 { |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1260 DWORD elapsed = GetTickCount () - start_time; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1261 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1262 if (timeout_ms > elapsed) /* INFINITE is MAX_UINT */ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1263 { |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1264 if (timeout_ms != INFINITE) |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1265 timeout_ms -= elapsed; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1266 goto count_children; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1267 } |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1268 } |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1269 |
9907 | 1270 return nr; |
1271 } | |
1272 | |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1273 /* Substitute for certain kill () operations */ |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1274 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1275 static BOOL CALLBACK |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1276 find_child_console (HWND hwnd, child_process * cp) |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1277 { |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1278 DWORD thread_id; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1279 DWORD process_id; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1280 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1281 thread_id = GetWindowThreadProcessId (hwnd, &process_id); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1282 if (process_id == cp->procinfo.dwProcessId) |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1283 { |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1284 char window_class[32]; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1285 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1286 GetClassName (hwnd, window_class, sizeof (window_class)); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1287 if (strcmp (window_class, |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1288 (os_subtype == OS_WIN95) |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1289 ? "tty" |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1290 : "ConsoleWindowClass") == 0) |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1291 { |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1292 cp->hwnd = hwnd; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1293 return FALSE; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1294 } |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1295 } |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1296 /* keep looking */ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1297 return TRUE; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1298 } |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1299 |
9907 | 1300 int |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1301 sys_kill (int pid, int sig) |
9907 | 1302 { |
1303 child_process *cp; | |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1304 HANDLE proc_hand; |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1305 int need_to_free = 0; |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1306 int rc = 0; |
9907 | 1307 |
1308 /* Only handle signals that will result in the process dying */ | |
1309 if (sig != SIGINT && sig != SIGKILL && sig != SIGQUIT && sig != SIGHUP) | |
1310 { | |
1311 errno = EINVAL; | |
1312 return -1; | |
1313 } | |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1314 |
9907 | 1315 cp = find_child_pid (pid); |
1316 if (cp == NULL) | |
1317 { | |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1318 proc_hand = OpenProcess (PROCESS_TERMINATE, 0, pid); |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1319 if (proc_hand == NULL) |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1320 { |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1321 errno = EPERM; |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1322 return -1; |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1323 } |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1324 need_to_free = 1; |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1325 } |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1326 else |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1327 { |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1328 proc_hand = cp->procinfo.hProcess; |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1329 pid = cp->procinfo.dwProcessId; |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1330 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1331 /* Try to locate console window for process. */ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1332 EnumWindows (find_child_console, (LPARAM) cp); |
9907 | 1333 } |
1334 | |
1335 if (sig == SIGINT) | |
1336 { | |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1337 if (NILP (Vw32_start_process_share_console) && cp && cp->hwnd) |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1338 { |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1339 BYTE control_scan_code = (BYTE) MapVirtualKey (VK_CONTROL, 0); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1340 BYTE vk_break_code = VK_CANCEL; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1341 BYTE break_scan_code = (BYTE) MapVirtualKey (vk_break_code, 0); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1342 HWND foreground_window; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1343 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1344 if (break_scan_code == 0) |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1345 { |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1346 /* Fake Ctrl-C if we can't manage Ctrl-Break. */ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1347 vk_break_code = 'C'; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1348 break_scan_code = (BYTE) MapVirtualKey (vk_break_code, 0); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1349 } |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1350 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1351 foreground_window = GetForegroundWindow (); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1352 if (foreground_window && SetForegroundWindow (cp->hwnd)) |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1353 { |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1354 /* Generate keystrokes as if user had typed Ctrl-Break or Ctrl-C. */ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1355 keybd_event (VK_CONTROL, control_scan_code, 0, 0); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1356 keybd_event (vk_break_code, break_scan_code, 0, 0); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1357 keybd_event (vk_break_code, break_scan_code, KEYEVENTF_KEYUP, 0); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1358 keybd_event (VK_CONTROL, control_scan_code, KEYEVENTF_KEYUP, 0); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1359 |
21613
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1360 /* Sleep for a bit to give time for Emacs frame to respond |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1361 to focus change events (if Emacs was active app). */ |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1362 Sleep (10); |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1363 |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1364 SetForegroundWindow (foreground_window); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1365 } |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1366 } |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1367 /* Ctrl-Break is NT equivalent of SIGINT. */ |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1368 else if (!GenerateConsoleCtrlEvent (CTRL_BREAK_EVENT, pid)) |
9907 | 1369 { |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1370 DebPrint (("sys_kill.GenerateConsoleCtrlEvent return %d " |
9907 | 1371 "for pid %lu\n", GetLastError (), pid)); |
1372 errno = EINVAL; | |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1373 rc = -1; |
21742
b1c3fe58dbbe
(sys_kill): Fix indenting.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21613
diff
changeset
|
1374 } |
9907 | 1375 } |
1376 else | |
1377 { | |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1378 if (NILP (Vw32_start_process_share_console) && cp && cp->hwnd) |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1379 { |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1380 #if 1 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1381 if (os_subtype == OS_WIN95) |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1382 { |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1383 /* |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1384 Another possibility is to try terminating the VDM out-right by |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1385 calling the Shell VxD (id 0x17) V86 interface, function #4 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1386 "SHELL_Destroy_VM", ie. |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1387 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1388 mov edx,4 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1389 mov ebx,vm_handle |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1390 call shellapi |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1391 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1392 First need to determine the current VM handle, and then arrange for |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1393 the shellapi call to be made from the system vm (by using |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1394 Switch_VM_and_callback). |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1395 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1396 Could try to invoke DestroyVM through CallVxD. |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1397 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1398 */ |
21613
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1399 #if 0 |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1400 /* On Win95, posting WM_QUIT causes the 16-bit subsystem |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1401 to hang when cmdproxy is used in conjunction with |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1402 command.com for an interactive shell. Posting |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1403 WM_CLOSE pops up a dialog that, when Yes is selected, |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1404 does the same thing. TerminateProcess is also less |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1405 than ideal in that subprocesses tend to stick around |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1406 until the machine is shutdown, but at least it |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1407 doesn't freeze the 16-bit subsystem. */ |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1408 PostMessage (cp->hwnd, WM_QUIT, 0xff, 0); |
21613
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1409 #endif |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1410 if (!TerminateProcess (proc_hand, 0xff)) |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1411 { |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1412 DebPrint (("sys_kill.TerminateProcess returned %d " |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1413 "for pid %lu\n", GetLastError (), pid)); |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1414 errno = EINVAL; |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1415 rc = -1; |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1416 } |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1417 } |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1418 else |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1419 #endif |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1420 PostMessage (cp->hwnd, WM_CLOSE, 0, 0); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1421 } |
16588
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16000
diff
changeset
|
1422 /* Kill the process. On W32 this doesn't kill child processes |
15351
6deee3a18ba8
(sys_kill): Don't try to terminate a DOS process.
Richard M. Stallman <rms@gnu.org>
parents:
15325
diff
changeset
|
1423 so it doesn't work very well for shells which is why it's not |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1424 used in every case. */ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1425 else if (!TerminateProcess (proc_hand, 0xff)) |
9907 | 1426 { |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1427 DebPrint (("sys_kill.TerminateProcess returned %d " |
9907 | 1428 "for pid %lu\n", GetLastError (), pid)); |
1429 errno = EINVAL; | |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1430 rc = -1; |
9907 | 1431 } |
1432 } | |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1433 |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1434 if (need_to_free) |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1435 CloseHandle (proc_hand); |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1436 |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1437 return rc; |
9907 | 1438 } |
1439 | |
21452
bd9b548fd162
Delete incorrect prototype of report_file_error.
Karl Heuer <kwzh@gnu.org>
parents:
19712
diff
changeset
|
1440 /* extern int report_file_error (char *, Lisp_Object); */ |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1441 |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1442 /* The following two routines are used to manipulate stdin, stdout, and |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1443 stderr of our child processes. |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1444 |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1445 Assuming that in, out, and err are *not* inheritable, we make them |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1446 stdin, stdout, and stderr of the child as follows: |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1447 |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1448 - Save the parent's current standard handles. |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1449 - Set the std handles to inheritable duplicates of the ones being passed in. |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1450 (Note that _get_osfhandle() is an io.h procedure that retrieves the |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1451 NT file handle for a crt file descriptor.) |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1452 - Spawn the child, which inherits in, out, and err as stdin, |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1453 stdout, and stderr. (see Spawnve) |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1454 - Close the std handles passed to the child. |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1455 - Reset the parent's standard handles to the saved handles. |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1456 (see reset_standard_handles) |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1457 We assume that the caller closes in, out, and err after calling us. */ |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1458 |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1459 void |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1460 prepare_standard_handles (int in, int out, int err, HANDLE handles[3]) |
9907 | 1461 { |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1462 HANDLE parent; |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1463 HANDLE newstdin, newstdout, newstderr; |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1464 |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1465 parent = GetCurrentProcess (); |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1466 |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1467 handles[0] = GetStdHandle (STD_INPUT_HANDLE); |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1468 handles[1] = GetStdHandle (STD_OUTPUT_HANDLE); |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1469 handles[2] = GetStdHandle (STD_ERROR_HANDLE); |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1470 |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1471 /* make inheritable copies of the new handles */ |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1472 if (!DuplicateHandle (parent, |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1473 (HANDLE) _get_osfhandle (in), |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1474 parent, |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1475 &newstdin, |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1476 0, |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1477 TRUE, |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1478 DUPLICATE_SAME_ACCESS)) |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1479 report_file_error ("Duplicating input handle for child", Qnil); |
9907 | 1480 |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1481 if (!DuplicateHandle (parent, |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1482 (HANDLE) _get_osfhandle (out), |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1483 parent, |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1484 &newstdout, |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1485 0, |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1486 TRUE, |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1487 DUPLICATE_SAME_ACCESS)) |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1488 report_file_error ("Duplicating output handle for child", Qnil); |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1489 |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1490 if (!DuplicateHandle (parent, |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1491 (HANDLE) _get_osfhandle (err), |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1492 parent, |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1493 &newstderr, |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1494 0, |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1495 TRUE, |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1496 DUPLICATE_SAME_ACCESS)) |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1497 report_file_error ("Duplicating error handle for child", Qnil); |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1498 |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1499 /* and store them as our std handles */ |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1500 if (!SetStdHandle (STD_INPUT_HANDLE, newstdin)) |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1501 report_file_error ("Changing stdin handle", Qnil); |
9907 | 1502 |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1503 if (!SetStdHandle (STD_OUTPUT_HANDLE, newstdout)) |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1504 report_file_error ("Changing stdout handle", Qnil); |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1505 |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1506 if (!SetStdHandle (STD_ERROR_HANDLE, newstderr)) |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1507 report_file_error ("Changing stderr handle", Qnil); |
9907 | 1508 } |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1509 |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1510 void |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1511 reset_standard_handles (int in, int out, int err, HANDLE handles[3]) |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1512 { |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1513 /* close the duplicated handles passed to the child */ |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1514 CloseHandle (GetStdHandle (STD_INPUT_HANDLE)); |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1515 CloseHandle (GetStdHandle (STD_OUTPUT_HANDLE)); |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1516 CloseHandle (GetStdHandle (STD_ERROR_HANDLE)); |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1517 |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1518 /* now restore parent's saved std handles */ |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1519 SetStdHandle (STD_INPUT_HANDLE, handles[0]); |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1520 SetStdHandle (STD_OUTPUT_HANDLE, handles[1]); |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1521 SetStdHandle (STD_ERROR_HANDLE, handles[2]); |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1522 } |
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1523 |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1524 void |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1525 set_process_dir (char * dir) |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1526 { |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1527 process_dir = dir; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1528 } |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1529 |
15356
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1530 #ifdef HAVE_SOCKETS |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1531 |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1532 /* To avoid problems with winsock implementations that work over dial-up |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1533 connections causing or requiring a connection to exist while Emacs is |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1534 running, Emacs no longer automatically loads winsock on startup if it |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1535 is present. Instead, it will be loaded when open-network-stream is |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1536 first called. |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1537 |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1538 To allow full control over when winsock is loaded, we provide these |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1539 two functions to dynamically load and unload winsock. This allows |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1540 dial-up users to only be connected when they actually need to use |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1541 socket services. */ |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1542 |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1543 /* From nt.c */ |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1544 extern HANDLE winsock_lib; |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1545 extern BOOL term_winsock (void); |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1546 extern BOOL init_winsock (int load_now); |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1547 |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1548 extern Lisp_Object Vsystem_name; |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1549 |
16588
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16000
diff
changeset
|
1550 DEFUN ("w32-has-winsock", Fw32_has_winsock, Sw32_has_winsock, 0, 1, 0, |
15356
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1551 "Test for presence of the Windows socket library `winsock'.\n\ |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1552 Returns non-nil if winsock support is present, nil otherwise.\n\ |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1553 \n\ |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1554 If the optional argument LOAD-NOW is non-nil, the winsock library is\n\ |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1555 also loaded immediately if not already loaded. If winsock is loaded,\n\ |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1556 the winsock local hostname is returned (since this may be different from\n\ |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1557 the value of `system-name' and should supplant it), otherwise t is\n\ |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1558 returned to indicate winsock support is present.") |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1559 (load_now) |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1560 Lisp_Object load_now; |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1561 { |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1562 int have_winsock; |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1563 |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1564 have_winsock = init_winsock (!NILP (load_now)); |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1565 if (have_winsock) |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1566 { |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1567 if (winsock_lib != NULL) |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1568 { |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1569 /* Return new value for system-name. The best way to do this |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1570 is to call init_system_name, saving and restoring the |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1571 original value to avoid side-effects. */ |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1572 Lisp_Object orig_hostname = Vsystem_name; |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1573 Lisp_Object hostname; |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1574 |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1575 init_system_name (); |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1576 hostname = Vsystem_name; |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1577 Vsystem_name = orig_hostname; |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1578 return hostname; |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1579 } |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1580 return Qt; |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1581 } |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1582 return Qnil; |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1583 } |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1584 |
16588
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16000
diff
changeset
|
1585 DEFUN ("w32-unload-winsock", Fw32_unload_winsock, Sw32_unload_winsock, |
15356
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1586 0, 0, 0, |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1587 "Unload the Windows socket library `winsock' if loaded.\n\ |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1588 This is provided to allow dial-up socket connections to be disconnected\n\ |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1589 when no longer needed. Returns nil without unloading winsock if any\n\ |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1590 socket connections still exist.") |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1591 () |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1592 { |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1593 return term_winsock () ? Qt : Qnil; |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1594 } |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1595 |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1596 #endif /* HAVE_SOCKETS */ |
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1597 |
15201
43551ec4b69d
(Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
15145
diff
changeset
|
1598 |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1599 /* Some miscellaneous functions that are Windows specific, but not GUI |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1600 specific (ie. are applicable in terminal or batch mode as well). */ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1601 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1602 /* lifted from fileio.c */ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1603 #define CORRECT_DIR_SEPS(s) \ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1604 do { if ('/' == DIRECTORY_SEP) dostounix_filename (s); \ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1605 else unixtodos_filename (s); \ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1606 } while (0) |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1607 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1608 DEFUN ("w32-short-file-name", Fw32_short_file_name, Sw32_short_file_name, 1, 1, 0, |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1609 "Return the short file name version (8.3) of the full path of FILENAME.\n\ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1610 If FILENAME does not exist, return nil.\n\ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1611 All path elements in FILENAME are converted to their short names.") |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1612 (filename) |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1613 Lisp_Object filename; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1614 { |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1615 char shortname[MAX_PATH]; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1616 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1617 CHECK_STRING (filename, 0); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1618 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1619 /* first expand it. */ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1620 filename = Fexpand_file_name (filename, Qnil); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1621 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1622 /* luckily, this returns the short version of each element in the path. */ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1623 if (GetShortPathName (XSTRING (filename)->data, shortname, MAX_PATH) == 0) |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1624 return Qnil; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1625 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1626 CORRECT_DIR_SEPS (shortname); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1627 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1628 return build_string (shortname); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1629 } |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1630 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1631 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1632 DEFUN ("w32-long-file-name", Fw32_long_file_name, Sw32_long_file_name, |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1633 1, 1, 0, |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1634 "Return the long file name version of the full path of FILENAME.\n\ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1635 If FILENAME does not exist, return nil.\n\ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1636 All path elements in FILENAME are converted to their long names.") |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1637 (filename) |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1638 Lisp_Object filename; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1639 { |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1640 char longname[ MAX_PATH ]; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1641 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1642 CHECK_STRING (filename, 0); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1643 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1644 /* first expand it. */ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1645 filename = Fexpand_file_name (filename, Qnil); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1646 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1647 if (!w32_get_long_filename (XSTRING (filename)->data, longname, MAX_PATH)) |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1648 return Qnil; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1649 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1650 CORRECT_DIR_SEPS (longname); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1651 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1652 return build_string (longname); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1653 } |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1654 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1655 DEFUN ("w32-set-process-priority", Fw32_set_process_priority, Sw32_set_process_priority, |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1656 2, 2, 0, |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1657 "Set the priority of PROCESS to PRIORITY.\n\ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1658 If PROCESS is nil, the priority of Emacs is changed, otherwise the\n\ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1659 priority of the process whose pid is PROCESS is changed.\n\ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1660 PRIORITY should be one of the symbols high, normal, or low;\n\ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1661 any other symbol will be interpreted as normal.\n\ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1662 \n\ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1663 If successful, the return value is t, otherwise nil.") |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1664 (process, priority) |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1665 Lisp_Object process, priority; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1666 { |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1667 HANDLE proc_handle = GetCurrentProcess (); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1668 DWORD priority_class = NORMAL_PRIORITY_CLASS; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1669 Lisp_Object result = Qnil; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1670 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1671 CHECK_SYMBOL (priority, 0); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1672 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1673 if (!NILP (process)) |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1674 { |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1675 DWORD pid; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1676 child_process *cp; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1677 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1678 CHECK_NUMBER (process, 0); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1679 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1680 /* Allow pid to be an internally generated one, or one obtained |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1681 externally. This is necessary because real pids on Win95 are |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1682 negative. */ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1683 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1684 pid = XINT (process); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1685 cp = find_child_pid (pid); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1686 if (cp != NULL) |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1687 pid = cp->procinfo.dwProcessId; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1688 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1689 proc_handle = OpenProcess (PROCESS_SET_INFORMATION, FALSE, pid); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1690 } |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1691 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1692 if (EQ (priority, Qhigh)) |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1693 priority_class = HIGH_PRIORITY_CLASS; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1694 else if (EQ (priority, Qlow)) |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1695 priority_class = IDLE_PRIORITY_CLASS; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1696 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1697 if (proc_handle != NULL) |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1698 { |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1699 if (SetPriorityClass (proc_handle, priority_class)) |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1700 result = Qt; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1701 if (!NILP (process)) |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1702 CloseHandle (proc_handle); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1703 } |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1704 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1705 return result; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1706 } |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1707 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1708 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1709 DEFUN ("w32-get-locale-info", Fw32_get_locale_info, Sw32_get_locale_info, 1, 2, 0, |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1710 "Return information about the Windows locale LCID.\n\ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1711 By default, return a three letter locale code which encodes the default\n\ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1712 language as the first two characters, and the country or regionial variant\n\ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1713 as the third letter. For example, ENU refers to `English (United States)',\n\ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1714 while ENC means `English (Canadian)'.\n\ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1715 \n\ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1716 If the optional argument LONGFORM is non-nil, the long form of the locale\n\ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1717 name is returned, e.g. `English (United States)' instead.\n\ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1718 \n\ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1719 If LCID (a 16-bit number) is not a valid locale, the result is nil.") |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1720 (lcid, longform) |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1721 Lisp_Object lcid, longform; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1722 { |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1723 int got_abbrev; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1724 int got_full; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1725 char abbrev_name[32] = { 0 }; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1726 char full_name[256] = { 0 }; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1727 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1728 CHECK_NUMBER (lcid, 0); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1729 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1730 if (!IsValidLocale (XINT (lcid), LCID_SUPPORTED)) |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1731 return Qnil; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1732 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1733 if (NILP (longform)) |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1734 { |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1735 got_abbrev = GetLocaleInfo (XINT (lcid), |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1736 LOCALE_SABBREVLANGNAME | LOCALE_USE_CP_ACP, |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1737 abbrev_name, sizeof (abbrev_name)); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1738 if (got_abbrev) |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1739 return build_string (abbrev_name); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1740 } |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1741 else |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1742 { |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1743 got_full = GetLocaleInfo (XINT (lcid), |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1744 LOCALE_SLANGUAGE | LOCALE_USE_CP_ACP, |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1745 full_name, sizeof (full_name)); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1746 if (got_full) |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1747 return build_string (full_name); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1748 } |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1749 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1750 return Qnil; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1751 } |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1752 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1753 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1754 DEFUN ("w32-get-current-locale-id", Fw32_get_current_locale_id, Sw32_get_current_locale_id, 0, 0, 0, |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1755 "Return Windows locale id for current locale setting.\n\ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1756 This is a numerical value; use `w32-get-locale-info' to convert to a\n\ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1757 human-readable form.") |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1758 () |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1759 { |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1760 return make_number (GetThreadLocale ()); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1761 } |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1762 |
21613
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1763 DWORD int_from_hex (char * s) |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1764 { |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1765 DWORD val = 0; |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1766 static char hex[] = "0123456789abcdefABCDEF"; |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1767 char * p; |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1768 |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1769 while (*s && (p = strchr(hex, *s)) != NULL) |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1770 { |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1771 unsigned digit = p - hex; |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1772 if (digit > 15) |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1773 digit -= 6; |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1774 val = val * 16 + digit; |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1775 s++; |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1776 } |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1777 return val; |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1778 } |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1779 |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1780 /* We need to build a global list, since the EnumSystemLocale callback |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1781 function isn't given a context pointer. */ |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1782 Lisp_Object Vw32_valid_locale_ids; |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1783 |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1784 BOOL CALLBACK enum_locale_fn (LPTSTR localeNum) |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1785 { |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1786 DWORD id = int_from_hex (localeNum); |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1787 Vw32_valid_locale_ids = Fcons (make_number (id), Vw32_valid_locale_ids); |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1788 return TRUE; |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1789 } |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1790 |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1791 DEFUN ("w32-get-valid-locale-ids", Fw32_get_valid_locale_ids, Sw32_get_valid_locale_ids, 0, 0, 0, |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1792 "Return list of all valid Windows locale ids.\n\ |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1793 Each id is a numerical value; use `w32-get-locale-info' to convert to a\n\ |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1794 human-readable form.") |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1795 () |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1796 { |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1797 Vw32_valid_locale_ids = Qnil; |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1798 |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1799 EnumSystemLocales (enum_locale_fn, LCID_SUPPORTED); |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1800 |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1801 Vw32_valid_locale_ids = Fnreverse (Vw32_valid_locale_ids); |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1802 return Vw32_valid_locale_ids; |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1803 } |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1804 |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1805 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1806 DEFUN ("w32-get-default-locale-id", Fw32_get_default_locale_id, Sw32_get_default_locale_id, 0, 1, 0, |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1807 "Return Windows locale id for default locale setting.\n\ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1808 By default, the system default locale setting is returned; if the optional\n\ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1809 parameter USERP is non-nil, the user default locale setting is returned.\n\ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1810 This is a numerical value; use `w32-get-locale-info' to convert to a\n\ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1811 human-readable form.") |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1812 (userp) |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1813 Lisp_Object userp; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1814 { |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1815 if (NILP (userp)) |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1816 return make_number (GetSystemDefaultLCID ()); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1817 return make_number (GetUserDefaultLCID ()); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1818 } |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1819 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1820 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1821 DEFUN ("w32-set-current-locale", Fw32_set_current_locale, Sw32_set_current_locale, 1, 1, 0, |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1822 "Make Windows locale LCID be the current locale setting for Emacs.\n\ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1823 If successful, the new locale id is returned, otherwise nil.") |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1824 (lcid) |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1825 Lisp_Object lcid; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1826 { |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1827 CHECK_NUMBER (lcid, 0); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1828 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1829 if (!IsValidLocale (XINT (lcid), LCID_SUPPORTED)) |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1830 return Qnil; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1831 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1832 if (!SetThreadLocale (XINT (lcid))) |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1833 return Qnil; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1834 |
21613
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1835 /* Need to set input thread locale if present. */ |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1836 if (dwWindowsThreadId) |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1837 /* Reply is not needed. */ |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1838 PostThreadMessage (dwWindowsThreadId, WM_EMACS_SETLOCALE, XINT (lcid), 0); |
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1839 |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1840 return make_number (GetThreadLocale ()); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1841 } |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1842 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1843 |
15201
43551ec4b69d
(Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
15145
diff
changeset
|
1844 syms_of_ntproc () |
43551ec4b69d
(Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
15145
diff
changeset
|
1845 { |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1846 Qhigh = intern ("high"); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1847 Qlow = intern ("low"); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1848 |
15356
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1849 #ifdef HAVE_SOCKETS |
16588
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16000
diff
changeset
|
1850 defsubr (&Sw32_has_winsock); |
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16000
diff
changeset
|
1851 defsubr (&Sw32_unload_winsock); |
15356
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1852 #endif |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1853 defsubr (&Sw32_short_file_name); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1854 defsubr (&Sw32_long_file_name); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1855 defsubr (&Sw32_set_process_priority); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1856 defsubr (&Sw32_get_locale_info); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1857 defsubr (&Sw32_get_current_locale_id); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1858 defsubr (&Sw32_get_default_locale_id); |
21613
fe4f5bfae371
(w32_executable_type): Properly cast dos_header when
Geoff Voelker <voelker@cs.washington.edu>
parents:
21452
diff
changeset
|
1859 defsubr (&Sw32_get_valid_locale_ids); |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1860 defsubr (&Sw32_set_current_locale); |
15356
1a917c5d944c
(Fwin32_has_winsock, Fwin32_unload_winsock) [HAVE_SOCKETS]: New functions.
Richard M. Stallman <rms@gnu.org>
parents:
15351
diff
changeset
|
1861 |
16588
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16000
diff
changeset
|
1862 DEFVAR_LISP ("w32-quote-process-args", &Vw32_quote_process_args, |
15201
43551ec4b69d
(Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
15145
diff
changeset
|
1863 "Non-nil enables quoting of process arguments to ensure correct parsing.\n\ |
43551ec4b69d
(Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
15145
diff
changeset
|
1864 Because Windows does not directly pass argv arrays to child processes,\n\ |
43551ec4b69d
(Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
15145
diff
changeset
|
1865 programs have to reconstruct the argv array by parsing the command\n\ |
43551ec4b69d
(Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
15145
diff
changeset
|
1866 line string. For an argument to contain a space, it must be enclosed\n\ |
43551ec4b69d
(Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
15145
diff
changeset
|
1867 in double quotes or it will be parsed as multiple arguments.\n\ |
43551ec4b69d
(Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
15145
diff
changeset
|
1868 \n\ |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1869 If the value is a character, that character will be used to escape any\n\ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1870 quote characters that appear, otherwise a suitable escape character\n\ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1871 will be chosen based on the type of the program."); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1872 Vw32_quote_process_args = Qt; |
15247
874a66251747
(Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents:
15201
diff
changeset
|
1873 |
16588
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16000
diff
changeset
|
1874 DEFVAR_LISP ("w32-start-process-show-window", |
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16000
diff
changeset
|
1875 &Vw32_start_process_show_window, |
16000
b5ecd5022991
(Vwin32_start_process_show_window): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
15419
diff
changeset
|
1876 "When nil, processes started via start-process hide their windows.\n\ |
b5ecd5022991
(Vwin32_start_process_show_window): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
15419
diff
changeset
|
1877 When non-nil, they show their window in the method of their choice."); |
16588
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16000
diff
changeset
|
1878 Vw32_start_process_show_window = Qnil; |
16000
b5ecd5022991
(Vwin32_start_process_show_window): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
15419
diff
changeset
|
1879 |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1880 DEFVAR_LISP ("w32-start-process-share-console", |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1881 &Vw32_start_process_share_console, |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1882 "When nil, processes started via start-process are given a new console.\n\ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1883 When non-nil, they share the Emacs console; this has the limitation of\n\ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1884 allowing only only DOS subprocess to run at a time (whether started directly\n\ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1885 or indirectly by Emacs), and preventing Emacs from cleanly terminating the\n\ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1886 subprocess group, but may allow Emacs to interrupt a subprocess that doesn't\n\ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1887 otherwise respond to interrupts from Emacs."); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1888 Vw32_start_process_share_console = Qnil; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1889 |
16588
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16000
diff
changeset
|
1890 DEFVAR_INT ("w32-pipe-read-delay", &Vw32_pipe_read_delay, |
15247
874a66251747
(Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents:
15201
diff
changeset
|
1891 "Forced delay before reading subprocess output.\n\ |
874a66251747
(Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents:
15201
diff
changeset
|
1892 This is done to improve the buffering of subprocess output, by\n\ |
874a66251747
(Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents:
15201
diff
changeset
|
1893 avoiding the inefficiency of frequently reading small amounts of data.\n\ |
874a66251747
(Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents:
15201
diff
changeset
|
1894 \n\ |
874a66251747
(Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents:
15201
diff
changeset
|
1895 If positive, the value is the number of milliseconds to sleep before\n\ |
874a66251747
(Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents:
15201
diff
changeset
|
1896 reading the subprocess output. If negative, the magnitude is the number\n\ |
874a66251747
(Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents:
15201
diff
changeset
|
1897 of time slices to wait (effectively boosting the priority of the child\n\ |
874a66251747
(Vwin32_pipe_read_delay): New var.
Karl Heuer <kwzh@gnu.org>
parents:
15201
diff
changeset
|
1898 process temporarily). A value of zero disables waiting entirely."); |
16588
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16000
diff
changeset
|
1899 Vw32_pipe_read_delay = 50; |
15325
5c8e4ef3137c
(Vwin32_downcase_file_names): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
15247
diff
changeset
|
1900 |
16588
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16000
diff
changeset
|
1901 DEFVAR_LISP ("w32-downcase-file-names", &Vw32_downcase_file_names, |
15325
5c8e4ef3137c
(Vwin32_downcase_file_names): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
15247
diff
changeset
|
1902 "Non-nil means convert all-upper case file names to lower case.\n\ |
5c8e4ef3137c
(Vwin32_downcase_file_names): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
15247
diff
changeset
|
1903 This applies when performing completions and file name expansion."); |
16588
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16000
diff
changeset
|
1904 Vw32_downcase_file_names = Qnil; |
19712
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1905 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1906 #if 0 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1907 DEFVAR_LISP ("w32-generate-fake-inodes", &Vw32_generate_fake_inodes, |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1908 "Non-nil means attempt to fake realistic inode values.\n\ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1909 This works by hashing the truename of files, and should detect \n\ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1910 aliasing between long and short (8.3 DOS) names, but can have\n\ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1911 false positives because of hash collisions. Note that determing\n\ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1912 the truename of a file can be slow."); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1913 Vw32_generate_fake_inodes = Qnil; |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1914 #endif |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1915 |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1916 DEFVAR_LISP ("w32-get-true-file-attributes", &Vw32_get_true_file_attributes, |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1917 "Non-nil means determine accurate link count in file-attributes.\n\ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1918 This option slows down file-attributes noticeably, so is disabled by\n\ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1919 default. Note that it is only useful for files on NTFS volumes,\n\ |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1920 where hard links are supported."); |
9a6e50f6b471
Include w32heap.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1921 Vw32_get_true_file_attributes = Qnil; |
15201
43551ec4b69d
(Vwin32_quote_process_args): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
15145
diff
changeset
|
1922 } |
15145
86a1f426871e
Include config.h after CRT headers. Include fcntl.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
1923 /* end of ntproc.c */ |