annotate src/ntproc.c @ 786:381a409ad3c3

[xemacs-hg @ 2002-03-20 10:15:58 by ben] add japanese 0213 from mule-ucs
author ben
date Wed, 20 Mar 2002 10:15:59 +0000
parents 943eaba38521
children a5954632b187
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.
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
3 Copyright (C) 2001 Ben Wing.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5 This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 XEmacs is free software; you can redistribute it and/or modify it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 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
9 Free Software Foundation; either version 2, or (at your option) any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10 later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12 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
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 along with XEmacs; see the file COPYING. If not, write to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20 Boston, MA 02111-1307, USA.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22 Drew Bliss Oct 14, 1993
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 Adapted from alarm.c by Tim Fleehart */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25 /* Adapted for XEmacs by David Hobley <david@spook-le0.cia.com.au> */
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
26 /* Synced with FSF Emacs 19.34.6 by Marc Paquette <marcpa@cam.org>
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
27 (Note: Sync messages from Marc Paquette may indicate
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
28 incomplete synching, so beware.)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
29 */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
30
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
31 /* !!#### This piece of crap is not getting Mule-ized. It will go away
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
32 as soon as my process-stderr patches go in and there are a few stream
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
33 device fixes, so my new call-process-written-using-start-process can
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
34 always work. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35
611
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 563
diff changeset
36 /* #### 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
37 in turn is only used in batch mode.
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 563
diff changeset
38
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 563
diff changeset
39 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
40
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 563
diff changeset
41 -- 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
42 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
43 -- a noninteractive event loop that supports processes.
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 563
diff changeset
44 */
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
45 #include <config.h>
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
46 #include "lisp.h"
611
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 563
diff changeset
47
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
48 #include "buffer.h"
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
49 #include "console-msw.h"
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
50 #include "process.h"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 #ifdef HAVE_A_OUT_H
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 #include <a.out.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 #endif
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
55 #include "sysfile.h"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 #include "sysproc.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 #include "syssignal.h"
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
58 #include "systime.h"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 #include "syswait.h"
442
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 /* #### I'm not going to play with shit. */
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
63 // #pragma warning (disable:4013 4024 4090)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 /* Control whether spawnve quotes arguments as necessary to ensure
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 correct parsing by child process. Because not all uses of spawnve
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 are careful about constructing argv arrays, we make this behavior
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 conditional (off by default). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 Lisp_Object Vwin32_quote_process_args;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 /* Control whether create_child causes the process' window to be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 hidden. The default is nil. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 Lisp_Object Vwin32_start_process_show_window;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 /* Control whether create_child causes the process to inherit Emacs'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 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
77 nil, to allow multiple DOS programs to run on Win95. Having separate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 consoles also allows Emacs to cleanly terminate process groups. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 Lisp_Object Vwin32_start_process_share_console;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 /* Time to sleep before reading from a subprocess output pipe - this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 avoids the inefficiency of frequently reading small amounts of data.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 This is primarily necessary for handling DOS processes on Windows 95,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 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
85 Lisp_Object Vwin32_pipe_read_delay;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
87 extern Lisp_Object Vlisp_EXEC_SUFFIXES;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
88
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
89 /* child_process.status values */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
90 enum {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
91 STATUS_READ_ERROR = -1,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
92 STATUS_READ_READY,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
93 STATUS_READ_IN_PROGRESS,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
94 STATUS_READ_FAILED,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
95 STATUS_READ_SUCCEEDED,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
96 STATUS_READ_ACKNOWLEDGED
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
97 };
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
98
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
99 /* This structure is used for both pipes and sockets; for
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
100 a socket, the process handle in pi is NULL. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
101 typedef struct _child_process
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
102 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
103 int fd;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
104 int pid;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
105 HANDLE char_avail;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
106 HANDLE char_consumed;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
107 HANDLE thrd;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
108 HWND hwnd;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
109 PROCESS_INFORMATION procinfo;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
110 volatile int status;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
111 char chr;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
112 } child_process;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
113
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
114 #define MAX_CHILDREN MAXDESC/2
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
115 #define CHILD_ACTIVE(cp) ((cp)->char_avail != NULL)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
116
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
117 extern child_process * new_child (void);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
118 extern void delete_child (child_process *cp);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
120 /* parallel array of private info on file handles */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
121 typedef struct
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
122 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
123 unsigned flags;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
124 HANDLE hnd;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
125 child_process * cp;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
126 } filedesc;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
127
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
128 extern filedesc fd_info [];
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
130 /* fd_info flag definitions */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
131 #define FILE_READ 0x0001
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
132 #define FILE_WRITE 0x0002
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
133 #define FILE_BINARY 0x0010
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
134 #define FILE_LAST_CR 0x0020
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
135 #define FILE_AT_EOF 0x0040
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
136 #define FILE_SEND_SIGCHLD 0x0080
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
137 #define FILE_PIPE 0x0100
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
138 #define FILE_SOCKET 0x0200
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
139
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
140 /* #### This is an evil dirty hack. We must get rid of it.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
141 Word "munging" is not in XEmacs lexicon. - kkm */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
142
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
143 /* parallel array of private info on file handles */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
144 filedesc fd_info [ MAXDESC ];
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
145
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
146 #ifdef DEBUG_XEMACS
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
147 #define DebPrint(stuff) _DebPrint stuff
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
148 #else
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
149 #define DebPrint(stuff)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
150 #endif
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
151
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
152 /* ------------------------------------------------------------------------- */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 #ifndef DEBUG_XEMACS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 __inline
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 void _DebPrint (const char *fmt, ...)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 #ifdef DEBUG_XEMACS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 char buf[1024];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 va_list args;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 va_start (args, fmt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 vsprintf (buf, fmt, args);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 va_end (args);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 OutputDebugString (buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
170 /* 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
171
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 /* Child process management list. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 int child_proc_count = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 child_process child_procs[ MAX_CHILDREN ];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 child_process *dead_child = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 DWORD WINAPI reader_thread (void *arg);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 /* Find an unused process slot. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 child_process *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 new_child (void)
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 child_process *cp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 DWORD id;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 for (cp = child_procs+(child_proc_count-1); cp >= child_procs; cp--)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 if (!CHILD_ACTIVE (cp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 goto Initialize;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 if (child_proc_count == MAX_CHILDREN)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 cp = &child_procs[child_proc_count++];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 Initialize:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 xzero (*cp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 cp->fd = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 cp->pid = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 if (cp->procinfo.hProcess)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 CloseHandle(cp->procinfo.hProcess);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 cp->procinfo.hProcess = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 cp->status = STATUS_READ_ERROR;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 /* use manual reset event so that select() will function properly */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 cp->char_avail = CreateEvent (NULL, TRUE, FALSE, NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 if (cp->char_avail)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 cp->char_consumed = CreateEvent (NULL, FALSE, FALSE, NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 if (cp->char_consumed)
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 cp->thrd = CreateThread (NULL, 1024, reader_thread, cp, 0, &id);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 if (cp->thrd)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 return cp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 delete_child (cp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 }
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 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 delete_child (child_process *cp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 int i;
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 /* Should not be deleting a child that is still needed. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 for (i = 0; i < MAXDESC; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 if (fd_info[i].cp == cp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 abort ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 if (!CHILD_ACTIVE (cp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 /* reap thread if necessary */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232 if (cp->thrd)
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 DWORD rc;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 if (GetExitCodeThread (cp->thrd, &rc) && rc == STILL_ACTIVE)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 /* let the thread exit cleanly if possible */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 cp->status = STATUS_READ_ERROR;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 SetEvent (cp->char_consumed);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 if (WaitForSingleObject (cp->thrd, 1000) != WAIT_OBJECT_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 DebPrint (("delete_child.WaitForSingleObject (thread) failed "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 "with %lu for fd %ld\n", GetLastError (), cp->fd));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 TerminateThread (cp->thrd, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 }
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 CloseHandle (cp->thrd);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 cp->thrd = NULL;
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 (cp->char_avail)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 CloseHandle (cp->char_avail);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 cp->char_avail = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 if (cp->char_consumed)
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 CloseHandle (cp->char_consumed);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 cp->char_consumed = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 }
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 /* update child_proc_count (highest numbered slot in use plus one) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 if (cp == child_procs + child_proc_count - 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 for (i = child_proc_count-1; i >= 0; i--)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 if (CHILD_ACTIVE (&child_procs[i]))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 child_proc_count = i + 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 if (i < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 child_proc_count = 0;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 /* Find a child by pid. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 static child_process *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 find_child_pid (DWORD pid)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 child_process *cp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 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
283 if (CHILD_ACTIVE (cp) && pid == (DWORD) cp->pid)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 return cp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 /* Function to do blocking read of one byte, needed to implement
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 select. It is only allowed on sockets and pipes. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 _sys_read_ahead (int fd)
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 child_process * cp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 int rc = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 if (fd < 0 || fd >= MAXDESC)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 return STATUS_READ_ERROR;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 cp = fd_info[fd].cp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 if (cp == NULL || cp->fd != fd || cp->status != STATUS_READ_READY)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 return STATUS_READ_ERROR;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 if ((fd_info[fd].flags & (FILE_PIPE | FILE_SOCKET)) == 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 || (fd_info[fd].flags & FILE_READ) == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 /* fd is not a pipe or socket */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 abort ();
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 cp->status = STATUS_READ_IN_PROGRESS;
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 if (fd_info[fd].flags & FILE_PIPE)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 rc = _read (fd, &cp->chr, sizeof (char));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 /* Give subprocess time to buffer some more output for us before
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 reporting that input is available; we need this because Win95
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 connects DOS programs to pipes by making the pipe appear to be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 the normal console stdout - as a result most DOS programs will
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 write to stdout without buffering, ie. one character at a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 time. Even some Win32 programs do this - "dir" in a command
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 shell on NT is very slow if we don't do this. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 if (rc > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 int wait = XINT (Vwin32_pipe_read_delay);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 if (wait > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 Sleep (wait);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 else if (wait < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 while (++wait <= 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 /* Yield remainder of our time slice, effectively giving a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 temporary priority boost to the child process. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 Sleep (0);
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 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 if (rc == sizeof (char))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 cp->status = STATUS_READ_SUCCEEDED;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 cp->status = STATUS_READ_FAILED;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 return cp->status;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 }
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 /* Thread proc for child process and socket reader threads. Each thread
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 is normally blocked until woken by select() to check for input by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 reading one char. When the read completes, char_avail is signalled
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 to wake up the select emulator and the thread blocks itself again. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 DWORD WINAPI
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 reader_thread (void *arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 child_process *cp;
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 /* Our identity */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 cp = (child_process *)arg;
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 /* <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
359 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
360 read anything for them to consume yet! */
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 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 if (cp == NULL ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 WaitForSingleObject (cp->char_consumed, INFINITE) != WAIT_OBJECT_0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 if (cp == NULL)
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 return 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 for (;;)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 int rc;
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 rc = _sys_read_ahead (cp->fd);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378 /* The name char_avail is a misnomer - it really just means the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 read-ahead has completed, whether successfully or not. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 if (!SetEvent (cp->char_avail))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 DebPrint (("reader_thread.SetEvent failed with %lu for fd %ld\n",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 GetLastError (), cp->fd));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 return 1;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 if (rc == STATUS_READ_ERROR)
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 /* We are finished, so clean up handles and set to NULL so
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 that CHILD_ACTIVE will see what is going on */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 if (cp->char_avail) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 CloseHandle (cp->char_avail);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 cp->char_avail = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395 if (cp->thrd) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 CloseHandle (cp->thrd);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 cp->thrd = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399 if (cp->char_consumed) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400 CloseHandle(cp->char_consumed);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 cp->char_consumed = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 if (cp->procinfo.hProcess)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 CloseHandle (cp->procinfo.hProcess);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 cp->procinfo.hProcess=NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 return 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411 /* 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
412 if (rc == STATUS_READ_FAILED)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415 /* Wait until our input is acknowledged before reading again */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 if (WaitForSingleObject (cp->char_consumed, INFINITE) != WAIT_OBJECT_0)
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 DebPrint (("reader_thread.WaitForSingleObject failed with "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 "%lu for fd %ld\n", GetLastError (), cp->fd));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 break;
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 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423 /* 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
424 CHILD_ACTIVE will see what is going on */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425 if (cp->char_avail) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426 CloseHandle (cp->char_avail);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427 cp->char_avail = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429 if (cp->thrd) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 CloseHandle (cp->thrd);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431 cp->thrd = NULL;
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 if (cp->char_consumed) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434 CloseHandle(cp->char_consumed);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 cp->char_consumed = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 if (cp->procinfo.hProcess)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 CloseHandle (cp->procinfo.hProcess);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440 cp->procinfo.hProcess=NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
446 /* This must die. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
447 static void
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
448 unixtodos_filename (char *p)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
449 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
450 while (*p)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
451 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
452 if (*p == '/')
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
453 *p = '\\';
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
454 p++;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
455 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
456 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
457
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 /* To avoid Emacs changing directory, we just record here the directory
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459 the new process should start in. This is set just before calling
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460 sys_spawnve, and is not generally valid at any other time. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461 static const char * process_dir;
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 static BOOL
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
464 create_child (const char *exe, char *cmdline, char *env,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465 int * pPid, child_process *cp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 STARTUPINFO start;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468 SECURITY_ATTRIBUTES sec_attrs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469 SECURITY_DESCRIPTOR sec_desc;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
470 char dir[ PATH_MAX ];
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472 if (cp == NULL) abort ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474 xzero (start);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475 start.cb = sizeof (start);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 if (NILP (Vwin32_start_process_show_window))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478 start.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480 start.dwFlags = STARTF_USESTDHANDLES;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481 start.wShowWindow = SW_HIDE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 start.hStdInput = GetStdHandle (STD_INPUT_HANDLE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484 start.hStdOutput = GetStdHandle (STD_OUTPUT_HANDLE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485 start.hStdError = GetStdHandle (STD_ERROR_HANDLE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487 /* Explicitly specify no security */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
488 /* #### not supported under win98, but will go away */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 if (!InitializeSecurityDescriptor (&sec_desc, SECURITY_DESCRIPTOR_REVISION))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490 goto EH_Fail;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
491 /* #### not supported under win98, but will go away */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492 if (!SetSecurityDescriptorDacl (&sec_desc, TRUE, NULL, FALSE))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493 goto EH_Fail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494 sec_attrs.nLength = sizeof (sec_attrs);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495 sec_attrs.lpSecurityDescriptor = &sec_desc;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496 sec_attrs.bInheritHandle = FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
498 strcpy (dir, process_dir);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
499 unixtodos_filename (dir);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501 if (!CreateProcess (exe, cmdline, &sec_attrs, NULL, TRUE,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
502 (!NILP (Vwin32_start_process_share_console)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503 ? CREATE_NEW_PROCESS_GROUP
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
504 : CREATE_NEW_CONSOLE),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505 env, dir,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506 &start, &cp->procinfo))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507 goto EH_Fail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509 cp->pid = (int) cp->procinfo.dwProcessId;
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 CloseHandle (cp->procinfo.hThread);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512 CloseHandle (cp->procinfo.hProcess);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513 cp->procinfo.hThread=NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514 cp->procinfo.hProcess=NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
516 /* pid must fit in a Lisp_Int */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519 *pPid = cp->pid;
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 return TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523 EH_Fail:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524 DebPrint (("create_child.CreateProcess failed: %ld\n", GetLastError()););
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525 return FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529 merge_and_sort_env (char **envp1, char **envp2, char **new_envp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531 char **optr, **nptr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532 int num;
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 nptr = new_envp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535 optr = envp1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536 while (*optr)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537 *nptr++ = *optr++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538 num = optr - envp1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540 optr = envp2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541 while (*optr)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542 *nptr++ = *optr++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543 num += optr - envp2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
545 qsort (new_envp, num, sizeof (char*), mswindows_compare_env);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 *nptr = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550 /* 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
551 so intercept spawn requests. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552 int
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
553 spawnve_will_die_soon (int mode, const Intbyte *cmdname,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
554 const Intbyte * const *argv, const Intbyte *const *envp)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
555 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
556 Lisp_Object program, full;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
557 char *cmdline, *env, *parg, **targ;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
558 int arglen, numenv;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
559 int pid;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560 child_process *cp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561 int is_dos_app, is_cygnus_app;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562 int do_quoting = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
563 char escape_char = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564 /* 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
565 variable in their environment. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
566 char ppid_env_var_buffer[64];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
567 char *extra_env[] = {ppid_env_var_buffer, NULL};
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
568 struct gcpro gcpro1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
569
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
570 /* We don't care about the other modes */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
571 if (mode != _P_NOWAIT)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
573 errno = EINVAL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
574 return -1;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
577 /* Handle executable names without an executable suffix. */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
578 program = build_string (cmdname);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579 GCPRO1 (program);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
580 if (NILP (Ffile_executable_p (program)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
581 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
582 full = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
583 locate_file (Vexec_path, program, Vlisp_EXEC_SUFFIXES, &full, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584 if (NILP (full))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586 UNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587 errno = EINVAL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588 return -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589 }
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 432
diff changeset
590 TO_EXTERNAL_FORMAT (LISP_STRING, full,
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 432
diff changeset
591 C_STRING_ALLOCA, cmdname,
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 432
diff changeset
592 Qfile_name);
428
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 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
595 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
596 cmdname = (char*)alloca (strlen (argv[0]) + 1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
597 strcpy ((char*)cmdname, argv[0]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599 UNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601 /* make sure argv[0] and cmdname are both in DOS format */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602 unixtodos_filename ((char*)cmdname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603 /* #### KLUDGE */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
604 ((const char**)argv)[0] = cmdname;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606 /* Determine whether program is a 16-bit DOS executable, or a Win32
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607 executable that is implicitly linked to the Cygnus dll (implying it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608 was compiled with the Cygnus GNU toolchain and hence relies on
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609 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
610 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
611 mswindows_executable_type (cmdname, &is_dos_app, &is_cygnus_app);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
613 /* 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
614 application to start it by specifying the helper app as cmdname,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615 while leaving the real app name as argv[0]. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
616 if (is_dos_app)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
617 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
618 cmdname = (char*) alloca (PATH_MAX);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
619 if (egetenv ("CMDPROXY"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
620 strcpy ((char*)cmdname, egetenv ("CMDPROXY"));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
621 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
622 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
623 strcpy ((char*)cmdname, XSTRING_DATA (Vinvocation_directory));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624 strcat ((char*)cmdname, "cmdproxy.exe");
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 unixtodos_filename ((char*)cmdname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
627 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
628
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
629 /* 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
630 form CreateProcess wants... argv needs to be a space separated/null
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
631 terminated list of parameters, and envp is a null
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
632 separated/double-null terminated list of parameters.
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 Additionally, zero-length args and args containing whitespace or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
635 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
636 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
637 the child process reconstructs the argv array we start with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
638 exactly, so we treat quotes at the beginning and end of arguments
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
639 as embedded quotes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
640
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
641 The Win32 GNU-based library from Cygnus doubles quotes to escape
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
642 them, while MSVC uses backslash for escaping. (Actually the MSVC
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643 startup code does attempt to recognize doubled quotes and accept
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
644 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
645 single embedded quote!) So by default we decide whether to use
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
646 quote or backslash as the escape character based on whether the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
647 binary is apparently a Cygnus compiled app.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
648
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
649 Note that using backslash to escape embedded quotes requires
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
650 additional special handling if an embedded quote is already
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
651 preceded by backslash, or if an arg requiring quoting ends with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
652 backslash. In such cases, the run of escape characters needs to be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
653 doubled. For consistency, we apply this special handling as long
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
654 as the escape character is not quote.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
655
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
656 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
657 figure out list lengths on the fly and allocate them. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
658
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
659 if (!NILP (Vwin32_quote_process_args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
660 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661 do_quoting = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662 /* Override escape char by binding win32-quote-process-args to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
663 desired character, or use t for auto-selection. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664 if (INTP (Vwin32_quote_process_args))
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
665 escape_char = (char) XINT (Vwin32_quote_process_args);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
666 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
667 escape_char = is_cygnus_app ? '"' : '\\';
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
670 /* do argv... */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
671 arglen = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
672 targ = (char**)argv;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673 while (*targ)
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 char * p = *targ;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
676 int need_quotes = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
677 int escape_char_run = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
678
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
679 if (*p == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
680 need_quotes = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
681 for ( ; *p; p++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
682 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
683 if (*p == '"')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
684 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
685 /* allow for embedded quotes to be escaped */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
686 arglen++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
687 need_quotes = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
688 /* handle the case where the embedded quote is already escaped */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
689 if (escape_char_run > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
690 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
691 /* To preserve the arg exactly, we need to double the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
692 preceding escape characters (plus adding one to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
693 escape the quote character itself). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
694 arglen += escape_char_run;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
695 }
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 else if (*p == ' ' || *p == '\t')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
698 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
699 need_quotes = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
700 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
701
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
702 if (*p == escape_char && escape_char != '"')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
703 escape_char_run++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
704 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
705 escape_char_run = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
706 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
707 if (need_quotes)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
708 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
709 arglen += 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
710 /* handle the case where the arg ends with an escape char - we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
711 must not let the enclosing quote be escaped. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
712 if (escape_char_run > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
713 arglen += escape_char_run;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
714 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
715 arglen += strlen (*targ++) + 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
716 }
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
717 cmdline = (char*) alloca (arglen);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
718 targ = (char**)argv;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
719 parg = cmdline;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
720 while (*targ)
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 char * p = *targ;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
723 int need_quotes = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
724
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
725 if (*p == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
726 need_quotes = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
727
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
728 if (do_quoting)
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 for ( ; *p; p++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
731 if (*p == ' ' || *p == '\t' || *p == '"')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
732 need_quotes = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
733 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
734 if (need_quotes)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
735 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
736 int escape_char_run = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
737 char * first;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
738 char * last;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
739
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
740 p = *targ;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
741 first = p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
742 last = p + strlen (p) - 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
743 *parg++ = '"';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
744 #if 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
745 /* This version does not escape quotes if they occur at the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
746 beginning or end of the arg - this could lead to incorrect
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
747 behavior when the arg itself represents a command line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
748 containing quoted args. I believe this was originally done
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
749 as a hack to make some things work, before
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
750 `win32-quote-process-args' was added. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
751 while (*p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
752 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
753 if (*p == '"' && p > first && p < last)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
754 *parg++ = escape_char; /* escape embedded quotes */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
755 *parg++ = *p++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
756 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
757 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
758 for ( ; *p; p++)
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 if (*p == '"')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
761 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
762 /* double preceding escape chars if any */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
763 while (escape_char_run > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
764 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
765 *parg++ = escape_char;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
766 escape_char_run--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
767 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
768 /* escape all quote chars, even at beginning or end */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
769 *parg++ = escape_char;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
770 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
771 *parg++ = *p;
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 if (*p == escape_char && escape_char != '"')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
774 escape_char_run++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
775 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
776 escape_char_run = 0;
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 /* double escape chars before enclosing quote */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
779 while (escape_char_run > 0)
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 *parg++ = escape_char;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
782 escape_char_run--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
783 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
784 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
785 *parg++ = '"';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
786 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
787 else
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 strcpy (parg, *targ);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
790 parg += strlen (*targ);
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 *parg++ = ' ';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
793 targ++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
794 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
795 *--parg = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
796
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
797 /* and envp... */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
798 arglen = 1;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
799 targ = (char**) envp;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
800 numenv = 1; /* for end null */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
801 while (*targ)
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 arglen += strlen (*targ++) + 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
804 numenv++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
805 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
806 /* extra env vars... */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
807 sprintf (ppid_env_var_buffer, "__PARENT_PROCESS_ID=%d",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
808 GetCurrentProcessId ());
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
809 arglen += strlen (ppid_env_var_buffer) + 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
810 numenv++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
811
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
812 /* 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
813 targ = (char **) alloca (numenv * sizeof (char*));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
814 merge_and_sort_env ((char**) envp, extra_env, targ);
428
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 /* concatenate env entries. */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
817 env = (char*) alloca (arglen);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
818 parg = env;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
819 while (*targ)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
820 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
821 strcpy (parg, *targ);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
822 parg += strlen (*targ++);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
823 *parg++ = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
824 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
825 *parg++ = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
826 *parg = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
827
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
828 cp = new_child ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
829 if (cp == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
830 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
831 errno = EAGAIN;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
832 return -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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
835 /* Now create the process. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
836 if (!create_child (cmdname, cmdline, env, &pid, cp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
837 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
838 delete_child (cp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
839 errno = ENOEXEC;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
840 return -1;
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 return pid;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
846 /* Substitute for certain kill () operations */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
847
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
848 static BOOL CALLBACK
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
849 find_child_console (HWND hwnd, child_process * cp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
850 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
851 DWORD thread_id;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
852 DWORD process_id;
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 thread_id = GetWindowThreadProcessId (hwnd, &process_id);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
855 if (process_id == cp->procinfo.dwProcessId)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
856 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
857 char window_class[32];
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 GetClassName (hwnd, window_class, sizeof (window_class));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
860 if (strcmp (window_class,
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
861 mswindows_windows9x_p
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
862 ? "tty"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
863 : "ConsoleWindowClass") == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
864 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
865 cp->hwnd = hwnd;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
866 return FALSE;
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 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
869 /* keep looking */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
870 return TRUE;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
873 int
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
874 kill_will_disappear_soon (int pid, int sig)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
875 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
876 child_process *cp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
877 HANDLE proc_hand;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
878 int need_to_free = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
879 int rc = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
880
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
881 /* Only handle signals that will result in the process dying */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
882 if (sig != SIGINT && sig != SIGKILL && sig != SIGQUIT && sig != SIGHUP)
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 errno = EINVAL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
885 return -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
886 }
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 cp = find_child_pid (pid);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
889 if (cp == NULL)
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 proc_hand = OpenProcess (PROCESS_TERMINATE, 0, pid);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
892 if (proc_hand == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
893 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
894 errno = EPERM;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
895 return -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
896 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
897 need_to_free = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
898 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
899 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
900 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
901 proc_hand = cp->procinfo.hProcess;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
902 pid = cp->procinfo.dwProcessId;
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 /* Try to locate console window for process. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
905 EnumWindows ((WNDENUMPROC)find_child_console, (LPARAM) cp);
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
908 if (sig == SIGINT)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
909 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
910 if (NILP (Vwin32_start_process_share_console) && cp && cp->hwnd)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
911 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
912 BYTE control_scan_code = (BYTE) MapVirtualKey (VK_CONTROL, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
913 BYTE vk_break_code = VK_CANCEL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
914 BYTE break_scan_code = (BYTE) MapVirtualKey (vk_break_code, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
915 HWND foreground_window;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
916
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
917 if (break_scan_code == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
918 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
919 /* Fake Ctrl-C if we can't manage Ctrl-Break. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
920 vk_break_code = 'C';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
921 break_scan_code = (BYTE) MapVirtualKey (vk_break_code, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
922 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
923
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
924 foreground_window = GetForegroundWindow ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
925 if (foreground_window && SetForegroundWindow (cp->hwnd))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
926 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
927 /* Generate keystrokes as if user had typed Ctrl-Break or Ctrl-C. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
928 keybd_event (VK_CONTROL, control_scan_code, 0, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
929 keybd_event (vk_break_code, break_scan_code, 0, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
930 keybd_event (vk_break_code, break_scan_code, KEYEVENTF_KEYUP, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
931 keybd_event (VK_CONTROL, control_scan_code, KEYEVENTF_KEYUP, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
932
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
933 /* Sleep for a bit to give time for Emacs frame to respond
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
934 to focus change events (if Emacs was active app). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
935 Sleep (10);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
936
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
937 SetForegroundWindow (foreground_window);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
938 }
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 /* Ctrl-Break is NT equivalent of SIGINT. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
941 else if (!GenerateConsoleCtrlEvent (CTRL_BREAK_EVENT, pid))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
942 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
943 DebPrint (("sys_kill.GenerateConsoleCtrlEvent return %d "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
944 "for pid %lu\n", GetLastError (), pid));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
945 errno = EINVAL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
946 rc = -1;
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 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
949 else
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 if (NILP (Vwin32_start_process_share_console) && cp && cp->hwnd)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
952 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
953 #if 1
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
954 if (mswindows_windows9x_p)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
955 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
956 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
957 Another possibility is to try terminating the VDM out-right by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
958 calling the Shell VxD (id 0x17) V86 interface, function #4
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
959 "SHELL_Destroy_VM", ie.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
960
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
961 mov edx,4
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
962 mov ebx,vm_handle
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
963 call shellapi
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 First need to determine the current VM handle, and then arrange for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
966 the shellapi call to be made from the system vm (by using
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
967 Switch_VM_and_callback).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
968
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
969 Could try to invoke DestroyVM through CallVxD.
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 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
972 #if 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
973 /* On Win95, posting WM_QUIT causes the 16-bit subsystem
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
974 to hang when cmdproxy is used in conjunction with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
975 command.com for an interactive shell. Posting
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
976 WM_CLOSE pops up a dialog that, when Yes is selected,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
977 does the same thing. TerminateProcess is also less
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
978 than ideal in that subprocesses tend to stick around
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
979 until the machine is shutdown, but at least it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
980 doesn't freeze the 16-bit subsystem. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
981 PostMessage (cp->hwnd, WM_QUIT, 0xff, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
982 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
983 if (!TerminateProcess (proc_hand, 0xff))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
984 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
985 DebPrint (("sys_kill.TerminateProcess returned %d "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
986 "for pid %lu\n", GetLastError (), pid));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
987 errno = EINVAL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
988 rc = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
989 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
990 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
991 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
992 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
993 PostMessage (cp->hwnd, WM_CLOSE, 0, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
994 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
995 /* Kill the process. On Win32 this doesn't kill child processes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
996 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
997 used in every case. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
998 else if (!TerminateProcess (proc_hand, 0xff))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
999 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1000 DebPrint (("sys_kill.TerminateProcess returned %d "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1001 "for pid %lu\n", GetLastError (), pid));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1002 errno = EINVAL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1003 rc = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1004 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1005 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1006
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1007 if (need_to_free)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1008 CloseHandle (proc_hand);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1009
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1010 return rc;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1011 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1012
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
1013 /* From callproc.c */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
1014 extern Lisp_Object Vbinary_process_input;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
1015 extern Lisp_Object Vbinary_process_output;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
1016
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
1017 /* Unix pipe() has only one arg */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
1018 /* Will die as soon as callproc.c dies */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
1019 int
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
1020 pipe_will_die_soon (int *phandles)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
1021 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
1022 int rc;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
1023 unsigned flags;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
1024
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
1025 /* make pipe handles non-inheritable; when we spawn a child, we
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
1026 replace the relevant handle with an inheritable one. Also put
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
1027 pipes into binary mode; we will do text mode translation ourselves
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
1028 if required. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
1029 rc = _pipe (phandles, 0, _O_NOINHERIT | _O_BINARY);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
1030
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
1031 if (rc == 0)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
1032 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
1033 flags = FILE_PIPE | FILE_READ;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
1034 if (!NILP (Vbinary_process_output))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
1035 flags |= FILE_BINARY;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
1036 fd_info[phandles[0]].flags = flags;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
1037
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
1038 flags = FILE_PIPE | FILE_WRITE;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
1039 if (!NILP (Vbinary_process_input))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
1040 flags |= FILE_BINARY;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
1041 fd_info[phandles[1]].flags = flags;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
1042 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
1043
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
1044 return rc;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
1045 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 647
diff changeset
1046
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1047 /* The following two routines are used to manipulate stdin, stdout, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1048 stderr of our child processes.
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 Assuming that in, out, and err are *not* inheritable, we make them
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1051 stdin, stdout, and stderr of the child as follows:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1052
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1053 - Save the parent's current standard handles.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1054 - 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
1055 (Note that _get_osfhandle() is an io.h procedure that retrieves the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1056 NT file handle for a crt file descriptor.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1057 - Spawn the child, which inherits in, out, and err as stdin,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1058 stdout, and stderr. (see Spawnve)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1059 - Close the std handles passed to the child.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1060 - Reset the parent's standard handles to the saved handles.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1061 (see reset_standard_handles)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1062 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
1063
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1064 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1065 prepare_standard_handles (int in, int out, int err, HANDLE handles[3])
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 HANDLE parent;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1068 HANDLE newstdin, newstdout, newstderr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1069
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1070 parent = GetCurrentProcess ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1071
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1072 handles[0] = GetStdHandle (STD_INPUT_HANDLE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1073 handles[1] = GetStdHandle (STD_OUTPUT_HANDLE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1074 handles[2] = GetStdHandle (STD_ERROR_HANDLE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1075
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1076 /* make inheritable copies of the new handles */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1077 if (!DuplicateHandle (parent,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1078 (HANDLE) _get_osfhandle (in),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1079 parent,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1080 &newstdin,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1081 0,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1082 TRUE,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1083 DUPLICATE_SAME_ACCESS))
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 558
diff changeset
1084 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
1085 Qunbound, GetLastError ());
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1086
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1087 if (!DuplicateHandle (parent,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1088 (HANDLE) _get_osfhandle (out),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1089 parent,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1090 &newstdout,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1091 0,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1092 TRUE,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1093 DUPLICATE_SAME_ACCESS))
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 558
diff changeset
1094 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
1095 Qunbound, GetLastError ());
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1096
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1097 if (!DuplicateHandle (parent,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1098 (HANDLE) _get_osfhandle (err),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1099 parent,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1100 &newstderr,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1101 0,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1102 TRUE,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1103 DUPLICATE_SAME_ACCESS))
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 558
diff changeset
1104 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
1105 Qunbound, GetLastError ());
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1106
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1107 /* and store them as our std handles */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1108 if (!SetStdHandle (STD_INPUT_HANDLE, newstdin))
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 558
diff changeset
1109 mswindows_report_process_error ("Changing stdin handle",
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 558
diff changeset
1110 Qunbound, GetLastError ());
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1111
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1112 if (!SetStdHandle (STD_OUTPUT_HANDLE, newstdout))
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 558
diff changeset
1113 mswindows_report_process_error ("Changing stdout handle",
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 558
diff changeset
1114 Qunbound, GetLastError ());
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1115
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1116 if (!SetStdHandle (STD_ERROR_HANDLE, newstderr))
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 558
diff changeset
1117 mswindows_report_process_error ("Changing stderr handle",
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 558
diff changeset
1118 Qunbound, GetLastError ());
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1119 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1120
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1121 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1122 reset_standard_handles (int in, int out, int err, HANDLE handles[3])
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 /* close the duplicated handles passed to the child */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1125 CloseHandle (GetStdHandle (STD_INPUT_HANDLE));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1126 CloseHandle (GetStdHandle (STD_OUTPUT_HANDLE));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1127 CloseHandle (GetStdHandle (STD_ERROR_HANDLE));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1128
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1129 /* now restore parent's saved std handles */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1130 SetStdHandle (STD_INPUT_HANDLE, handles[0]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1131 SetStdHandle (STD_OUTPUT_HANDLE, handles[1]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1132 SetStdHandle (STD_ERROR_HANDLE, handles[2]);
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1135 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1136 set_process_dir (const char * dir)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1137 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1138 process_dir = dir;
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
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 void
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1143 syms_of_ntproc (void)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1144 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1145 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1146
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1147 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1148 vars_of_ntproc (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1149 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1150 DEFVAR_LISP ("win32-quote-process-args", &Vwin32_quote_process_args /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1151 Non-nil enables quoting of process arguments to ensure correct parsing.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1152 Because Windows does not directly pass argv arrays to child processes,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1153 programs have to reconstruct the argv array by parsing the command
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1154 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
1155 in double quotes or it will be parsed as multiple arguments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1156
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1157 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
1158 quote characters that appear, otherwise a suitable escape character
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1159 will be chosen based on the type of the program.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1160 */ );
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1161 Vwin32_quote_process_args = Qt;
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 DEFVAR_LISP ("win32-start-process-show-window",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1164 &Vwin32_start_process_show_window /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1165 When nil, processes started via start-process hide their windows.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1166 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
1167 */ );
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1168 Vwin32_start_process_show_window = Qnil;
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 DEFVAR_LISP ("win32-start-process-share-console",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1171 &Vwin32_start_process_share_console /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1172 When nil, processes started via start-process are given a new console.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1173 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
1174 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
1175 or indirectly by Emacs), and preventing Emacs from cleanly terminating the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1176 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
1177 otherwise respond to interrupts from Emacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1178 */ );
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1179 Vwin32_start_process_share_console = Qt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1180
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1181 DEFVAR_LISP ("win32-pipe-read-delay", &Vwin32_pipe_read_delay /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1182 Forced delay before reading subprocess output.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1183 This is done to improve the buffering of subprocess output, by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1184 avoiding the inefficiency of frequently reading small amounts of data.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1185
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1186 If positive, the value is the number of milliseconds to sleep before
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1187 reading the subprocess output. If negative, the magnitude is the number
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1188 of time slices to wait (effectively boosting the priority of the child
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1189 process temporarily). A value of zero disables waiting entirely.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1190 */ );
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1191 Vwin32_pipe_read_delay = make_int (50);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1192 }
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 /* end of ntproc.c */