annotate src/process-nt.c @ 404:2f8bb876ab1d r21-2-32

Import from CVS: tag r21-2-32
author cvs
date Mon, 13 Aug 2007 11:16:07 +0200
parents a86b2b5e0111
children b8cc9ab3f761
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1 /* Asynchronous subprocess implementation for Win32
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
2 Copyright (C) 1985, 1986, 1987, 1988, 1992, 1993, 1994, 1995
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
3 Free Software Foundation, Inc.
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
4 Copyright (C) 1995 Sun Microsystems, Inc.
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
5 Copyright (C) 1995, 1996, 2000 Ben Wing.
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
6
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
7 This file is part of XEmacs.
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
8
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
9 XEmacs is free software; you can redistribute it and/or modify it
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
10 under the terms of the GNU General Public License as published by the
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
11 Free Software Foundation; either version 2, or (at your option) any
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
12 later version.
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
13
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
14 XEmacs is distributed in the hope that it will be useful, but WITHOUT
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
17 for more details.
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
18
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
19 You should have received a copy of the GNU General Public License
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
20 along with XEmacs; see the file COPYING. If not, write to
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
21 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
22 Boston, MA 02111-1307, USA. */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
23
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
24 /* Written by Kirill M. Katsnelson <kkm@kis.ru>, April 1998 */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
25
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
26 #include <config.h>
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
27 #include "lisp.h"
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
28
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
29 #include "console-msw.h"
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
30 #include "hash.h"
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
31 #include "lstream.h"
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
32 #include "process.h"
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
33 #include "procimpl.h"
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
34 #include "sysdep.h"
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
35
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
36 #include <shellapi.h>
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
37 #ifdef __MINGW32__
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
38 #include <errno.h>
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
39 #endif
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
40 #include <signal.h>
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
41 #ifdef HAVE_SOCKETS
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
42 #include <winsock.h>
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
43 #endif
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
44
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
45 /* Arbitrary size limit for code fragments passed to run_in_other_process */
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
46 #define FRAGMENT_CODE_SIZE 32
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
47
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
48 /* Bound by winnt.el */
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
49 Lisp_Object Qnt_quote_process_args;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
50
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
51 /* Implementation-specific data. Pointed to by Lisp_Process->process_data */
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
52 struct nt_process_data
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
53 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
54 HANDLE h_process;
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
55 DWORD dwProcessId;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
56 HWND hwnd; /* console window */
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
57 int need_enable_child_signals;
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
58 };
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
59
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
60 /* Control whether create_child causes the process to inherit Emacs'
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
61 console window, or be given a new one of its own. The default is
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
62 nil, to allow multiple DOS programs to run on Win95. Having separate
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
63 consoles also allows Emacs to cleanly terminate process groups. */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
64 Lisp_Object Vmswindows_start_process_share_console;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
65
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
66 /* Control whether create_child cause the process to inherit Emacs'
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
67 error mode setting. The default is t, to minimize the possibility of
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
68 subprocesses blocking when accessing unmounted drives. */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
69 Lisp_Object Vmswindows_start_process_inherit_error_mode;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
70
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
71 #define NT_DATA(p) ((struct nt_process_data*)((p)->process_data))
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
72
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
73 /*-----------------------------------------------------------------------*/
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
74 /* Process helpers */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
75 /*-----------------------------------------------------------------------*/
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
76
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
77 /* This one breaks process abstraction. Prototype is in console-msw.h,
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
78 used by select_process method in event-msw.c */
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
79 HANDLE
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
80 get_nt_process_handle (Lisp_Process *p)
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
81 {
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
82 return (NT_DATA (p)->h_process);
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
83 }
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
84
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
85 static struct Lisp_Process *
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
86 find_process_from_pid (DWORD pid)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
87 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
88 Lisp_Object tail, proc;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
89
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
90 for (tail = Vprocess_list; CONSP (tail); tail = XCDR (tail))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
91 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
92 proc = XCAR (tail);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
93 if (NT_DATA (XPROCESS (proc))->dwProcessId == pid)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
94 return XPROCESS (proc);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
95 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
96 return 0;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
97 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
98
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
99
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
100 /*-----------------------------------------------------------------------*/
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
101 /* Running remote threads. See Microsoft Systems Journal 1994 Number 5 */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
102 /* Jeffrey Richter, Load Your 32-bit DLL into Another Process's Address..*/
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
103 /*-----------------------------------------------------------------------*/
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
104
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
105 typedef struct
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
106 {
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
107 HANDLE h_process;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
108 HANDLE h_thread;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
109 LPVOID address;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
110 } process_memory;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
111
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
112 /*
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
113 * Allocate SIZE bytes in H_PROCESS address space. Fill in PMC used
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
114 * further by other routines. Return nonzero if successful.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
115 *
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
116 * The memory in other process is allocated by creating a suspended
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
117 * thread. Initial stack of that thread is used as the memory
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
118 * block. The thread entry point is the routine ExitThread in
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
119 * kernel32.dll, so the allocated memory is freed just by resuming the
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
120 * thread, which immediately terminates after that.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
121 */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
122
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
123 static int
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
124 alloc_process_memory (HANDLE h_process, size_t size,
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
125 process_memory* pmc)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
126 {
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
127 LPTHREAD_START_ROUTINE adr_ExitThread =
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
128 (LPTHREAD_START_ROUTINE)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
129 GetProcAddress (GetModuleHandle ("kernel32"), "ExitThread");
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
130 DWORD dw_unused;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
131 CONTEXT context;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
132 MEMORY_BASIC_INFORMATION mbi;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
133
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
134 pmc->h_process = h_process;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
135 pmc->h_thread = CreateRemoteThread (h_process, NULL, size,
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
136 adr_ExitThread, NULL,
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
137 CREATE_SUSPENDED, &dw_unused);
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
138 if (pmc->h_thread == NULL)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
139 return 0;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
140
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
141 /* Get context, for thread's stack pointer */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
142 context.ContextFlags = CONTEXT_CONTROL;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
143 if (!GetThreadContext (pmc->h_thread, &context))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
144 goto failure;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
145
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
146 /* Determine base address of the committed range */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
147 if (sizeof(mbi) != VirtualQueryEx (h_process,
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
148 #if defined (_X86_)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
149 (LPDWORD)context.Esp - 1,
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
150 #elif defined (_ALPHA_)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
151 (LPDWORD)context.IntSp - 1,
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
152 #else
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
153 #error Unknown processor architecture
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
154 #endif
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
155 &mbi, sizeof(mbi)))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
156 goto failure;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
157
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
158 /* Change the page protection of the allocated memory to executable,
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
159 read, and write. */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
160 if (!VirtualProtectEx (h_process, mbi.BaseAddress, size,
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
161 PAGE_EXECUTE_READWRITE, &dw_unused))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
162 goto failure;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
163
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
164 pmc->address = mbi.BaseAddress;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
165 return 1;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
166
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
167 failure:
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
168 ResumeThread (pmc->h_thread);
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
169 pmc->address = 0;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
170 return 0;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
171 }
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
172
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
173 static void
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
174 free_process_memory (process_memory* pmc)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
175 {
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
176 ResumeThread (pmc->h_thread);
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
177 }
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
178
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
179 /*
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
180 * Run ROUTINE in the context of process determined by H_PROCESS. The
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
181 * routine is passed the address of DATA as parameter. The ROUTINE must
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
182 * not be longer than ROUTINE_CODE_SIZE bytes. DATA_SIZE is the size of
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
183 * DATA structure.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
184 *
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
185 * Note that the code must be positionally independent, and compiled
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
186 * without stack checks (they cause implicit calls into CRT so will
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
187 * fail). DATA should not refer any data in calling process, as both
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
188 * routine and its data are copied into remote process. Size of data
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
189 * and code together should not exceed one page (4K on x86 systems).
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
190 *
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
191 * Return the value returned by ROUTINE, or (DWORD)-1 if call failed.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
192 */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
193 static DWORD
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
194 run_in_other_process (HANDLE h_process,
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
195 LPTHREAD_START_ROUTINE routine,
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
196 LPVOID data, size_t data_size)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
197 {
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
198 process_memory pm;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
199 const size_t code_size = FRAGMENT_CODE_SIZE;
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
200 /* Need at most 3 extra bytes of memory, for data alignment */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
201 size_t total_size = code_size + data_size + 3;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
202 LPVOID remote_data;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
203 HANDLE h_thread;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
204 DWORD dw_unused;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
205
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
206 /* Allocate memory */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
207 if (!alloc_process_memory (h_process, total_size, &pm))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
208 return (DWORD)-1;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
209
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
210 /* Copy code */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
211 if (!WriteProcessMemory (h_process, pm.address, (LPVOID)routine,
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
212 code_size, NULL))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
213 goto failure;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
214
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
215 /* Copy data */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
216 if (data_size)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
217 {
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
218 remote_data = (LPBYTE)pm.address + ((code_size + 4) & ~3);
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
219 if (!WriteProcessMemory (h_process, remote_data, data, data_size, NULL))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
220 goto failure;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
221 }
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
222 else
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
223 remote_data = NULL;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
224
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
225 /* Execute the remote copy of code, passing it remote data */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
226 h_thread = CreateRemoteThread (h_process, NULL, 0,
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
227 (LPTHREAD_START_ROUTINE) pm.address,
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
228 remote_data, 0, &dw_unused);
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
229 if (h_thread == NULL)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
230 goto failure;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
231
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
232 /* Wait till thread finishes */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
233 WaitForSingleObject (h_thread, INFINITE);
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
234
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
235 /* Free remote memory */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
236 free_process_memory (&pm);
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
237
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
238 /* Return thread's exit code */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
239 {
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
240 DWORD exit_code;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
241 GetExitCodeThread (h_thread, &exit_code);
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
242 CloseHandle (h_thread);
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
243 return exit_code;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
244 }
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
245
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
246 failure:
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
247 free_process_memory (&pm);
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
248 return (DWORD)-1;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
249 }
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
250
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
251 /*-----------------------------------------------------------------------*/
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
252 /* Sending signals */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
253 /*-----------------------------------------------------------------------*/
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
254
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
255 /* ---------------------------- the NT way ------------------------------- */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
256
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
257 /*
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
258 * We handle the following signals:
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
259 *
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
260 * SIGKILL, SIGTERM, SIGQUIT, SIGHUP - These four translate to ExitProcess
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
261 * executed by the remote process
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
262 * SIGINT - The remote process is sent CTRL_BREAK_EVENT
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
263 *
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
264 * The MSVC5.0 compiler feels free to re-order functions within a
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
265 * compilation unit, so we have no way of finding out the size of the
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
266 * following functions. Therefore these functions must not be larger than
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
267 * FRAGMENT_CODE_SIZE.
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
268 */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
269
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
270 /*
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
271 * Sending SIGKILL
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
272 */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
273 typedef struct
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
274 {
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
275 void (WINAPI *adr_ExitProcess) (UINT);
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
276 } sigkill_data;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
277
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
278 static DWORD WINAPI
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
279 sigkill_proc (sigkill_data* data)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
280 {
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
281 (*data->adr_ExitProcess)(255);
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
282 return 1;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
283 }
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
284
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
285 /*
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
286 * Sending break or control c
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
287 */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
288 typedef struct
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
289 {
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
290 BOOL (WINAPI *adr_GenerateConsoleCtrlEvent) (DWORD, DWORD);
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
291 DWORD event;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
292 } sigint_data;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
293
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
294 static DWORD WINAPI
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
295 sigint_proc (sigint_data* data)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
296 {
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
297 return (*data->adr_GenerateConsoleCtrlEvent) (data->event, 0);
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
298 }
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
299
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
300 /*
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
301 * Enabling signals
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
302 */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
303 typedef struct
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
304 {
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
305 BOOL (WINAPI *adr_SetConsoleCtrlHandler) (LPVOID, BOOL);
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
306 } sig_enable_data;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
307
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
308 static DWORD WINAPI
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
309 sig_enable_proc (sig_enable_data* data)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
310 {
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
311 (*data->adr_SetConsoleCtrlHandler) (NULL, FALSE);
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
312 return 1;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
313 }
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
314
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
315 /*
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
316 * Send signal SIGNO to process H_PROCESS.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
317 * Return nonzero if successful.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
318 */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
319
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
320 static int
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
321 send_signal_the_nt_way (struct nt_process_data *cp, int pid, int signo)
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
322 {
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
323 HANDLE h_process;
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
324 HMODULE h_kernel = GetModuleHandle ("kernel32");
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
325 int close_process = 0;
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
326 DWORD retval;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
327
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
328 assert (h_kernel != NULL);
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
329
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
330 if (cp)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
331 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
332 pid = cp->dwProcessId;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
333 h_process = cp->h_process;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
334 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
335 else
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
336 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
337 close_process = 1;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
338 /* Try to open the process with required privileges */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
339 h_process = OpenProcess (PROCESS_CREATE_THREAD
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
340 | PROCESS_QUERY_INFORMATION
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
341 | PROCESS_VM_OPERATION
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
342 | PROCESS_VM_WRITE,
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
343 FALSE, pid);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
344 if (!h_process)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
345 return 0;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
346 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
347
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
348 switch (signo)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
349 {
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
350 case SIGKILL:
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
351 case SIGTERM:
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
352 case SIGQUIT:
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
353 case SIGHUP:
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
354 {
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
355 sigkill_data d;
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
356
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
357 d.adr_ExitProcess =
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
358 (void (WINAPI *) (UINT)) GetProcAddress (h_kernel, "ExitProcess");
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
359 assert (d.adr_ExitProcess);
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
360 retval = run_in_other_process (h_process,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
361 (LPTHREAD_START_ROUTINE)sigkill_proc,
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
362 &d, sizeof (d));
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
363 break;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
364 }
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
365 case SIGINT:
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
366 {
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
367 sigint_data d;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
368 d.adr_GenerateConsoleCtrlEvent =
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
369 (BOOL (WINAPI *) (DWORD, DWORD))
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
370 GetProcAddress (h_kernel, "GenerateConsoleCtrlEvent");
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
371 assert (d.adr_GenerateConsoleCtrlEvent);
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
372 d.event = CTRL_C_EVENT;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
373 retval = run_in_other_process (h_process,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
374 (LPTHREAD_START_ROUTINE)sigint_proc,
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
375 &d, sizeof (d));
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
376 break;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
377 }
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
378 default:
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
379 assert (0);
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
380 }
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
381
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
382 if (close_process)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
383 CloseHandle (h_process);
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
384 return (int)retval > 0 ? 1 : 0;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
385 }
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
386
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
387 /*
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
388 * Enable CTRL_C_EVENT handling in a new child process
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
389 */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
390 static void
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
391 enable_child_signals (HANDLE h_process)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
392 {
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
393 HMODULE h_kernel = GetModuleHandle ("kernel32");
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
394 sig_enable_data d;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
395
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
396 assert (h_kernel != NULL);
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
397 d.adr_SetConsoleCtrlHandler =
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
398 (BOOL (WINAPI *) (LPVOID, BOOL))
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
399 GetProcAddress (h_kernel, "SetConsoleCtrlHandler");
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
400 assert (d.adr_SetConsoleCtrlHandler);
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
401 run_in_other_process (h_process, (LPTHREAD_START_ROUTINE)sig_enable_proc,
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
402 &d, sizeof (d));
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
403 }
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
404
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
405 #pragma warning (default : 4113)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
406
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
407 /* ---------------------------- the 95 way ------------------------------- */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
408
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
409 static BOOL CALLBACK
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
410 find_child_console (HWND hwnd, struct nt_process_data *cp)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
411 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
412 DWORD thread_id;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
413 DWORD process_id;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
414
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
415 thread_id = GetWindowThreadProcessId (hwnd, &process_id);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
416 if (process_id == cp->dwProcessId)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
417 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
418 char window_class[32];
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
419
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
420 GetClassName (hwnd, window_class, sizeof (window_class));
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
421 if (strcmp (window_class,
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
422 msw_windows9x_p ()
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
423 ? "tty"
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
424 : "ConsoleWindowClass") == 0)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
425 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
426 cp->hwnd = hwnd;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
427 return FALSE;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
428 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
429 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
430 /* keep looking */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
431 return TRUE;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
432 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
433
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
434 static int
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
435 send_signal_the_95_way (struct nt_process_data *cp, int pid, int signo)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
436 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
437 HANDLE h_process;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
438 int close_process = 0;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
439 int rc = 1;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
440
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
441 if (cp)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
442 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
443 pid = cp->dwProcessId;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
444 h_process = cp->h_process;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
445
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
446 /* Try to locate console window for process. */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
447 EnumWindows (find_child_console, (LPARAM) cp);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
448 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
449 else
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
450 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
451 close_process = 1;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
452 /* Try to open the process with required privileges */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
453 h_process = OpenProcess (PROCESS_TERMINATE, FALSE, pid);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
454 if (!h_process)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
455 return 0;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
456 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
457
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
458 if (signo == SIGINT)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
459 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
460 if (NILP (Vmswindows_start_process_share_console) && cp && cp->hwnd)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
461 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
462 BYTE control_scan_code = (BYTE) MapVirtualKey (VK_CONTROL, 0);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
463 BYTE vk_break_code = VK_CANCEL;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
464 BYTE break_scan_code = (BYTE) MapVirtualKey (vk_break_code, 0);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
465 HWND foreground_window;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
466
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
467 if (break_scan_code == 0)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
468 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
469 /* Fake Ctrl-C if we can't manage Ctrl-Break. */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
470 vk_break_code = 'C';
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
471 break_scan_code = (BYTE) MapVirtualKey (vk_break_code, 0);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
472 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
473
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
474 foreground_window = GetForegroundWindow ();
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
475 if (foreground_window)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
476 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
477 /* NT 5.0, and apparently also Windows 98, will not allow
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
478 a Window to be set to foreground directly without the
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
479 user's involvement. The workaround is to attach
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
480 ourselves to the thread that owns the foreground
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
481 window, since that is the only thread that can set the
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
482 foreground window. */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
483 DWORD foreground_thread, child_thread;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
484 foreground_thread =
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
485 GetWindowThreadProcessId (foreground_window, NULL);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
486 if (foreground_thread == GetCurrentThreadId ()
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
487 || !AttachThreadInput (GetCurrentThreadId (),
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
488 foreground_thread, TRUE))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
489 foreground_thread = 0;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
490
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
491 child_thread = GetWindowThreadProcessId (cp->hwnd, NULL);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
492 if (child_thread == GetCurrentThreadId ()
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
493 || !AttachThreadInput (GetCurrentThreadId (),
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
494 child_thread, TRUE))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
495 child_thread = 0;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
496
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
497 /* Set the foreground window to the child. */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
498 if (SetForegroundWindow (cp->hwnd))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
499 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
500 /* Generate keystrokes as if user had typed Ctrl-Break or
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
501 Ctrl-C. */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
502 keybd_event (VK_CONTROL, control_scan_code, 0, 0);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
503 keybd_event (vk_break_code, break_scan_code,
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
504 (vk_break_code == 'C' ? 0 : KEYEVENTF_EXTENDEDKEY), 0);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
505 keybd_event (vk_break_code, break_scan_code,
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
506 (vk_break_code == 'C' ? 0 : KEYEVENTF_EXTENDEDKEY)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
507 | KEYEVENTF_KEYUP, 0);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
508 keybd_event (VK_CONTROL, control_scan_code,
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
509 KEYEVENTF_KEYUP, 0);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
510
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
511 /* Sleep for a bit to give time for Emacs frame to respond
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
512 to focus change events (if Emacs was active app). */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
513 Sleep (100);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
514
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
515 SetForegroundWindow (foreground_window);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
516 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
517 /* Detach from the foreground and child threads now that
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
518 the foreground switching is over. */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
519 if (foreground_thread)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
520 AttachThreadInput (GetCurrentThreadId (),
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
521 foreground_thread, FALSE);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
522 if (child_thread)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
523 AttachThreadInput (GetCurrentThreadId (),
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
524 child_thread, FALSE);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
525 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
526 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
527 /* Ctrl-Break is NT equivalent of SIGINT. */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
528 else if (!GenerateConsoleCtrlEvent (CTRL_BREAK_EVENT, pid))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
529 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
530 #if 0 /* FSF Emacs */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
531 DebPrint (("sys_kill.GenerateConsoleCtrlEvent return %d "
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
532 "for pid %lu\n", GetLastError (), pid));
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
533 errno = EINVAL;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
534 #endif
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
535 rc = 0;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
536 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
537 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
538 else
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
539 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
540 if (NILP (Vmswindows_start_process_share_console) && cp && cp->hwnd)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
541 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
542 #if 1
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
543 if (msw_windows9x_p ())
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
544 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
545 /*
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
546 Another possibility is to try terminating the VDM out-right by
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
547 calling the Shell VxD (id 0x17) V86 interface, function #4
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
548 "SHELL_Destroy_VM", ie.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
549
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
550 mov edx,4
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
551 mov ebx,vm_handle
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
552 call shellapi
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
553
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
554 First need to determine the current VM handle, and then arrange for
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
555 the shellapi call to be made from the system vm (by using
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
556 Switch_VM_and_callback).
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
557
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
558 Could try to invoke DestroyVM through CallVxD.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
559
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
560 */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
561 #if 0
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
562 /* On Win95, posting WM_QUIT causes the 16-bit subsystem
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
563 to hang when cmdproxy is used in conjunction with
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
564 command.com for an interactive shell. Posting
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
565 WM_CLOSE pops up a dialog that, when Yes is selected,
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
566 does the same thing. TerminateProcess is also less
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
567 than ideal in that subprocesses tend to stick around
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
568 until the machine is shutdown, but at least it
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
569 doesn't freeze the 16-bit subsystem. */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
570 PostMessage (cp->hwnd, WM_QUIT, 0xff, 0);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
571 #endif
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
572 if (!TerminateProcess (h_process, 0xff))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
573 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
574 #if 0 /* FSF Emacs */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
575 DebPrint (("sys_kill.TerminateProcess returned %d "
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
576 "for pid %lu\n", GetLastError (), pid));
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
577 errno = EINVAL;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
578 #endif
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
579 rc = 0;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
580 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
581 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
582 else
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
583 #endif
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
584 PostMessage (cp->hwnd, WM_CLOSE, 0, 0);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
585 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
586 /* Kill the process. On W32 this doesn't kill child processes
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
587 so it doesn't work very well for shells which is why it's not
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
588 used in every case. */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
589 else if (!TerminateProcess (h_process, 0xff))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
590 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
591 #if 0 /* FSF Emacs */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
592 DebPrint (("sys_kill.TerminateProcess returned %d "
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
593 "for pid %lu\n", GetLastError (), pid));
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
594 errno = EINVAL;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
595 #endif
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
596 rc = 0;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
597 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
598 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
599
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
600 if (close_process)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
601 CloseHandle (h_process);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
602
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
603 return rc;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
604 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
605
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
606 /* -------------------------- all-OS functions ---------------------------- */
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
607
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
608 static int
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
609 send_signal (struct nt_process_data *cp, int pid, int signo)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
610 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
611 return send_signal_the_nt_way (cp, pid, signo)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
612 || send_signal_the_95_way (cp, pid, signo);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
613 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
614
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
615 /*
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
616 * Signal error if SIGNO is not supported
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
617 */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
618 static void
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
619 validate_signal_number (int signo)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
620 {
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
621 if (signo != SIGKILL && signo != SIGTERM
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
622 && signo != SIGQUIT && signo != SIGINT
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
623 && signo != SIGHUP)
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
624 signal_simple_error ("Signal number not supported", make_int (signo));
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
625 }
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
626
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
627 /*-----------------------------------------------------------------------*/
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
628 /* Process methods */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
629 /*-----------------------------------------------------------------------*/
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
630
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
631 /*
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
632 * Allocate and initialize Lisp_Process->process_data
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
633 */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
634
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
635 static void
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
636 nt_alloc_process_data (Lisp_Process *p)
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
637 {
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
638 p->process_data = xnew_and_zero (struct nt_process_data);
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
639 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
640
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
641 static void
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
642 nt_finalize_process_data (Lisp_Process *p, int for_disksave)
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
643 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
644 assert (!for_disksave);
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
645 if (NT_DATA (p)->h_process)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
646 CloseHandle (NT_DATA (p)->h_process);
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
647 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
648
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
649 /*
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
650 * Initialize XEmacs process implementation once
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
651 */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
652 static void
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
653 nt_init_process (void)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
654 {
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
655 /* Initialize winsock */
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
656 WSADATA wsa_data;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
657 /* Request Winsock v1.1 Note the order: (minor=1, major=1) */
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
658 WSAStartup (MAKEWORD (1,1), &wsa_data);
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
659 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
660
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
661 /*
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
662 * Fork off a subprocess. P is a pointer to newly created subprocess
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
663 * object. If this function signals, the caller is responsible for
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
664 * deleting (and finalizing) the process object.
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
665 *
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
666 * The method must return PID of the new process, a (positive??? ####) number
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
667 * which fits into Lisp_Int. No return value indicates an error, the method
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
668 * must signal an error instead.
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
669 */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
670
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
671 static void
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
672 signal_cannot_launch (Lisp_Object image_file, DWORD err)
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
673 {
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
674 mswindows_set_errno (err);
290
c9fe270a4101 Import from CVS: tag r21-0b43
cvs
parents: 288
diff changeset
675 signal_simple_error_2 ("Error starting", image_file, lisp_strerror (errno));
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
676 }
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
677
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
678 static void
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
679 ensure_console_window_exists ()
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
680 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
681 if (msw_windows9x_p ())
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
682 msw_hide_console ();
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
683 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
684
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
685 static int
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
686 nt_create_process (Lisp_Process *p,
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
687 Lisp_Object *argv, int nargv,
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
688 Lisp_Object program, Lisp_Object cur_dir)
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
689 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
690 HANDLE hmyshove, hmyslurp, hprocin, hprocout, hprocerr;
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
691 LPTSTR command_line;
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
692 BOOL do_io, windowed;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
693 char *proc_env;
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
694
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
695 /* Find out whether the application is windowed or not */
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
696 {
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
697 /* SHGetFileInfo tends to return ERROR_FILE_NOT_FOUND on most
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
698 errors. This leads to bogus error message. */
298
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 290
diff changeset
699 DWORD image_type;
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 290
diff changeset
700 char *p = strrchr ((char *)XSTRING_DATA (program), '.');
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 290
diff changeset
701 if (p != NULL &&
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 290
diff changeset
702 (stricmp (p, ".exe") == 0 ||
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 290
diff changeset
703 stricmp (p, ".com") == 0 ||
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 290
diff changeset
704 stricmp (p, ".bat") == 0 ||
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 290
diff changeset
705 stricmp (p, ".cmd") == 0))
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 290
diff changeset
706 {
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 290
diff changeset
707 image_type = SHGetFileInfo ((char *)XSTRING_DATA (program), 0,NULL,
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 290
diff changeset
708 0, SHGFI_EXETYPE);
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 290
diff changeset
709 }
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 290
diff changeset
710 else
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 290
diff changeset
711 {
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 290
diff changeset
712 char progname[MAX_PATH];
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 290
diff changeset
713 sprintf (progname, "%s.exe", (char *)XSTRING_DATA (program));
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 290
diff changeset
714 image_type = SHGetFileInfo (progname, 0, NULL, 0, SHGFI_EXETYPE);
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 290
diff changeset
715 }
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
716 if (image_type == 0)
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
717 signal_cannot_launch (program, (GetLastError () == ERROR_FILE_NOT_FOUND
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
718 ? ERROR_BAD_FORMAT : GetLastError ()));
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
719 windowed = HIWORD (image_type) != 0;
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
720 }
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
721
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
722 /* Decide whether to do I/O on process handles, or just mark the
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
723 process exited immediately upon successful launching. We do I/O if the
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
724 process is a console one, or if it is windowed but windowed_process_io
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
725 is non-zero */
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
726 do_io = !windowed || windowed_process_io ;
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
727
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
728 if (do_io)
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
729 {
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
730 /* Create two unidirectional named pipes */
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
731 HANDLE htmp;
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
732 SECURITY_ATTRIBUTES sa;
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
733
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
734 sa.nLength = sizeof(sa);
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
735 sa.bInheritHandle = TRUE;
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
736 sa.lpSecurityDescriptor = NULL;
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
737
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
738 CreatePipe (&hprocin, &hmyshove, &sa, 0);
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
739 CreatePipe (&hmyslurp, &hprocout, &sa, 0);
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
740
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
741 /* Duplicate the stdout handle for use as stderr */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
742 DuplicateHandle(GetCurrentProcess(), hprocout, GetCurrentProcess(), &hprocerr,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
743 0, TRUE, DUPLICATE_SAME_ACCESS);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
744
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
745 /* Stupid Win32 allows to create a pipe with *both* ends either
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
746 inheritable or not. We need process ends inheritable, and local
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
747 ends not inheritable. */
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
748 DuplicateHandle (GetCurrentProcess(), hmyshove, GetCurrentProcess(), &htmp,
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
749 0, FALSE, DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS);
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
750 hmyshove = htmp;
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
751 DuplicateHandle (GetCurrentProcess(), hmyslurp, GetCurrentProcess(), &htmp,
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
752 0, FALSE, DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS);
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
753 hmyslurp = htmp;
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
754 }
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
755
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
756 /* Convert an argv vector into Win32 style command line by a call to
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
757 lisp function `nt-quote-process-args' which see (in winnt.el)*/
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
758 {
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
759 int i;
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
760 Lisp_Object args_or_ret = Qnil;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
761 struct gcpro gcpro1;
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
762
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
763 GCPRO1 (args_or_ret);
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
764
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
765 for (i = 0; i < nargv; ++i)
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
766 args_or_ret = Fcons (*argv++, args_or_ret);
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
767 args_or_ret = Fnreverse (args_or_ret);
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
768 args_or_ret = Fcons (program, args_or_ret);
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
769
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
770 args_or_ret = call1 (Qnt_quote_process_args, args_or_ret);
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
771
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
772 if (!STRINGP (args_or_ret))
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
773 /* Luser wrote his/her own clever version */
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
774 error ("Bogus return value from `nt-quote-process-args'");
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
775
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
776 command_line = alloca_array (char, (XSTRING_LENGTH (program)
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
777 + XSTRING_LENGTH (args_or_ret) + 2));
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
778 strcpy (command_line, XSTRING_DATA (program));
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
779 strcat (command_line, " ");
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
780 strcat (command_line, XSTRING_DATA (args_or_ret));
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
781
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
782 UNGCPRO; /* args_or_ret */
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
783 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
784
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
785 /* Set `proc_env' to a nul-separated array of the strings in
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
786 Vprocess_environment terminated by 2 nuls. */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
787
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
788 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
789 extern int compare_env (const char **strp1, const char **strp2);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
790 char **env;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
791 REGISTER Lisp_Object tem;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
792 REGISTER char **new_env;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
793 REGISTER int new_length = 0, i, new_space;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
794 char *penv;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
795
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
796 for (tem = Vprocess_environment;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
797 (CONSP (tem)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
798 && STRINGP (XCAR (tem)));
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
799 tem = XCDR (tem))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
800 new_length++;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
801
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
802 /* new_length + 1 to include terminating 0. */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
803 env = new_env = alloca_array (char *, new_length + 1);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
804
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
805 /* Copy the Vprocess_environment strings into new_env. */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
806 for (tem = Vprocess_environment;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
807 (CONSP (tem)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
808 && STRINGP (XCAR (tem)));
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
809 tem = XCDR (tem))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
810 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
811 char **ep = env;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
812 char *string = (char *) XSTRING_DATA (XCAR (tem));
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
813 /* See if this string duplicates any string already in the env.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
814 If so, don't put it in.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
815 When an env var has multiple definitions,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
816 we keep the definition that comes first in process-environment. */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
817 for (; ep != new_env; ep++)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
818 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
819 char *p = *ep, *q = string;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
820 while (1)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
821 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
822 if (*q == 0)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
823 /* The string is malformed; might as well drop it. */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
824 goto duplicate;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
825 if (*q != *p)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
826 break;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
827 if (*q == '=')
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
828 goto duplicate;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
829 p++, q++;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
830 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
831 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
832 *new_env++ = string;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
833 duplicate: ;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
834 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
835 *new_env = 0;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
836
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
837 /* Sort the environment variables */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
838 new_length = new_env - env;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
839 qsort (env, new_length, sizeof (char *), compare_env);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
840
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
841 /* Work out how much space to allocate */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
842 new_space = 0;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
843 for (i = 0; i < new_length; i++)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
844 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
845 new_space += strlen(env[i]) + 1;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
846 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
847 new_space++;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
848
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
849 /* Allocate space and copy variables into it */
400
a86b2b5e0111 Import from CVS: tag r21-2-30
cvs
parents: 398
diff changeset
850 penv = proc_env = (char*) alloca(new_space);
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
851 for (i = 0; i < new_length; i++)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
852 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
853 strcpy(penv, env[i]);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
854 penv += strlen(env[i]) + 1;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
855 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
856 *penv = 0;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
857 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
858
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
859 /* Create process */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
860 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
861 STARTUPINFO si;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
862 PROCESS_INFORMATION pi;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
863 DWORD err;
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
864 DWORD flags;
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
865
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
866 xzero (si);
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
867 si.dwFlags = STARTF_USESHOWWINDOW;
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
868 si.wShowWindow = windowed ? SW_SHOWNORMAL : SW_HIDE;
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
869 if (do_io)
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
870 {
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
871 si.hStdInput = hprocin;
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
872 si.hStdOutput = hprocout;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
873 si.hStdError = hprocerr;
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
874 si.dwFlags |= STARTF_USESTDHANDLES;
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
875 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
876
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
877 flags = CREATE_SUSPENDED;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
878 if (msw_windows9x_p ())
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
879 flags |= (!NILP (Vmswindows_start_process_share_console)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
880 ? CREATE_NEW_PROCESS_GROUP
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
881 : CREATE_NEW_CONSOLE);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
882 else
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
883 flags |= CREATE_NEW_CONSOLE | CREATE_NEW_PROCESS_GROUP;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
884 if (NILP (Vmswindows_start_process_inherit_error_mode))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
885 flags |= CREATE_DEFAULT_ERROR_MODE;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
886
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
887 ensure_console_window_exists ();
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
888
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
889 err = (CreateProcess (NULL, command_line, NULL, NULL, TRUE, flags,
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
890 proc_env, (char *) XSTRING_DATA (cur_dir), &si, &pi)
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
891 ? 0 : GetLastError ());
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
892
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
893 if (do_io)
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
894 {
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
895 /* These just have been inherited; we do not need a copy */
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
896 CloseHandle (hprocin);
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
897 CloseHandle (hprocout);
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
898 CloseHandle (hprocerr);
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
899 }
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
900
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
901 /* Handle process creation failure */
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
902 if (err)
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
903 {
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
904 if (do_io)
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
905 {
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
906 CloseHandle (hmyshove);
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
907 CloseHandle (hmyslurp);
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
908 }
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
909 signal_cannot_launch (program, GetLastError ());
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
910 }
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
911
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
912 /* The process started successfully */
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
913 if (do_io)
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
914 {
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
915 NT_DATA(p)->h_process = pi.hProcess;
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
916 NT_DATA(p)->dwProcessId = pi.dwProcessId;
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
917 init_process_io_handles (p, (void*)hmyslurp, (void*)hmyshove, 0);
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
918 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
919 else
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
920 {
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
921 /* Indicate as if the process has exited immediately. */
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
922 p->status_symbol = Qexit;
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
923 CloseHandle (pi.hProcess);
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
924 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
925
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
926 ResumeThread (pi.hThread);
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
927 CloseHandle (pi.hThread);
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
928
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
929 /* Remember to enable child signals later if this is not a windowed
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
930 app. Can't do it right now because that screws up the MKS Toolkit
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
931 shell. */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
932 if (!windowed)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
933 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
934 NT_DATA(p)->need_enable_child_signals = 10;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
935 kick_status_notify ();
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
936 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
937
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
938 return ((int)pi.dwProcessId);
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
939 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
940 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
941
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
942 /*
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
943 * This method is called to update status fields of the process
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
944 * structure. If the process has not existed, this method is expected
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
945 * to do nothing.
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
946 *
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
947 * The method is called only for real child processes.
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
948 */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
949
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
950 static void
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
951 nt_update_status_if_terminated (Lisp_Process* p)
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
952 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
953 DWORD exit_code;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
954
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
955 if (NT_DATA(p)->need_enable_child_signals > 1)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
956 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
957 NT_DATA(p)->need_enable_child_signals -= 1;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
958 kick_status_notify ();
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
959 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
960 else if (NT_DATA(p)->need_enable_child_signals == 1)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
961 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
962 enable_child_signals(NT_DATA(p)->h_process);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
963 NT_DATA(p)->need_enable_child_signals = 0;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
964 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
965
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
966 if (GetExitCodeProcess (NT_DATA(p)->h_process, &exit_code)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
967 && exit_code != STILL_ACTIVE)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
968 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
969 p->tick++;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
970 p->core_dumped = 0;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
971 /* The exit code can be a code returned by process, or an
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
972 NTSTATUS value. We cannot accurately handle the latter since
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
973 it is a full 32 bit integer */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
974 if (exit_code & 0xC0000000)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
975 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
976 p->status_symbol = Qsignal;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
977 p->exit_code = exit_code & 0x1FFFFFFF;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
978 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
979 else
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
980 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
981 p->status_symbol = Qexit;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
982 p->exit_code = exit_code;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
983 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
984 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
985 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
986
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
987 /*
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
988 * Stuff the entire contents of LSTREAM to the process output pipe
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
989 */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
990
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
991 /* #### If only this function could be somehow merged with
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
992 unix_send_process... */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
993
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
994 static void
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
995 nt_send_process (Lisp_Object proc, struct lstream* lstream)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
996 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
997 volatile Lisp_Object vol_proc = proc;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
998 Lisp_Process *volatile p = XPROCESS (proc);
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
999
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
1000 /* use a reasonable-sized buffer (somewhere around the size of the
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
1001 stream buffer) so as to avoid inundating the stream with blocked
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
1002 data. */
390
c6012109f545 Import from CVS: tag r21-2-10
cvs
parents: 380
diff changeset
1003 Bufbyte chunkbuf[128];
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
1004 Bytecount chunklen;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
1005
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
1006 while (1)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
1007 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
1008 ssize_t writeret;
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
1009
390
c6012109f545 Import from CVS: tag r21-2-10
cvs
parents: 380
diff changeset
1010 chunklen = Lstream_read (lstream, chunkbuf, 128);
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
1011 if (chunklen <= 0)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
1012 break; /* perhaps should abort() if < 0?
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
1013 This should never happen. */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
1014
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
1015 /* Lstream_write() will never successfully write less than the
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
1016 amount sent in. In the worst case, it just buffers the
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
1017 unwritten data. */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
1018 writeret = Lstream_write (XLSTREAM (DATA_OUTSTREAM(p)), chunkbuf,
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
1019 chunklen);
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
1020 Lstream_flush (XLSTREAM (DATA_OUTSTREAM(p)));
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
1021 if (writeret < 0)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
1022 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
1023 p->status_symbol = Qexit;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
1024 p->exit_code = ERROR_BROKEN_PIPE;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
1025 p->core_dumped = 0;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
1026 p->tick++;
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
1027 process_tick++;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
1028 deactivate_process (*((Lisp_Object *) (&vol_proc)));
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
1029 error ("Broken pipe error sending to process %s; closed it",
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
1030 XSTRING_DATA (p->name));
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
1031 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
1032
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
1033 {
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
1034 int wait_ms = 25;
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
1035 while (Lstream_was_blocked_p (XLSTREAM (p->pipe_outstream)))
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
1036 {
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
1037 /* Buffer is full. Wait, accepting input; that may allow
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
1038 the program to finish doing output and read more. */
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
1039 Faccept_process_output (Qnil, Qzero, make_int (wait_ms));
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
1040 Lstream_flush (XLSTREAM (p->pipe_outstream));
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
1041 wait_ms = min (1000, 2 * wait_ms);
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
1042 }
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
1043 }
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
1044 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
1045 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
1046
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
1047 /*
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
1048 * Send a signal number SIGNO to PROCESS.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
1049 * CURRENT_GROUP means send to the process group that currently owns
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
1050 * the terminal being used to communicate with PROCESS.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
1051 * This is used for various commands in shell mode.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
1052 * If NOMSG is zero, insert signal-announcements into process's buffers
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
1053 * right away.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
1054 *
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
1055 * If we can, we try to signal PROCESS by sending control characters
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
1056 * down the pty. This allows us to signal inferiors who have changed
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
1057 * their uid, for which killpg would return an EPERM error.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
1058 *
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
1059 * The method signals an error if the given SIGNO is not valid
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
1060 */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
1061
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
1062 static void
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
1063 nt_kill_child_process (Lisp_Object proc, int signo,
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
1064 int current_group, int nomsg)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
1065 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
1066 Lisp_Process *p = XPROCESS (proc);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
1067
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
1068 /* Enable child signals if necessary. This may lose the first
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
1069 but it's better than nothing. */
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1070 if (NT_DATA (p)->need_enable_child_signals > 0)
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
1071 {
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1072 enable_child_signals (NT_DATA(p)->h_process);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1073 NT_DATA (p)->need_enable_child_signals = 0;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
1074 }
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
1075
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
1076 /* Signal error if SIGNO cannot be sent */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
1077 validate_signal_number (signo);
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
1078
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
1079 /* Send signal */
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1080 if (!send_signal (NT_DATA (p), 0, signo))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1081 signal_simple_error ("Cannot send signal to process", proc);
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
1082 }
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
1083
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
1084 /*
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
1085 * Kill any process in the system given its PID.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
1086 *
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
1087 * Returns zero if a signal successfully sent, or
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
1088 * negative number upon failure
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
1089 */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
1090 static int
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
1091 nt_kill_process_by_pid (int pid, int signo)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
1092 {
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1093 struct Lisp_Process *p;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1094
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
1095 /* Signal error if SIGNO cannot be sent */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
1096 validate_signal_number (signo);
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
1097
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1098 p = find_process_from_pid (pid);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1099 return send_signal (p ? NT_DATA (p) : 0, pid, signo) ? 0 : -1;
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
1100 }
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1101
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1102 /*-----------------------------------------------------------------------*/
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1103 /* Sockets connections */
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1104 /*-----------------------------------------------------------------------*/
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1105 #ifdef HAVE_SOCKETS
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
1106
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1107 /* #### Hey MS, how long Winsock 2 for '95 will be in beta? */
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1108
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1109 #define SOCK_TIMER_ID 666
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1110 #define XM_SOCKREPLY (WM_USER + 666)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1111
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1112 static int
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1113 get_internet_address (Lisp_Object host, struct sockaddr_in *address,
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1114 Error_behavior errb)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1115 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1116 char buf [MAXGETHOSTSTRUCT];
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1117 HWND hwnd;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1118 HANDLE hasync;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1119 int success = 0;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1120
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1121 address->sin_family = AF_INET;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1122
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1123 /* First check if HOST is already a numeric address */
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1124 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1125 unsigned long inaddr = inet_addr (XSTRING_DATA (host));
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1126 if (inaddr != INADDR_NONE)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1127 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1128 address->sin_addr.s_addr = inaddr;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1129 return 1;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1130 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1131 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1132
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1133 /* Create a window which will receive completion messages */
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1134 hwnd = CreateWindow ("STATIC", NULL, WS_OVERLAPPED, 0, 0, 1, 1,
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1135 NULL, NULL, NULL, NULL);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1136 assert (hwnd);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1137
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1138 /* Post name resolution request */
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1139 hasync = WSAAsyncGetHostByName (hwnd, XM_SOCKREPLY, XSTRING_DATA (host),
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1140 buf, sizeof (buf));
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1141 if (hasync == NULL)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1142 goto done;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1143
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1144 /* Set a timer to poll for quit every 250 ms */
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1145 SetTimer (hwnd, SOCK_TIMER_ID, 250, NULL);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1146
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1147 while (1)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1148 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1149 MSG msg;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1150 GetMessage (&msg, hwnd, 0, 0);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1151 if (msg.message == XM_SOCKREPLY)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1152 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1153 /* Ok, got an answer */
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1154 if (WSAGETASYNCERROR(msg.lParam) == NO_ERROR)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1155 success = 1;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
1156 else
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
1157 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
1158 warn_when_safe(Qstream, Qwarning,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
1159 "cannot get IP address for host \"%s\"",
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
1160 XSTRING_DATA (host));
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
1161 }
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1162 goto done;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1163 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1164 else if (msg.message == WM_TIMER && msg.wParam == SOCK_TIMER_ID)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1165 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1166 if (QUITP)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1167 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1168 WSACancelAsyncRequest (hasync);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1169 KillTimer (hwnd, SOCK_TIMER_ID);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1170 DestroyWindow (hwnd);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1171 REALLY_QUIT;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1172 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1173 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1174 DispatchMessage (&msg);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1175 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1176
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1177 done:
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1178 KillTimer (hwnd, SOCK_TIMER_ID);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1179 DestroyWindow (hwnd);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1180 if (success)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1181 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1182 /* BUF starts with struct hostent */
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1183 struct hostent* he = (struct hostent*) buf;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1184 address->sin_addr.s_addr = *(unsigned long*)he->h_addr_list[0];
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1185 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1186 return success;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1187 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1188
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1189 static Lisp_Object
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1190 nt_canonicalize_host_name (Lisp_Object host)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1191 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1192 struct sockaddr_in address;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1193
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1194 if (!get_internet_address (host, &address, ERROR_ME_NOT))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1195 return host;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1196
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1197 if (address.sin_family == AF_INET)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1198 return build_string (inet_ntoa (address.sin_addr));
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1199 else
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1200 return host;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1201 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1202
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1203 /* open a TCP network connection to a given HOST/SERVICE. Treated
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1204 exactly like a normal process when reading and writing. Only
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1205 differences are in status display and process deletion. A network
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1206 connection has no PID; you cannot signal it. All you can do is
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1207 deactivate and close it via delete-process */
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1208
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1209 static void
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1210 nt_open_network_stream (Lisp_Object name, Lisp_Object host,
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1211 Lisp_Object service,
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
1212 Lisp_Object protocol, void** vinfd, void** voutfd)
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1213 {
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1214 /* !!#### not Mule-ized */
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1215 struct sockaddr_in address;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1216 SOCKET s;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1217 int port;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1218 int retval;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1219
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1220 CHECK_STRING (host);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1221
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
1222 if (!EQ (protocol, Qtcp))
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1223 signal_simple_error ("Unsupported protocol", protocol);
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1224
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1225 if (INTP (service))
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1226 port = htons ((unsigned short) XINT (service));
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1227 else
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1228 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1229 struct servent *svc_info;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1230 CHECK_STRING (service);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1231 svc_info = getservbyname ((char *) XSTRING_DATA (service), "tcp");
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1232 if (svc_info == 0)
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1233 signal_simple_error ("Unknown service", service);
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1234 port = svc_info->s_port;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1235 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1236
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1237 get_internet_address (host, &address, ERROR_ME);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1238 address.sin_port = port;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1239
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1240 s = socket (address.sin_family, SOCK_STREAM, 0);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1241 if (s < 0)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1242 report_file_error ("error creating socket", list1 (name));
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1243
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1244 /* We don't want to be blocked on connect */
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1245 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 390
diff changeset
1246 unsigned long nonblock = 1;
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1247 ioctlsocket (s, FIONBIO, &nonblock);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1248 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1249
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1250 retval = connect (s, (struct sockaddr *) &address, sizeof (address));
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1251 if (retval != NO_ERROR && WSAGetLastError() != WSAEWOULDBLOCK)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1252 goto connect_failed;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1253 /* Wait while connection is established */
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1254 while (1)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1255 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1256 fd_set fdset;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1257 struct timeval tv;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1258 int nsel;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1259
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1260 if (QUITP)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1261 {
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1262 closesocket (s);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1263 REALLY_QUIT;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1264 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1265
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1266 /* Poll for quit every 250 ms */
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1267 tv.tv_sec = 0;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1268 tv.tv_usec = 250 * 1000;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1269
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1270 FD_ZERO (&fdset);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1271 FD_SET (s, &fdset);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1272 nsel = select (0, NULL, &fdset, &fdset, &tv);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1273
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1274 if (nsel > 0)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1275 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 373
diff changeset
1276 /* Check: was connection successful or not? */
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1277 tv.tv_usec = 0;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1278 nsel = select (0, NULL, NULL, &fdset, &tv);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1279 if (nsel > 0)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1280 goto connect_failed;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1281 else
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1282 break;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1283 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1284 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1285
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1286 /* We are connected at this point */
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1287 *vinfd = (void*)s;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1288 DuplicateHandle (GetCurrentProcess(), (HANDLE)s,
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1289 GetCurrentProcess(), (LPHANDLE)voutfd,
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1290 0, FALSE, DUPLICATE_SAME_ACCESS);
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1291 return;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1292
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1293 connect_failed:
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1294 closesocket (s);
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1295 if (INTP (service))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1296 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1297 warn_when_safe (Qstream, Qwarning,
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1298 "failure to open network stream to host \"%s\" for service \"%d\"",
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1299 XSTRING_DATA (host),
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1300 (unsigned short) XINT (service));
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1301 }
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1302 else
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1303 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1304 warn_when_safe (Qstream, Qwarning,
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1305 "failure to open network stream to host \"%s\" for service \"%s\"",
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1306 XSTRING_DATA (host),
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1307 XSTRING_DATA (service));
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1308 }
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1309 report_file_error ("connection failed", list2 (host, name));
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1310 }
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1311
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1312 #endif
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
1313
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
1314 /*-----------------------------------------------------------------------*/
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
1315 /* Initialization */
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
1316 /*-----------------------------------------------------------------------*/
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
1317
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
1318 void
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
1319 process_type_create_nt (void)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
1320 {
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
1321 PROCESS_HAS_METHOD (nt, alloc_process_data);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
1322 PROCESS_HAS_METHOD (nt, finalize_process_data);
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1323 PROCESS_HAS_METHOD (nt, init_process);
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
1324 PROCESS_HAS_METHOD (nt, create_process);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
1325 PROCESS_HAS_METHOD (nt, update_status_if_terminated);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
1326 PROCESS_HAS_METHOD (nt, send_process);
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
1327 PROCESS_HAS_METHOD (nt, kill_child_process);
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
1328 PROCESS_HAS_METHOD (nt, kill_process_by_pid);
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
1329 #ifdef HAVE_SOCKETS
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
1330 PROCESS_HAS_METHOD (nt, canonicalize_host_name);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
1331 PROCESS_HAS_METHOD (nt, open_network_stream);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
1332 #ifdef HAVE_MULTICAST
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
1333 #error I won't do this until '95 has winsock2
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
1334 PROCESS_HAS_METHOD (nt, open_multicast_group);
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
1335 #endif
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
1336 #endif
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
1337 }
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
1338
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
1339 void
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
1340 syms_of_process_nt (void)
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
1341 {
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
1342 defsymbol (&Qnt_quote_process_args, "nt-quote-process-args");
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
1343 }
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
1344
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
1345 void
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
1346 vars_of_process_nt (void)
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
1347 {
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1348 DEFVAR_LISP ("mswindows-start-process-share-console",
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1349 &Vmswindows_start_process_share_console /*
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1350 When nil, new child processes are given a new console.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1351 When non-nil, they share the Emacs console; this has the limitation of
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1352 allowing only only DOS subprocess to run at a time (whether started directly
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1353 or indirectly by Emacs), and preventing Emacs from cleanly terminating the
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1354 subprocess group, but may allow Emacs to interrupt a subprocess that doesn't
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1355 otherwise respond to interrupts from Emacs.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1356 */ );
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1357 Vmswindows_start_process_share_console = Qnil;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1358
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1359 DEFVAR_LISP ("mswindows-start-process-inherit-error-mode",
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1360 &Vmswindows_start_process_inherit_error_mode /*
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1361 "When nil, new child processes revert to the default error mode.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1362 When non-nil, they inherit their error mode setting from Emacs, which stops
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1363 them blocking when trying to access unmounted drives etc.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1364 */ );
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
1365 Vmswindows_start_process_inherit_error_mode = Qt;
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents:
diff changeset
1366 }