annotate src/ntproc.c @ 770:336a418893b5

[xemacs-hg @ 2002-03-08 13:33:12 by adrian] file-name-all-completions vs. completion-ignored-extensions <s5tzo2u3vsx.fsf@goedel1.math.washington.edu>
author adrian
date Fri, 08 Mar 2002 13:33:14 +0000
parents b39c14581166
children 943eaba38521
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
611
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 563
diff changeset
1 /* Old process support under MS Windows, soon to die.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2 Copyright (C) 1992, 1995 Free Software Foundation, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4 This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6 XEmacs is free software; you can redistribute it and/or modify it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 under the terms of the GNU General Public License as published by the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 Free Software Foundation; either version 2, or (at your option) any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 along with XEmacs; see the file COPYING. If not, write to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 Boston, MA 02111-1307, USA.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 Drew Bliss Oct 14, 1993
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22 Adapted from alarm.c by Tim Fleehart */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 /* Adapted for XEmacs by David Hobley <david@spook-le0.cia.com.au> */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25 /* Synced with FSF Emacs 19.34.6 by Marc Paquette <marcpa@cam.org> */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26
611
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 563
diff changeset
27 /* #### This ENTIRE file is only around because of callproc.c, which
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 563
diff changeset
28 in turn is only used in batch mode.
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 563
diff changeset
29
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 563
diff changeset
30 We only need two things to get rid of both this and callproc.c:
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 563
diff changeset
31
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 563
diff changeset
32 -- my `stderr-proc' ws, which adds support for a separate stderr
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 563
diff changeset
33 in asynch. subprocesses. (it's a feature in `old-call-process-internal'.)
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 563
diff changeset
34 -- a noninteractive event loop that supports processes.
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 563
diff changeset
35 */
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 563
diff changeset
36
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37 #include <config.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 #undef signal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 #undef wait
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 #undef spawnve
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 #undef select
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 #undef kill
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 #include <windows.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 #ifdef HAVE_A_OUT_H
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 #include <a.out.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 #include "lisp.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 #include "sysproc.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 #include "nt.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 #include "ntheap.h" /* From 19.34.6 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 #include "systime.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 #include "syssignal.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 #include "sysfile.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 #include "syswait.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 #include "buffer.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 #include "process.h"
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
58
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
59 #include "console-msw.h"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
60
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 /*#include "w32term.h"*/ /* From 19.34.6: sync in ? --marcpa */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 /* #### I'm not going to play with shit. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 #pragma warning (disable:4013 4024 4090)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 /* Control whether spawnve quotes arguments as necessary to ensure
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 correct parsing by child process. Because not all uses of spawnve
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 are careful about constructing argv arrays, we make this behavior
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 conditional (off by default). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 Lisp_Object Vwin32_quote_process_args;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 /* Control whether create_child causes the process' window to be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 hidden. The default is nil. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 Lisp_Object Vwin32_start_process_show_window;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 /* Control whether create_child causes the process to inherit Emacs'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 console window, or be given a new one of its own. The default is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 nil, to allow multiple DOS programs to run on Win95. Having separate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 consoles also allows Emacs to cleanly terminate process groups. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 Lisp_Object Vwin32_start_process_share_console;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 /* Time to sleep before reading from a subprocess output pipe - this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 avoids the inefficiency of frequently reading small amounts of data.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 This is primarily necessary for handling DOS processes on Windows 95,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 but is useful for Win32 processes on both Win95 and NT as well. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 Lisp_Object Vwin32_pipe_read_delay;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
88 /* Control whether xemacs_stat() attempts to generate fake but hopefully
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 "accurate" inode values, by hashing the absolute truenames of files.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 This should detect aliasing between long and short names, but still
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 allows the possibility of hash collisions. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 Lisp_Object Vwin32_generate_fake_inodes;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 Lisp_Object Qhigh, Qlow;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 extern Lisp_Object Vlisp_EXEC_SUFFIXES;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 #ifndef DEBUG_XEMACS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 __inline
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 void _DebPrint (const char *fmt, ...)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 #ifdef DEBUG_XEMACS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 char buf[1024];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 va_list args;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 va_start (args, fmt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 vsprintf (buf, fmt, args);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 va_end (args);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 OutputDebugString (buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
114 /* sys_signal moved to nt.c. It's now called mswindows_signal... */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 /* Defined in <process.h> which conflicts with the local copy */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 #define _P_NOWAIT 1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 /* Child process management list. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 int child_proc_count = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 child_process child_procs[ MAX_CHILDREN ];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 child_process *dead_child = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 DWORD WINAPI reader_thread (void *arg);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 /* Find an unused process slot. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 child_process *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 new_child (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 child_process *cp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 DWORD id;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 for (cp = child_procs+(child_proc_count-1); cp >= child_procs; cp--)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 if (!CHILD_ACTIVE (cp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 goto Initialize;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 if (child_proc_count == MAX_CHILDREN)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 cp = &child_procs[child_proc_count++];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 Initialize:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 xzero (*cp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 cp->fd = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 cp->pid = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 if (cp->procinfo.hProcess)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 CloseHandle(cp->procinfo.hProcess);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 cp->procinfo.hProcess = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 cp->status = STATUS_READ_ERROR;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 /* use manual reset event so that select() will function properly */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 cp->char_avail = CreateEvent (NULL, TRUE, FALSE, NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 if (cp->char_avail)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 cp->char_consumed = CreateEvent (NULL, FALSE, FALSE, NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 if (cp->char_consumed)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 cp->thrd = CreateThread (NULL, 1024, reader_thread, cp, 0, &id);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 if (cp->thrd)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 return cp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 delete_child (cp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 delete_child (child_process *cp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 /* Should not be deleting a child that is still needed. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 for (i = 0; i < MAXDESC; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 if (fd_info[i].cp == cp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 abort ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 if (!CHILD_ACTIVE (cp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 /* reap thread if necessary */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 if (cp->thrd)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 DWORD rc;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 if (GetExitCodeThread (cp->thrd, &rc) && rc == STILL_ACTIVE)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 /* let the thread exit cleanly if possible */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 cp->status = STATUS_READ_ERROR;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 SetEvent (cp->char_consumed);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 if (WaitForSingleObject (cp->thrd, 1000) != WAIT_OBJECT_0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 DebPrint (("delete_child.WaitForSingleObject (thread) failed "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 "with %lu for fd %ld\n", GetLastError (), cp->fd));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 TerminateThread (cp->thrd, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 CloseHandle (cp->thrd);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 cp->thrd = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 if (cp->char_avail)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 CloseHandle (cp->char_avail);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 cp->char_avail = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 if (cp->char_consumed)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 CloseHandle (cp->char_consumed);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 cp->char_consumed = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 /* update child_proc_count (highest numbered slot in use plus one) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 if (cp == child_procs + child_proc_count - 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 for (i = child_proc_count-1; i >= 0; i--)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 if (CHILD_ACTIVE (&child_procs[i]))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 child_proc_count = i + 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 if (i < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 child_proc_count = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 /* Find a child by pid. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 static child_process *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 find_child_pid (DWORD pid)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 child_process *cp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 for (cp = child_procs+(child_proc_count-1); cp >= child_procs; cp--)
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 638
diff changeset
230 if (CHILD_ACTIVE (cp) && pid == (DWORD) cp->pid)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 return cp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 /* Function to do blocking read of one byte, needed to implement
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 select. It is only allowed on sockets and pipes. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 _sys_read_ahead (int fd)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 child_process * cp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 int rc = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 if (fd < 0 || fd >= MAXDESC)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 return STATUS_READ_ERROR;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 cp = fd_info[fd].cp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 if (cp == NULL || cp->fd != fd || cp->status != STATUS_READ_READY)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 return STATUS_READ_ERROR;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 if ((fd_info[fd].flags & (FILE_PIPE | FILE_SOCKET)) == 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 || (fd_info[fd].flags & FILE_READ) == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 /* fd is not a pipe or socket */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 abort ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 cp->status = STATUS_READ_IN_PROGRESS;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 if (fd_info[fd].flags & FILE_PIPE)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 rc = _read (fd, &cp->chr, sizeof (char));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 /* Give subprocess time to buffer some more output for us before
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 reporting that input is available; we need this because Win95
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 connects DOS programs to pipes by making the pipe appear to be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 the normal console stdout - as a result most DOS programs will
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 write to stdout without buffering, ie. one character at a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 time. Even some Win32 programs do this - "dir" in a command
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 shell on NT is very slow if we don't do this. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271 if (rc > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 int wait = XINT (Vwin32_pipe_read_delay);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 if (wait > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 Sleep (wait);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 else if (wait < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 while (++wait <= 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 /* Yield remainder of our time slice, effectively giving a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 temporary priority boost to the child process. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 Sleep (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 if (rc == sizeof (char))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 cp->status = STATUS_READ_SUCCEEDED;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 cp->status = STATUS_READ_FAILED;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 return cp->status;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293 /* Thread proc for child process and socket reader threads. Each thread
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 is normally blocked until woken by select() to check for input by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 reading one char. When the read completes, char_avail is signalled
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 to wake up the select emulator and the thread blocks itself again. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 DWORD WINAPI
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 reader_thread (void *arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 child_process *cp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 /* Our identity */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 cp = (child_process *)arg;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 /* <matts@tibco.com> - I think the test below is wrong - we don't
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 want to wait for someone to signal char_consumed, as we haven't
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 read anything for them to consume yet! */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 if (cp == NULL ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 WaitForSingleObject (cp->char_consumed, INFINITE) != WAIT_OBJECT_0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 if (cp == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 return 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 for (;;)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 int rc;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 rc = _sys_read_ahead (cp->fd);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 /* The name char_avail is a misnomer - it really just means the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 read-ahead has completed, whether successfully or not. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 if (!SetEvent (cp->char_avail))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 DebPrint (("reader_thread.SetEvent failed with %lu for fd %ld\n",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 GetLastError (), cp->fd));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 return 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 if (rc == STATUS_READ_ERROR)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 /* We are finished, so clean up handles and set to NULL so
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 that CHILD_ACTIVE will see what is going on */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 if (cp->char_avail) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 CloseHandle (cp->char_avail);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 cp->char_avail = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 if (cp->thrd) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 CloseHandle (cp->thrd);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 cp->thrd = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346 if (cp->char_consumed) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 CloseHandle(cp->char_consumed);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 cp->char_consumed = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 if (cp->procinfo.hProcess)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 CloseHandle (cp->procinfo.hProcess);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 cp->procinfo.hProcess=NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 return 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 /* If the read died, the child has died so let the thread die */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359 if (rc == STATUS_READ_FAILED)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 /* Wait until our input is acknowledged before reading again */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 if (WaitForSingleObject (cp->char_consumed, INFINITE) != WAIT_OBJECT_0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 DebPrint (("reader_thread.WaitForSingleObject failed with "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 "%lu for fd %ld\n", GetLastError (), cp->fd));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 /* We are finished, so clean up handles and set to NULL so that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 CHILD_ACTIVE will see what is going on */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 if (cp->char_avail) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373 CloseHandle (cp->char_avail);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 cp->char_avail = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 if (cp->thrd) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 CloseHandle (cp->thrd);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378 cp->thrd = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 if (cp->char_consumed) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 CloseHandle(cp->char_consumed);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 cp->char_consumed = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 if (cp->procinfo.hProcess)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 CloseHandle (cp->procinfo.hProcess);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 cp->procinfo.hProcess=NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 /* To avoid Emacs changing directory, we just record here the directory
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 the new process should start in. This is set just before calling
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395 sys_spawnve, and is not generally valid at any other time. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 static const char * process_dir;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 static BOOL
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
399 create_child (const char *exe, char *cmdline, char *env,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400 int * pPid, child_process *cp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402 STARTUPINFO start;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 SECURITY_ATTRIBUTES sec_attrs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 SECURITY_DESCRIPTOR sec_desc;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 char dir[ MAXPATHLEN ];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 if (cp == NULL) abort ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 xzero (start);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410 start.cb = sizeof (start);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 if (NILP (Vwin32_start_process_show_window))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 start.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415 start.dwFlags = STARTF_USESTDHANDLES;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 start.wShowWindow = SW_HIDE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418 start.hStdInput = GetStdHandle (STD_INPUT_HANDLE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 start.hStdOutput = GetStdHandle (STD_OUTPUT_HANDLE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 start.hStdError = GetStdHandle (STD_ERROR_HANDLE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422 /* Explicitly specify no security */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
423 /* #### not supported under win98, but will go away */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 if (!InitializeSecurityDescriptor (&sec_desc, SECURITY_DESCRIPTOR_REVISION))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425 goto EH_Fail;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
426 /* #### not supported under win98, but will go away */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427 if (!SetSecurityDescriptorDacl (&sec_desc, TRUE, NULL, FALSE))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 goto EH_Fail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429 sec_attrs.nLength = sizeof (sec_attrs);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 sec_attrs.lpSecurityDescriptor = &sec_desc;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431 sec_attrs.bInheritHandle = FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433 strcpy (dir, process_dir);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434 unixtodos_filename (dir);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436 if (!CreateProcess (exe, cmdline, &sec_attrs, NULL, TRUE,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 (!NILP (Vwin32_start_process_share_console)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 ? CREATE_NEW_PROCESS_GROUP
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 : CREATE_NEW_CONSOLE),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440 env, dir,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441 &start, &cp->procinfo))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442 goto EH_Fail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444 cp->pid = (int) cp->procinfo.dwProcessId;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 CloseHandle (cp->procinfo.hThread);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 CloseHandle (cp->procinfo.hProcess);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448 cp->procinfo.hThread=NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449 cp->procinfo.hProcess=NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
451 /* pid must fit in a Lisp_Int */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454 *pPid = cp->pid;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 return TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 EH_Fail:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459 DebPrint (("create_child.CreateProcess failed: %ld\n", GetLastError()););
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460 return FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 merge_and_sort_env (char **envp1, char **envp2, char **new_envp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466 char **optr, **nptr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 int num;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469 nptr = new_envp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470 optr = envp1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 while (*optr)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472 *nptr++ = *optr++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473 num = optr - envp1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475 optr = envp2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 while (*optr)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 *nptr++ = *optr++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478 num += optr - envp2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
480 qsort (new_envp, num, sizeof (char*), compare_env);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482 *nptr = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485 /* When a new child process is created we need to register it in our list,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486 so intercept spawn requests. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487 int
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
488 sys_spawnve (int mode, const char *cmdname,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
489 const char * const *argv, const char *const *envp)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491 Lisp_Object program, full;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492 char *cmdline, *env, *parg, **targ;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493 int arglen, numenv;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494 int pid;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495 child_process *cp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496 int is_dos_app, is_cygnus_app;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497 int do_quoting = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
498 char escape_char = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
499 /* We pass our process ID to our children by setting up an environment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500 variable in their environment. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501 char ppid_env_var_buffer[64];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
502 char *extra_env[] = {ppid_env_var_buffer, NULL};
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503 struct gcpro gcpro1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
504
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505 /* We don't care about the other modes */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506 if (mode != _P_NOWAIT)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508 errno = EINVAL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509 return -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512 /* Handle executable names without an executable suffix. */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
513 program = build_string (cmdname);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514 GCPRO1 (program);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515 if (NILP (Ffile_executable_p (program)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517 full = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518 locate_file (Vexec_path, program, Vlisp_EXEC_SUFFIXES, &full, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519 if (NILP (full))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
521 UNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522 errno = EINVAL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523 return -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524 }
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 432
diff changeset
525 TO_EXTERNAL_FORMAT (LISP_STRING, full,
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 432
diff changeset
526 C_STRING_ALLOCA, cmdname,
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 432
diff changeset
527 Qfile_name);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
531 cmdname = (char*)alloca (strlen (argv[0]) + 1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532 strcpy ((char*)cmdname, argv[0]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534 UNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536 /* make sure argv[0] and cmdname are both in DOS format */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537 unixtodos_filename ((char*)cmdname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538 /* #### KLUDGE */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
539 ((const char**)argv)[0] = cmdname;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541 /* Determine whether program is a 16-bit DOS executable, or a Win32
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542 executable that is implicitly linked to the Cygnus dll (implying it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543 was compiled with the Cygnus GNU toolchain and hence relies on
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 cygwin.dll to parse the command line - we use this to decide how to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545 escape quote chars in command line args that must be quoted). */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
546 mswindows_executable_type (cmdname, &is_dos_app, &is_cygnus_app);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548 /* On Windows 95, if cmdname is a DOS app, we invoke a helper
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549 application to start it by specifying the helper app as cmdname,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550 while leaving the real app name as argv[0]. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551 if (is_dos_app)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
553 cmdname = (char*) alloca (MAXPATHLEN);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
554 if (egetenv ("CMDPROXY"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
555 strcpy ((char*)cmdname, egetenv ("CMDPROXY"));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
556 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
557 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
558 strcpy ((char*)cmdname, XSTRING_DATA (Vinvocation_directory));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
559 strcat ((char*)cmdname, "cmdproxy.exe");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561 unixtodos_filename ((char*)cmdname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
563
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564 /* we have to do some conjuring here to put argv and envp into the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
565 form CreateProcess wants... argv needs to be a space separated/null
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
566 terminated list of parameters, and envp is a null
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
567 separated/double-null terminated list of parameters.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
568
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
569 Additionally, zero-length args and args containing whitespace or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
570 quote chars need to be wrapped in double quotes - for this to work,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
571 embedded quotes need to be escaped as well. The aim is to ensure
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572 the child process reconstructs the argv array we start with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
573 exactly, so we treat quotes at the beginning and end of arguments
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
574 as embedded quotes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
575
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
576 The Win32 GNU-based library from Cygnus doubles quotes to escape
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
577 them, while MSVC uses backslash for escaping. (Actually the MSVC
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
578 startup code does attempt to recognize doubled quotes and accept
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579 them, but gets it wrong and ends up requiring three quotes to get a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
580 single embedded quote!) So by default we decide whether to use
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
581 quote or backslash as the escape character based on whether the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
582 binary is apparently a Cygnus compiled app.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
583
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584 Note that using backslash to escape embedded quotes requires
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585 additional special handling if an embedded quote is already
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586 preceded by backslash, or if an arg requiring quoting ends with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587 backslash. In such cases, the run of escape characters needs to be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588 doubled. For consistency, we apply this special handling as long
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589 as the escape character is not quote.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
590
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591 Since we have no idea how large argv and envp are likely to be we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
592 figure out list lengths on the fly and allocate them. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
593
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
594 if (!NILP (Vwin32_quote_process_args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
595 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
596 do_quoting = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
597 /* Override escape char by binding win32-quote-process-args to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598 desired character, or use t for auto-selection. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599 if (INTP (Vwin32_quote_process_args))
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
600 escape_char = (char) XINT (Vwin32_quote_process_args);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602 escape_char = is_cygnus_app ? '"' : '\\';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605 /* do argv... */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606 arglen = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607 targ = (char**)argv;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608 while (*targ)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610 char * p = *targ;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611 int need_quotes = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612 int escape_char_run = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
613
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
614 if (*p == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615 need_quotes = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
616 for ( ; *p; p++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
617 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
618 if (*p == '"')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
619 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
620 /* allow for embedded quotes to be escaped */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
621 arglen++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
622 need_quotes = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
623 /* handle the case where the embedded quote is already escaped */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624 if (escape_char_run > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
625 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626 /* To preserve the arg exactly, we need to double the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
627 preceding escape characters (plus adding one to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
628 escape the quote character itself). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
629 arglen += escape_char_run;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
630 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
631 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
632 else if (*p == ' ' || *p == '\t')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
633 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
634 need_quotes = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
635 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
636
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
637 if (*p == escape_char && escape_char != '"')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
638 escape_char_run++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
639 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
640 escape_char_run = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
641 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
642 if (need_quotes)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
644 arglen += 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
645 /* handle the case where the arg ends with an escape char - we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
646 must not let the enclosing quote be escaped. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
647 if (escape_char_run > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
648 arglen += escape_char_run;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
649 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
650 arglen += strlen (*targ++) + 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
651 }
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
652 cmdline = (char*) alloca (arglen);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
653 targ = (char**)argv;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
654 parg = cmdline;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
655 while (*targ)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
656 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
657 char * p = *targ;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
658 int need_quotes = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
659
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
660 if (*p == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661 need_quotes = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
663 if (do_quoting)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
665 for ( ; *p; p++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
666 if (*p == ' ' || *p == '\t' || *p == '"')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
667 need_quotes = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
668 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
669 if (need_quotes)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
670 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
671 int escape_char_run = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
672 char * first;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673 char * last;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
674
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
675 p = *targ;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
676 first = p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
677 last = p + strlen (p) - 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
678 *parg++ = '"';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
679 #if 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
680 /* This version does not escape quotes if they occur at the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
681 beginning or end of the arg - this could lead to incorrect
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
682 behavior when the arg itself represents a command line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
683 containing quoted args. I believe this was originally done
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
684 as a hack to make some things work, before
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
685 `win32-quote-process-args' was added. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
686 while (*p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
687 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
688 if (*p == '"' && p > first && p < last)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
689 *parg++ = escape_char; /* escape embedded quotes */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
690 *parg++ = *p++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
691 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
692 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
693 for ( ; *p; p++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
694 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
695 if (*p == '"')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
696 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
697 /* double preceding escape chars if any */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
698 while (escape_char_run > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
699 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
700 *parg++ = escape_char;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
701 escape_char_run--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
702 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
703 /* escape all quote chars, even at beginning or end */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
704 *parg++ = escape_char;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
705 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
706 *parg++ = *p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
707
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
708 if (*p == escape_char && escape_char != '"')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
709 escape_char_run++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
710 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
711 escape_char_run = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
712 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
713 /* double escape chars before enclosing quote */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
714 while (escape_char_run > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
715 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
716 *parg++ = escape_char;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
717 escape_char_run--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
718 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
719 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
720 *parg++ = '"';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
721 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
722 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
723 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
724 strcpy (parg, *targ);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
725 parg += strlen (*targ);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
726 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
727 *parg++ = ' ';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
728 targ++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
729 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
730 *--parg = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
731
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
732 /* and envp... */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
733 arglen = 1;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
734 targ = (char**) envp;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
735 numenv = 1; /* for end null */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
736 while (*targ)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
737 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
738 arglen += strlen (*targ++) + 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
739 numenv++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
740 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
741 /* extra env vars... */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
742 sprintf (ppid_env_var_buffer, "__PARENT_PROCESS_ID=%d",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
743 GetCurrentProcessId ());
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
744 arglen += strlen (ppid_env_var_buffer) + 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
745 numenv++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
746
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
747 /* merge env passed in and extra env into one, and sort it. */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
748 targ = (char **) alloca (numenv * sizeof (char*));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
749 merge_and_sort_env ((char**) envp, extra_env, targ);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
750
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
751 /* concatenate env entries. */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
752 env = (char*) alloca (arglen);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
753 parg = env;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
754 while (*targ)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
755 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
756 strcpy (parg, *targ);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
757 parg += strlen (*targ++);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
758 *parg++ = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
759 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
760 *parg++ = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
761 *parg = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
762
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
763 cp = new_child ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
764 if (cp == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
765 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
766 errno = EAGAIN;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
767 return -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
768 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
769
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
770 /* Now create the process. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
771 if (!create_child (cmdname, cmdline, env, &pid, cp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
772 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
773 delete_child (cp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
774 errno = ENOEXEC;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
775 return -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
776 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
777
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
778 return pid;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
779 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
780
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
781 /* Substitute for certain kill () operations */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
782
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
783 static BOOL CALLBACK
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
784 find_child_console (HWND hwnd, child_process * cp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
785 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
786 DWORD thread_id;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
787 DWORD process_id;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
788
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
789 thread_id = GetWindowThreadProcessId (hwnd, &process_id);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
790 if (process_id == cp->procinfo.dwProcessId)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
791 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
792 char window_class[32];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
793
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
794 GetClassName (hwnd, window_class, sizeof (window_class));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
795 if (strcmp (window_class,
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
796 mswindows_windows9x_p()
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
797 ? "tty"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
798 : "ConsoleWindowClass") == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
799 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
800 cp->hwnd = hwnd;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
801 return FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
802 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
803 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
804 /* keep looking */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
805 return TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
806 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
807
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
808 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
809 sys_kill (int pid, int sig)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
810 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
811 child_process *cp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
812 HANDLE proc_hand;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
813 int need_to_free = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
814 int rc = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
815
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
816 /* Only handle signals that will result in the process dying */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
817 if (sig != SIGINT && sig != SIGKILL && sig != SIGQUIT && sig != SIGHUP)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
818 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
819 errno = EINVAL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
820 return -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
821 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
822
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
823 cp = find_child_pid (pid);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
824 if (cp == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
825 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
826 proc_hand = OpenProcess (PROCESS_TERMINATE, 0, pid);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
827 if (proc_hand == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
828 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
829 errno = EPERM;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
830 return -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
831 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
832 need_to_free = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
833 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
834 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
835 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
836 proc_hand = cp->procinfo.hProcess;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
837 pid = cp->procinfo.dwProcessId;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
838
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
839 /* Try to locate console window for process. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
840 EnumWindows ((WNDENUMPROC)find_child_console, (LPARAM) cp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
841 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
842
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
843 if (sig == SIGINT)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
844 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
845 if (NILP (Vwin32_start_process_share_console) && cp && cp->hwnd)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
846 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
847 BYTE control_scan_code = (BYTE) MapVirtualKey (VK_CONTROL, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
848 BYTE vk_break_code = VK_CANCEL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
849 BYTE break_scan_code = (BYTE) MapVirtualKey (vk_break_code, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
850 HWND foreground_window;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
851
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
852 if (break_scan_code == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
853 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
854 /* Fake Ctrl-C if we can't manage Ctrl-Break. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
855 vk_break_code = 'C';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
856 break_scan_code = (BYTE) MapVirtualKey (vk_break_code, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
857 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
858
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
859 foreground_window = GetForegroundWindow ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
860 if (foreground_window && SetForegroundWindow (cp->hwnd))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
861 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
862 /* Generate keystrokes as if user had typed Ctrl-Break or Ctrl-C. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
863 keybd_event (VK_CONTROL, control_scan_code, 0, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
864 keybd_event (vk_break_code, break_scan_code, 0, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
865 keybd_event (vk_break_code, break_scan_code, KEYEVENTF_KEYUP, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
866 keybd_event (VK_CONTROL, control_scan_code, KEYEVENTF_KEYUP, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
867
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
868 /* Sleep for a bit to give time for Emacs frame to respond
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
869 to focus change events (if Emacs was active app). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
870 Sleep (10);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
871
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
872 SetForegroundWindow (foreground_window);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
873 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
874 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
875 /* Ctrl-Break is NT equivalent of SIGINT. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
876 else if (!GenerateConsoleCtrlEvent (CTRL_BREAK_EVENT, pid))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
877 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
878 DebPrint (("sys_kill.GenerateConsoleCtrlEvent return %d "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
879 "for pid %lu\n", GetLastError (), pid));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
880 errno = EINVAL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
881 rc = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
882 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
883 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
884 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
885 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
886 if (NILP (Vwin32_start_process_share_console) && cp && cp->hwnd)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
887 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
888 #if 1
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
889 if (mswindows_windows9x_p())
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
890 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
891 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
892 Another possibility is to try terminating the VDM out-right by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
893 calling the Shell VxD (id 0x17) V86 interface, function #4
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
894 "SHELL_Destroy_VM", ie.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
895
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
896 mov edx,4
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
897 mov ebx,vm_handle
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
898 call shellapi
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
899
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
900 First need to determine the current VM handle, and then arrange for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
901 the shellapi call to be made from the system vm (by using
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
902 Switch_VM_and_callback).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
903
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
904 Could try to invoke DestroyVM through CallVxD.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
905
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
906 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
907 #if 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
908 /* On Win95, posting WM_QUIT causes the 16-bit subsystem
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
909 to hang when cmdproxy is used in conjunction with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
910 command.com for an interactive shell. Posting
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
911 WM_CLOSE pops up a dialog that, when Yes is selected,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
912 does the same thing. TerminateProcess is also less
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
913 than ideal in that subprocesses tend to stick around
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
914 until the machine is shutdown, but at least it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
915 doesn't freeze the 16-bit subsystem. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
916 PostMessage (cp->hwnd, WM_QUIT, 0xff, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
917 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
918 if (!TerminateProcess (proc_hand, 0xff))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
919 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
920 DebPrint (("sys_kill.TerminateProcess returned %d "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
921 "for pid %lu\n", GetLastError (), pid));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
922 errno = EINVAL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
923 rc = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
924 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
925 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
926 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
927 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
928 PostMessage (cp->hwnd, WM_CLOSE, 0, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
929 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
930 /* Kill the process. On Win32 this doesn't kill child processes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
931 so it doesn't work very well for shells which is why it's not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
932 used in every case. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
933 else if (!TerminateProcess (proc_hand, 0xff))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
934 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
935 DebPrint (("sys_kill.TerminateProcess returned %d "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
936 "for pid %lu\n", GetLastError (), pid));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
937 errno = EINVAL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
938 rc = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
939 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
940 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
941
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
942 if (need_to_free)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
943 CloseHandle (proc_hand);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
944
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
945 return rc;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
946 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
947
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
948 /* The following two routines are used to manipulate stdin, stdout, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
949 stderr of our child processes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
950
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
951 Assuming that in, out, and err are *not* inheritable, we make them
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
952 stdin, stdout, and stderr of the child as follows:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
953
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
954 - Save the parent's current standard handles.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
955 - Set the std handles to inheritable duplicates of the ones being passed in.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
956 (Note that _get_osfhandle() is an io.h procedure that retrieves the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
957 NT file handle for a crt file descriptor.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
958 - Spawn the child, which inherits in, out, and err as stdin,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
959 stdout, and stderr. (see Spawnve)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
960 - Close the std handles passed to the child.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
961 - Reset the parent's standard handles to the saved handles.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
962 (see reset_standard_handles)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
963 We assume that the caller closes in, out, and err after calling us. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
964
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
965 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
966 prepare_standard_handles (int in, int out, int err, HANDLE handles[3])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
967 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
968 HANDLE parent;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
969 HANDLE newstdin, newstdout, newstderr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
970
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
971 parent = GetCurrentProcess ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
972
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
973 handles[0] = GetStdHandle (STD_INPUT_HANDLE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
974 handles[1] = GetStdHandle (STD_OUTPUT_HANDLE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
975 handles[2] = GetStdHandle (STD_ERROR_HANDLE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
976
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
977 /* make inheritable copies of the new handles */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
978 if (!DuplicateHandle (parent,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
979 (HANDLE) _get_osfhandle (in),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
980 parent,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
981 &newstdin,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
982 0,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
983 TRUE,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
984 DUPLICATE_SAME_ACCESS))
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 558
diff changeset
985 mswindows_report_process_error ("Duplicating input handle for child",
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 558
diff changeset
986 Qunbound, GetLastError ());
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
987
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
988 if (!DuplicateHandle (parent,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
989 (HANDLE) _get_osfhandle (out),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
990 parent,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
991 &newstdout,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
992 0,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
993 TRUE,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
994 DUPLICATE_SAME_ACCESS))
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 558
diff changeset
995 mswindows_report_process_error ("Duplicating output handle for child",
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 558
diff changeset
996 Qunbound, GetLastError ());
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
997
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
998 if (!DuplicateHandle (parent,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
999 (HANDLE) _get_osfhandle (err),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1000 parent,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1001 &newstderr,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1002 0,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1003 TRUE,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1004 DUPLICATE_SAME_ACCESS))
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 558
diff changeset
1005 mswindows_report_process_error ("Duplicating error handle for child",
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 558
diff changeset
1006 Qunbound, GetLastError ());
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1007
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1008 /* and store them as our std handles */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1009 if (!SetStdHandle (STD_INPUT_HANDLE, newstdin))
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 558
diff changeset
1010 mswindows_report_process_error ("Changing stdin handle",
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 558
diff changeset
1011 Qunbound, GetLastError ());
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1012
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1013 if (!SetStdHandle (STD_OUTPUT_HANDLE, newstdout))
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 558
diff changeset
1014 mswindows_report_process_error ("Changing stdout handle",
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 558
diff changeset
1015 Qunbound, GetLastError ());
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1016
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1017 if (!SetStdHandle (STD_ERROR_HANDLE, newstderr))
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 558
diff changeset
1018 mswindows_report_process_error ("Changing stderr handle",
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 558
diff changeset
1019 Qunbound, GetLastError ());
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1020 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1021
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1022 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1023 reset_standard_handles (int in, int out, int err, HANDLE handles[3])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1024 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1025 /* close the duplicated handles passed to the child */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1026 CloseHandle (GetStdHandle (STD_INPUT_HANDLE));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1027 CloseHandle (GetStdHandle (STD_OUTPUT_HANDLE));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1028 CloseHandle (GetStdHandle (STD_ERROR_HANDLE));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1029
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1030 /* now restore parent's saved std handles */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1031 SetStdHandle (STD_INPUT_HANDLE, handles[0]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1032 SetStdHandle (STD_OUTPUT_HANDLE, handles[1]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1033 SetStdHandle (STD_ERROR_HANDLE, handles[2]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1034 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1035
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1036 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1037 set_process_dir (const char * dir)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1038 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1039 process_dir = dir;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1040 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1041
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1042 /* Some miscellaneous functions that are Windows specific, but not GUI
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1043 specific (ie. are applicable in terminal or batch mode as well). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1044
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1045 DEFUN ("win32-short-file-name", Fwin32_short_file_name, 1, 1, "", /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1046 Return the short file name version (8.3) of the full path of FILENAME.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1047 If FILENAME does not exist, return nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1048 All path elements in FILENAME are converted to their short names.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1049 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1050 (filename))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1051 {
558
ed498ef2108b [xemacs-hg @ 2001-05-23 09:59:33 by ben]
ben
parents: 442
diff changeset
1052 char shortname[PATH_MAX];
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1053
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1054 CHECK_STRING (filename);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1055
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1056 /* first expand it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1057 filename = Fexpand_file_name (filename, Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1058
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1059 /* luckily, this returns the short version of each element in the path. */
558
ed498ef2108b [xemacs-hg @ 2001-05-23 09:59:33 by ben]
ben
parents: 442
diff changeset
1060 if (GetShortPathName (XSTRING_DATA (filename), shortname, PATH_MAX) == 0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1061 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1062
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1063 CORRECT_DIR_SEPS (shortname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1064
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1065 return build_string (shortname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1066 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1067
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1068
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1069 DEFUN ("win32-long-file-name", Fwin32_long_file_name, 1, 1, "", /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1070 Return the long file name version of the full path of FILENAME.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1071 If FILENAME does not exist, return nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1072 All path elements in FILENAME are converted to their long names.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1073 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1074 (filename))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1075 {
558
ed498ef2108b [xemacs-hg @ 2001-05-23 09:59:33 by ben]
ben
parents: 442
diff changeset
1076 char longname[ PATH_MAX ];
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1077
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1078 CHECK_STRING (filename);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1079
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1080 /* first expand it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1081 filename = Fexpand_file_name (filename, Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1082
558
ed498ef2108b [xemacs-hg @ 2001-05-23 09:59:33 by ben]
ben
parents: 442
diff changeset
1083 if (!win32_get_long_filename (XSTRING_DATA (filename), longname, PATH_MAX))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1084 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1085
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1086 CORRECT_DIR_SEPS (longname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1087
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1088 return build_string (longname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1089 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1090
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1091 DEFUN ("win32-set-process-priority", Fwin32_set_process_priority, 2, 2, "", /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1092 Set the priority of PROCESS to PRIORITY.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1093 If PROCESS is nil, the priority of Emacs is changed, otherwise the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1094 priority of the process whose pid is PROCESS is changed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1095 PRIORITY should be one of the symbols high, normal, or low;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1096 any other symbol will be interpreted as normal.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1097
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1098 If successful, the return value is t, otherwise nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1099 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1100 (process, priority))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1101 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1102 HANDLE proc_handle = GetCurrentProcess ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1103 DWORD priority_class = NORMAL_PRIORITY_CLASS;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1104 Lisp_Object result = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1105
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1106 CHECK_SYMBOL (priority);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1107
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1108 if (!NILP (process))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1109 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1110 DWORD pid;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1111 child_process *cp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1112
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1113 CHECK_INT (process);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1114
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1115 /* Allow pid to be an internally generated one, or one obtained
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1116 externally. This is necessary because real pids on Win95 are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1117 negative. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1118
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1119 pid = XINT (process);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1120 cp = find_child_pid (pid);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1121 if (cp != NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1122 pid = cp->procinfo.dwProcessId;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1123
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1124 proc_handle = OpenProcess (PROCESS_SET_INFORMATION, FALSE, pid);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1125 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1126
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1127 if (EQ (priority, Qhigh))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1128 priority_class = HIGH_PRIORITY_CLASS;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1129 else if (EQ (priority, Qlow))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1130 priority_class = IDLE_PRIORITY_CLASS;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1131
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1132 if (proc_handle != NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1133 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1134 if (SetPriorityClass (proc_handle, priority_class))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1135 result = Qt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1136 if (!NILP (process))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1137 CloseHandle (proc_handle);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1138 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1139
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1140 return result;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1141 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1142
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1143
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1144 DEFUN ("win32-get-locale-info", Fwin32_get_locale_info, 1, 2, "", /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1145 "Return information about the Windows locale LCID.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1146 By default, return a three letter locale code which encodes the default
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1147 language as the first two characters, and the country or regional variant
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1148 as the third letter. For example, ENU refers to `English (United States)',
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1149 while ENC means `English (Canadian)'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1150
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1151 If the optional argument LONGFORM is non-nil, the long form of the locale
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1152 name is returned, e.g. `English (United States)' instead.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1153
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1154 If LCID (a 16-bit number) is not a valid locale, the result is nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1155 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1156 (lcid, longform))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1157 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1158 int got_abbrev;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1159 int got_full;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1160 char abbrev_name[32] = { 0 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1161 char full_name[256] = { 0 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1162
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1163 CHECK_INT (lcid);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1164
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1165 if (!IsValidLocale (XINT (lcid), LCID_SUPPORTED))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1166 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1167
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1168 if (NILP (longform))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1169 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1170 got_abbrev = GetLocaleInfo (XINT (lcid),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1171 LOCALE_SABBREVLANGNAME | LOCALE_USE_CP_ACP,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1172 abbrev_name, sizeof (abbrev_name));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1173 if (got_abbrev)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1174 return build_string (abbrev_name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1175 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1176 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1177 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1178 got_full = GetLocaleInfo (XINT (lcid),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1179 LOCALE_SLANGUAGE | LOCALE_USE_CP_ACP,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1180 full_name, sizeof (full_name));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1181 if (got_full)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1182 return build_string (full_name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1183 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1184
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1185 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1186 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1187
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1188
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1189 DEFUN ("win32-get-current-locale-id", Fwin32_get_current_locale_id, 0, 0, "", /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1190 "Return Windows locale id for current locale setting.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1191 This is a numerical value; use `win32-get-locale-info' to convert to a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1192 human-readable form.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1193 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1194 ())
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1195 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1196 return make_int (GetThreadLocale ());
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1197 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1198
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1199
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1200 DEFUN ("win32-get-default-locale-id", Fwin32_get_default_locale_id, 0, 1, "", /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1201 "Return Windows locale id for default locale setting.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1202 By default, the system default locale setting is returned; if the optional
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1203 parameter USERP is non-nil, the user default locale setting is returned.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1204 This is a numerical value; use `win32-get-locale-info' to convert to a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1205 human-readable form.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1206 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1207 (userp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1208 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1209 if (NILP (userp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1210 return make_int (GetSystemDefaultLCID ());
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1211 return make_int (GetUserDefaultLCID ());
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1212 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1213
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1214 DWORD int_from_hex (char * s)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1215 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1216 DWORD val = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1217 static char hex[] = "0123456789abcdefABCDEF";
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1218 char * p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1219
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1220 while (*s && (p = strchr(hex, *s)) != NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1221 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1222 unsigned digit = p - hex;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1223 if (digit > 15)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1224 digit -= 6;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1225 val = val * 16 + digit;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1226 s++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1227 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1228 return val;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1229 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1230
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1231 /* We need to build a global list, since the EnumSystemLocale callback
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1232 function isn't given a context pointer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1233 Lisp_Object Vwin32_valid_locale_ids;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1234
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1235 BOOL CALLBACK enum_locale_fn (LPTSTR localeNum)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1236 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1237 DWORD id = int_from_hex (localeNum);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1238 Vwin32_valid_locale_ids = Fcons (make_int (id), Vwin32_valid_locale_ids);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1239 return TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1240 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1241
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1242 DEFUN ("win32-get-valid-locale-ids", Fwin32_get_valid_locale_ids, 0, 0, "", /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1243 Return list of all valid Windows locale ids.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1244 Each id is a numerical value; use `win32-get-locale-info' to convert to a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1245 human-readable form.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1246 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1247 ())
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1248 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1249 Vwin32_valid_locale_ids = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1250
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1251 EnumSystemLocales (enum_locale_fn, LCID_SUPPORTED);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1252
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1253 Vwin32_valid_locale_ids = Fnreverse (Vwin32_valid_locale_ids);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1254 return Vwin32_valid_locale_ids;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1255 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1256
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1257
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1258 DEFUN ("win32-set-current-locale", Fwin32_set_current_locale, 1, 1, "", /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1259 Make Windows locale LCID be the current locale setting for Emacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1260 If successful, the new locale id is returned, otherwise nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1261 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1262 (lcid))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1263 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1264 CHECK_INT (lcid);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1265
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1266 if (!IsValidLocale (XINT (lcid), LCID_SUPPORTED))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1267 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1268
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1269 /* #### not supported under win98, but will go away */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1270 if (!SetThreadLocale (XINT (lcid)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1271 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1272
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1273 /* Sync with FSF Emacs 19.34.6 note: dwWinThreadId declared in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1274 w32term.h and defined in w32fns.c, both of which are not in current
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 432
diff changeset
1275 XEmacs. #### Check what we lose by ifdef'ing out these. --marcpa */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1276 #if 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1277 /* Need to set input thread locale if present. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1278 if (dwWinThreadId)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1279 /* Reply is not needed. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1280 PostThreadMessage (dwWinThreadId, WM_EMACS_SETLOCALE, XINT (lcid), 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1281 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1282
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1283 return make_int (GetThreadLocale ());
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1284 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1285
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1286
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1287 void
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1288 syms_of_ntproc (void)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1289 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1290 DEFSUBR (Fwin32_short_file_name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1291 DEFSUBR (Fwin32_long_file_name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1292 DEFSUBR (Fwin32_set_process_priority);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1293 DEFSUBR (Fwin32_get_locale_info);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1294 DEFSUBR (Fwin32_get_current_locale_id);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1295 DEFSUBR (Fwin32_get_default_locale_id);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1296 DEFSUBR (Fwin32_get_valid_locale_ids);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1297 DEFSUBR (Fwin32_set_current_locale);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1298 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1299
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1300
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1301 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1302 vars_of_ntproc (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1303 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 558
diff changeset
1304 DEFSYMBOL (Qhigh);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 558
diff changeset
1305 DEFSYMBOL (Qlow);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1306
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1307 DEFVAR_LISP ("win32-quote-process-args", &Vwin32_quote_process_args /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1308 Non-nil enables quoting of process arguments to ensure correct parsing.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1309 Because Windows does not directly pass argv arrays to child processes,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1310 programs have to reconstruct the argv array by parsing the command
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1311 line string. For an argument to contain a space, it must be enclosed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1312 in double quotes or it will be parsed as multiple arguments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1313
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1314 If the value is a character, that character will be used to escape any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1315 quote characters that appear, otherwise a suitable escape character
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1316 will be chosen based on the type of the program.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1317 */ );
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1318 Vwin32_quote_process_args = Qt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1319
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1320 DEFVAR_LISP ("win32-start-process-show-window",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1321 &Vwin32_start_process_show_window /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1322 When nil, processes started via start-process hide their windows.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1323 When non-nil, they show their window in the method of their choice.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1324 */ );
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1325 Vwin32_start_process_show_window = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1326
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1327 DEFVAR_LISP ("win32-start-process-share-console",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1328 &Vwin32_start_process_share_console /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1329 When nil, processes started via start-process are given a new console.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1330 When non-nil, they share the Emacs console; this has the limitation of
638
373ced43e288 [xemacs-hg @ 2001-07-26 21:10:44 by adrian]
adrian
parents: 611
diff changeset
1331 allowing only one DOS subprocess to run at a time (whether started directly
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1332 or indirectly by Emacs), and preventing Emacs from cleanly terminating the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1333 subprocess group, but may allow Emacs to interrupt a subprocess that doesn't
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1334 otherwise respond to interrupts from Emacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1335 */ );
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1336 Vwin32_start_process_share_console = Qt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1337
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1338 DEFVAR_LISP ("win32-pipe-read-delay", &Vwin32_pipe_read_delay /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1339 Forced delay before reading subprocess output.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1340 This is done to improve the buffering of subprocess output, by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1341 avoiding the inefficiency of frequently reading small amounts of data.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1342
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1343 If positive, the value is the number of milliseconds to sleep before
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1344 reading the subprocess output. If negative, the magnitude is the number
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1345 of time slices to wait (effectively boosting the priority of the child
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1346 process temporarily). A value of zero disables waiting entirely.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1347 */ );
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1348 Vwin32_pipe_read_delay = make_int (50);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1349
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1350 #if 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1351 DEFVAR_LISP ("win32-generate-fake-inodes", &Vwin32_generate_fake_inodes /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1352 "Non-nil means attempt to fake realistic inode values.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1353 This works by hashing the truename of files, and should detect
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1354 aliasing between long and short (8.3 DOS) names, but can have
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1355 false positives because of hash collisions. Note that determining
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1356 the truename of a file can be slow.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1357 */ );
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1358 Vwin32_generate_fake_inodes = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1359 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1360 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1361
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1362 /* end of ntproc.c */