annotate src/ntproc.c @ 209:41ff10fd062f r20-4b3

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