Mercurial > hg > xemacs-beta
annotate src/process.c @ 4710:3a87551bfeb5
Fixes for a number of minor warnings issued by gcc. See xemacs-patches message
<870180fe0910051206s13dca5c3j6303732e33c478f5@mail.gmail.com>.
| author | Jerry James <james@xemacs.org> |
|---|---|
| date | Mon, 05 Oct 2009 13:07:34 -0600 |
| parents | 80cd90837ac5 |
| children | 428d7c571110 |
| rev | line source |
|---|---|
| 428 | 1 /* Asynchronous subprocess control for XEmacs. |
| 2 Copyright (C) 1985, 1986, 1987, 1988, 1992, 1993, 1994, 1995 | |
| 3 Free Software Foundation, Inc. | |
| 4 Copyright (C) 1995 Sun Microsystems, Inc. | |
| 3025 | 5 Copyright (C) 1995, 1996, 2001, 2002, 2004, 2005 Ben Wing. |
| 428 | 6 |
| 7 This file is part of XEmacs. | |
| 8 | |
| 9 XEmacs is free software; you can redistribute it and/or modify it | |
| 10 under the terms of the GNU General Public License as published by the | |
| 11 Free Software Foundation; either version 2, or (at your option) any | |
| 12 later version. | |
| 13 | |
| 14 XEmacs is distributed in the hope that it will be useful, but WITHOUT | |
| 15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 17 for more details. | |
| 18 | |
| 19 You should have received a copy of the GNU General Public License | |
| 20 along with XEmacs; see the file COPYING. If not, write to | |
| 21 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
| 22 Boston, MA 02111-1307, USA. */ | |
| 23 | |
| 814 | 24 /* This file has been Mule-ized. */ |
| 428 | 25 |
| 26 /* This file has been split into process.c and process-unix.c by | |
| 27 Kirill M. Katsnelson <kkm@kis.ru>, so please bash him and not | |
| 814 | 28 the original author(s). |
| 29 | |
| 30 Non-synch-subprocess stuff (mostly process environment) moved from | |
| 853 | 31 callproc.c, 4-3-02, Ben Wing. |
| 32 | |
| 33 callproc.c deleted entirely 5-23-02, Ben Wing. Good riddance! | |
| 34 */ | |
| 428 | 35 |
| 36 #include <config.h> | |
| 37 | |
| 814 | 38 #if defined (NO_SUBPROCESSES) |
| 39 #error "We don't support this anymore." | |
| 40 #endif | |
| 428 | 41 |
| 42 #include "lisp.h" | |
| 43 | |
| 44 #include "buffer.h" | |
| 45 #include "commands.h" | |
| 800 | 46 #include "device.h" |
| 428 | 47 #include "events.h" |
| 800 | 48 #include "file-coding.h" |
| 428 | 49 #include "frame.h" |
| 50 #include "hash.h" | |
| 51 #include "insdel.h" | |
| 52 #include "lstream.h" | |
| 53 #include "opaque.h" | |
| 54 #include "process.h" | |
| 55 #include "procimpl.h" | |
| 816 | 56 #include "sysdep.h" |
| 428 | 57 #include "window.h" |
| 58 | |
| 59 #include "sysfile.h" | |
| 60 #include "sysproc.h" | |
| 859 | 61 #include "syssignal.h" |
| 428 | 62 #include "systime.h" |
| 63 #include "systty.h" | |
| 64 #include "syswait.h" | |
| 65 | |
| 2367 | 66 #ifdef WIN32_NATIVE |
| 67 #include "syswindows.h" | |
| 68 #endif | |
| 69 | |
| 863 | 70 Lisp_Object Qprocessp, Qprocess_live_p, Qprocess_readable_p; |
| 428 | 71 |
| 72 /* Process methods */ | |
| 73 struct process_methods the_process_methods; | |
| 74 | |
| 75 /* a process object is a network connection when its pid field a cons | |
| 76 (name of name of port we are connected to . foreign host name) */ | |
| 77 | |
| 78 /* Valid values of process->status_symbol */ | |
| 79 Lisp_Object Qrun, Qstop; | |
| 80 /* Qrun => Qopen, Qexit => Qclosed for "network connection" processes */ | |
| 81 Lisp_Object Qopen, Qclosed; | |
| 82 /* Protocol families */ | |
| 83 Lisp_Object Qtcp, Qudp; | |
| 84 | |
| 85 #ifdef HAVE_MULTICAST | |
| 86 Lisp_Object Qmulticast; /* Will be used for occasional warnings */ | |
| 87 #endif | |
| 88 | |
| 89 /* t means use pty, nil means use a pipe, | |
| 90 maybe other values to come. */ | |
| 91 Lisp_Object Vprocess_connection_type; | |
| 92 | |
| 93 /* Read comments to DEFVAR of this */ | |
| 94 int windowed_process_io; | |
| 95 | |
| 96 #ifdef PROCESS_IO_BLOCKING | |
| 97 /* List of port numbers or port names to set a blocking I/O mode. | |
| 98 Nil means set a non-blocking I/O mode [default]. */ | |
| 99 Lisp_Object network_stream_blocking_port_list; | |
| 100 #endif /* PROCESS_IO_BLOCKING */ | |
| 101 | |
| 102 /* Number of events of change of status of a process. */ | |
| 103 volatile int process_tick; | |
| 104 | |
| 105 /* Number of events for which the user or sentinel has been notified. */ | |
| 106 static int update_tick; | |
| 107 | |
| 108 /* Nonzero means delete a process right away if it exits. */ | |
| 109 int delete_exited_processes; | |
| 110 | |
| 853 | 111 /* Hash table which maps USIDs as returned by create_io_streams_cb to |
| 428 | 112 process objects. Processes are not GC-protected through this! */ |
| 113 struct hash_table *usid_to_process; | |
| 114 | |
| 115 /* List of process objects. */ | |
| 116 Lisp_Object Vprocess_list; | |
| 117 | |
| 442 | 118 Lisp_Object Vnull_device; |
| 428 | 119 |
| 771 | 120 /* Cons of coding systems used to initialize process I/O on a newly- |
| 121 created process. */ | |
| 122 Lisp_Object Vdefault_process_coding_system; | |
| 853 | 123 /* Same for a network connection. */ |
| 124 Lisp_Object Vdefault_network_coding_system; | |
| 771 | 125 |
| 563 | 126 Lisp_Object Qprocess_error; |
| 127 Lisp_Object Qnetwork_error; | |
| 128 | |
| 771 | 129 Fixnum debug_process_io; |
| 130 | |
| 814 | 131 Lisp_Object Vshell_file_name; |
| 132 | |
| 133 /* The environment to pass to all subprocesses when they are started. | |
| 134 This is in the semi-bogus format of ("VAR=VAL" "VAR2=VAL2" ... ) | |
| 135 */ | |
| 136 Lisp_Object Vprocess_environment; | |
| 137 | |
| 138 /* Make sure egetenv() not called too soon */ | |
| 139 int env_initted; | |
| 140 | |
| 141 Lisp_Object Vlisp_EXEC_SUFFIXES; | |
| 142 | |
| 428 | 143 |
| 144 | |
| 1204 | 145 static const struct memory_description process_description [] = { |
| 146 #define MARKED_SLOT(x) { XD_LISP_OBJECT, offsetof (Lisp_Process, x) }, | |
| 147 #include "process-slots.h" | |
| 934 | 148 { XD_END } |
| 149 }; | |
| 150 | |
| 428 | 151 static Lisp_Object |
| 444 | 152 mark_process (Lisp_Object object) |
| 428 | 153 { |
| 444 | 154 Lisp_Process *process = XPROCESS (object); |
| 1204 | 155 #define MARKED_SLOT(x) mark_object (process->x); |
| 156 #include "process-slots.h" | |
| 157 return Qnil; | |
| 428 | 158 } |
| 159 | |
| 160 static void | |
| 444 | 161 print_process (Lisp_Object object, Lisp_Object printcharfun, int escapeflag) |
| 428 | 162 { |
| 444 | 163 Lisp_Process *process = XPROCESS (object); |
| 428 | 164 |
| 165 if (print_readably) | |
| 563 | 166 printing_unreadable_object ("#<process %s>", XSTRING_DATA (process->name)); |
| 428 | 167 |
| 168 if (!escapeflag) | |
| 169 { | |
| 444 | 170 print_internal (process->name, printcharfun, 0); |
| 428 | 171 } |
| 172 else | |
| 173 { | |
| 444 | 174 int netp = network_connection_p (object); |
| 826 | 175 write_c_string (printcharfun, |
| 176 netp ? GETTEXT ("#<network connection ") : | |
| 177 GETTEXT ("#<process ")); | |
| 444 | 178 print_internal (process->name, printcharfun, 1); |
| 826 | 179 write_c_string (printcharfun, (netp ? " " : " pid ")); |
| 444 | 180 print_internal (process->pid, printcharfun, 1); |
| 800 | 181 write_fmt_string_lisp (printcharfun, " state:%S", 1, process->status_symbol); |
| 444 | 182 MAYBE_PROCMETH (print_process_data, (process, printcharfun)); |
| 826 | 183 write_c_string (printcharfun, ">"); |
| 428 | 184 } |
| 185 } | |
| 186 | |
| 187 #ifdef HAVE_WINDOW_SYSTEM | |
| 440 | 188 extern void debug_process_finalization (Lisp_Process *p); |
| 428 | 189 #endif /* HAVE_WINDOW_SYSTEM */ |
| 190 | |
| 191 static void | |
| 192 finalize_process (void *header, int for_disksave) | |
| 193 { | |
| 194 /* #### this probably needs to be tied into the tty event loop */ | |
| 195 /* #### when there is one */ | |
| 440 | 196 Lisp_Process *p = (Lisp_Process *) header; |
| 428 | 197 #ifdef HAVE_WINDOW_SYSTEM |
| 198 if (!for_disksave) | |
| 199 { | |
| 200 debug_process_finalization (p); | |
| 201 } | |
| 202 #endif /* HAVE_WINDOW_SYSTEM */ | |
| 203 | |
| 204 if (p->process_data) | |
| 205 { | |
| 206 MAYBE_PROCMETH (finalize_process_data, (p, for_disksave)); | |
| 207 if (!for_disksave) | |
| 1726 | 208 xfree (p->process_data, void *); |
| 428 | 209 } |
| 210 } | |
| 211 | |
| 934 | 212 DEFINE_LRECORD_IMPLEMENTATION ("process", process, |
| 213 0, /*dumpable-flag*/ | |
| 214 mark_process, print_process, finalize_process, | |
| 215 0, 0, process_description, Lisp_Process); | |
| 428 | 216 |
| 217 /************************************************************************/ | |
| 218 /* basic process accessors */ | |
| 219 /************************************************************************/ | |
| 220 | |
| 771 | 221 /* This function returns low-level streams, connected directly to the child |
| 222 process, rather than en/decoding streams */ | |
| 428 | 223 void |
| 853 | 224 get_process_streams (Lisp_Process *p, Lisp_Object *instr, Lisp_Object *outstr, |
| 225 Lisp_Object *errstr) | |
| 428 | 226 { |
| 227 assert (p); | |
| 853 | 228 assert (NILP (p->pipe_instream) || LSTREAMP (p->pipe_instream)); |
| 229 assert (NILP (p->pipe_outstream) || LSTREAMP (p->pipe_outstream)); | |
| 230 assert (NILP (p->pipe_errstream) || LSTREAMP (p->pipe_errstream)); | |
| 428 | 231 *instr = p->pipe_instream; |
| 232 *outstr = p->pipe_outstream; | |
| 853 | 233 *errstr = p->pipe_errstream; |
| 428 | 234 } |
| 235 | |
| 853 | 236 /* Given a USID referring to either a process's instream or errstream, |
| 237 return the associated process. */ | |
| 440 | 238 Lisp_Process * |
| 428 | 239 get_process_from_usid (USID usid) |
| 240 { | |
| 442 | 241 const void *vval; |
| 428 | 242 |
| 243 assert (usid != USID_ERROR && usid != USID_DONTHASH); | |
| 244 | |
| 442 | 245 if (gethash ((const void*)usid, usid_to_process, &vval)) |
| 428 | 246 { |
| 444 | 247 Lisp_Object process; |
| 826 | 248 process = VOID_TO_LISP (vval); |
| 444 | 249 return XPROCESS (process); |
| 428 | 250 } |
| 251 else | |
| 252 return 0; | |
| 253 } | |
| 254 | |
| 255 int | |
| 853 | 256 get_process_selected_p (Lisp_Process *p, int do_err) |
| 428 | 257 { |
| 853 | 258 return do_err ? p->err_selected : p->in_selected; |
| 428 | 259 } |
| 260 | |
| 261 void | |
| 853 | 262 set_process_selected_p (Lisp_Process *p, int in_selected, int err_selected) |
| 428 | 263 { |
| 853 | 264 p->in_selected = !!in_selected; |
| 265 p->err_selected = !!err_selected; | |
| 428 | 266 } |
| 267 | |
| 268 int | |
| 440 | 269 connected_via_filedesc_p (Lisp_Process *p) |
| 428 | 270 { |
| 271 return MAYBE_INT_PROCMETH (tooltalk_connection_p, (p)); | |
| 272 } | |
| 273 | |
| 274 #ifdef HAVE_SOCKETS | |
| 275 int | |
| 276 network_connection_p (Lisp_Object process) | |
| 277 { | |
| 278 return CONSP (XPROCESS (process)->pid); | |
| 279 } | |
| 280 #endif | |
| 281 | |
| 282 DEFUN ("processp", Fprocessp, 1, 1, 0, /* | |
| 283 Return t if OBJECT is a process. | |
| 284 */ | |
| 444 | 285 (object)) |
| 428 | 286 { |
| 444 | 287 return PROCESSP (object) ? Qt : Qnil; |
| 428 | 288 } |
| 289 | |
| 440 | 290 DEFUN ("process-live-p", Fprocess_live_p, 1, 1, 0, /* |
| 291 Return t if OBJECT is a process that is alive. | |
| 292 */ | |
| 444 | 293 (object)) |
| 440 | 294 { |
| 444 | 295 return PROCESSP (object) && PROCESS_LIVE_P (XPROCESS (object)) |
| 296 ? Qt : Qnil; | |
| 440 | 297 } |
| 298 | |
| 863 | 299 #if 0 |
| 300 /* This is a reasonable definition for this new primitive. Kyle sez: | |
| 301 | |
| 302 "The patch looks OK to me except for the creation and exporting of the | |
| 303 Fprocess_readable_p function. I don't think a new Lisp function | |
| 304 should be created until we know something actually needs it. If | |
| 305 we later want to give process-readable-p different semantics it | |
| 306 may be hard to do it and stay compatible with what we hastily | |
| 307 create today." | |
| 308 | |
| 309 He's right, not yet. Let's discuss the semantics on XEmacs Design | |
| 310 before enabling this. | |
| 311 */ | |
| 312 DEFUN ("process-readable-p", Fprocess_readable_p, 1, 1, 0, /* | |
| 313 Return t if OBJECT is a process from which input may be available. | |
| 314 */ | |
| 315 (object)) | |
| 316 { | |
| 317 return PROCESSP (object) && PROCESS_READABLE_P (XPROCESS (object)) | |
| 318 ? Qt : Qnil; | |
| 319 } | |
| 320 #endif | |
| 321 | |
| 428 | 322 DEFUN ("process-list", Fprocess_list, 0, 0, 0, /* |
| 323 Return a list of all processes. | |
| 324 */ | |
| 325 ()) | |
| 326 { | |
| 327 return Fcopy_sequence (Vprocess_list); | |
| 328 } | |
| 329 | |
| 330 DEFUN ("get-process", Fget_process, 1, 1, 0, /* | |
| 444 | 331 Return the process named PROCESS-NAME (a string), or nil if there is none. |
| 332 PROCESS-NAME may also be a process; if so, the value is that process. | |
| 428 | 333 */ |
| 444 | 334 (process_name)) |
| 428 | 335 { |
| 444 | 336 if (PROCESSP (process_name)) |
| 337 return process_name; | |
| 428 | 338 |
| 339 if (!gc_in_progress) | |
| 340 /* this only gets called during GC when emacs is going away as a result | |
| 341 of a signal or crash. */ | |
| 444 | 342 CHECK_STRING (process_name); |
| 428 | 343 |
| 444 | 344 { |
| 345 LIST_LOOP_2 (process, Vprocess_list) | |
| 346 if (internal_equal (process_name, XPROCESS (process)->name, 0)) | |
| 347 return process; | |
| 348 } | |
| 428 | 349 return Qnil; |
| 350 } | |
| 351 | |
| 352 DEFUN ("get-buffer-process", Fget_buffer_process, 1, 1, 0, /* | |
| 353 Return the (or, a) process associated with BUFFER. | |
| 354 BUFFER may be a buffer or the name of one. | |
| 355 */ | |
| 444 | 356 (buffer)) |
| 428 | 357 { |
| 444 | 358 if (NILP (buffer)) return Qnil; |
| 359 buffer = Fget_buffer (buffer); | |
| 360 if (NILP (buffer)) return Qnil; | |
| 428 | 361 |
| 444 | 362 { |
| 363 LIST_LOOP_2 (process, Vprocess_list) | |
| 364 if (EQ (XPROCESS (process)->buffer, buffer)) | |
| 365 return process; | |
| 366 } | |
| 428 | 367 return Qnil; |
| 368 } | |
| 369 | |
| 370 /* This is how commands for the user decode process arguments. It | |
| 371 accepts a process, a process name, a buffer, a buffer name, or nil. | |
| 372 Buffers denote the first process in the buffer, and nil denotes the | |
| 373 current buffer. */ | |
| 374 | |
| 375 static Lisp_Object | |
| 376 get_process (Lisp_Object name) | |
| 377 { | |
| 444 | 378 Lisp_Object buffer; |
| 428 | 379 |
| 380 #ifdef I18N3 | |
| 381 /* #### Look more closely into translating process names. */ | |
| 382 #endif | |
| 383 | |
| 384 /* This may be called during a GC from process_send_signal() from | |
| 2500 | 385 kill_buffer_processes() if emacs decides to ABORT(). */ |
| 428 | 386 if (PROCESSP (name)) |
| 387 return name; | |
| 444 | 388 else if (STRINGP (name)) |
| 428 | 389 { |
| 444 | 390 Lisp_Object object = Fget_process (name); |
| 391 if (PROCESSP (object)) | |
| 392 return object; | |
| 393 | |
| 394 buffer = Fget_buffer (name); | |
| 395 if (BUFFERP (buffer)) | |
| 396 goto have_buffer_object; | |
| 397 | |
| 563 | 398 invalid_argument ("Process does not exist", name); |
| 428 | 399 } |
| 400 else if (NILP (name)) | |
| 444 | 401 { |
| 402 buffer = Fcurrent_buffer (); | |
| 403 goto have_buffer_object; | |
| 404 } | |
| 405 else if (BUFFERP (name)) | |
| 406 { | |
| 407 Lisp_Object process; | |
| 408 buffer = name; | |
| 428 | 409 |
| 444 | 410 have_buffer_object: |
| 411 process = Fget_buffer_process (buffer); | |
| 412 if (PROCESSP (process)) | |
| 413 return process; | |
| 414 | |
| 563 | 415 invalid_argument ("Buffer has no process", buffer); |
| 428 | 416 } |
| 417 else | |
| 444 | 418 return get_process (Fsignal (Qwrong_type_argument, |
| 771 | 419 (list2 (build_msg_string ("process or buffer or nil"), |
| 444 | 420 name)))); |
| 428 | 421 } |
| 422 | |
| 423 DEFUN ("process-id", Fprocess_id, 1, 1, 0, /* | |
| 424 Return the process id of PROCESS. | |
| 425 This is the pid of the Unix process which PROCESS uses or talks to. | |
| 426 For a network connection, this value is a cons of | |
| 427 (foreign-network-port . foreign-host-name). | |
| 428 */ | |
| 444 | 429 (process)) |
| 428 | 430 { |
| 431 Lisp_Object pid; | |
| 444 | 432 CHECK_PROCESS (process); |
| 428 | 433 |
| 444 | 434 pid = XPROCESS (process)->pid; |
| 435 if (network_connection_p (process)) | |
| 428 | 436 /* return Qnil; */ |
| 437 return Fcons (Fcar (pid), Fcdr (pid)); | |
| 438 else | |
| 439 return pid; | |
| 440 } | |
| 441 | |
| 442 DEFUN ("process-name", Fprocess_name, 1, 1, 0, /* | |
| 443 Return the name of PROCESS, as a string. | |
| 444 This is the name of the program invoked in PROCESS, | |
| 445 possibly modified to make it unique among process names. | |
| 446 */ | |
| 444 | 447 (process)) |
| 428 | 448 { |
| 444 | 449 CHECK_PROCESS (process); |
| 450 return XPROCESS (process)->name; | |
| 428 | 451 } |
| 452 | |
| 453 DEFUN ("process-command", Fprocess_command, 1, 1, 0, /* | |
| 454 Return the command that was executed to start PROCESS. | |
| 455 This is a list of strings, the first string being the program executed | |
| 456 and the rest of the strings being the arguments given to it. | |
| 457 */ | |
| 444 | 458 (process)) |
| 428 | 459 { |
| 444 | 460 CHECK_PROCESS (process); |
| 461 return XPROCESS (process)->command; | |
| 428 | 462 } |
| 463 | |
| 464 | |
| 465 /************************************************************************/ | |
| 466 /* creating a process */ | |
| 467 /************************************************************************/ | |
| 468 | |
| 563 | 469 DOESNT_RETURN |
| 470 report_process_error (const char *string, Lisp_Object data) | |
| 471 { | |
| 472 report_error_with_errno (Qprocess_error, string, data); | |
| 473 } | |
| 474 | |
| 475 DOESNT_RETURN | |
| 476 report_network_error (const char *string, Lisp_Object data) | |
| 477 { | |
| 478 report_error_with_errno (Qnetwork_error, string, data); | |
| 479 } | |
| 480 | |
| 428 | 481 Lisp_Object |
| 482 make_process_internal (Lisp_Object name) | |
| 483 { | |
| 484 Lisp_Object val, name1; | |
| 485 int i; | |
| 3017 | 486 Lisp_Process *p = ALLOC_LCRECORD_TYPE (Lisp_Process, &lrecord_process); |
| 428 | 487 |
| 1204 | 488 #define MARKED_SLOT(x) p->x = Qnil; |
| 489 #include "process-slots.h" | |
| 490 | |
| 428 | 491 /* If name is already in use, modify it until it is unused. */ |
| 492 name1 = name; | |
| 493 for (i = 1; ; i++) | |
| 494 { | |
| 495 char suffix[10]; | |
| 496 Lisp_Object tem = Fget_process (name1); | |
| 497 if (NILP (tem)) | |
| 498 break; | |
| 499 sprintf (suffix, "<%d>", i); | |
| 500 name1 = concat2 (name, build_string (suffix)); | |
| 501 } | |
| 502 name = name1; | |
| 503 p->name = name; | |
| 504 | |
| 505 p->mark = Fmake_marker (); | |
| 853 | 506 p->stderr_mark = Fmake_marker (); |
| 428 | 507 p->status_symbol = Qrun; |
| 508 | |
| 509 MAYBE_PROCMETH (alloc_process_data, (p)); | |
| 510 | |
| 793 | 511 val = wrap_process (p); |
| 428 | 512 |
| 513 Vprocess_list = Fcons (val, Vprocess_list); | |
| 514 return val; | |
| 515 } | |
| 516 | |
| 517 void | |
| 853 | 518 init_process_io_handles (Lisp_Process *p, void* in, void* out, void* err, |
| 519 int flags) | |
| 428 | 520 { |
| 853 | 521 USID in_usid, err_usid; |
| 771 | 522 Lisp_Object incode, outcode; |
| 523 | |
| 853 | 524 if (flags & STREAM_NETWORK_CONNECTION) |
| 525 { | |
| 526 if (!CONSP (Vdefault_network_coding_system) || | |
| 527 NILP (incode = (find_coding_system_for_text_file | |
| 528 (Fcar (Vdefault_network_coding_system), 1))) || | |
| 529 NILP (outcode = (find_coding_system_for_text_file | |
| 530 (Fcdr (Vdefault_network_coding_system), 0)))) | |
| 531 signal_error (Qinvalid_state, | |
| 532 "Bogus value for `default-network-coding-system'", | |
| 533 Vdefault_network_coding_system); | |
| 534 } | |
| 535 else | |
| 536 { | |
| 537 if (!CONSP (Vdefault_process_coding_system) || | |
| 538 NILP (incode = (find_coding_system_for_text_file | |
| 539 (Fcar (Vdefault_process_coding_system), 1))) || | |
| 540 NILP (outcode = (find_coding_system_for_text_file | |
| 541 (Fcdr (Vdefault_process_coding_system), 0)))) | |
| 542 signal_error (Qinvalid_state, | |
| 543 "Bogus value for `default-process-coding-system'", | |
| 544 Vdefault_process_coding_system); | |
| 545 } | |
| 771 | 546 |
| 784 | 547 if (!NILP (Vcoding_system_for_read) && |
| 548 NILP (incode = (find_coding_system_for_text_file | |
| 549 (Vcoding_system_for_read, 1)))) | |
| 550 signal_error (Qinvalid_state, | |
| 551 "Bogus value for `coding-system-for-read'", | |
| 552 Vcoding_system_for_read); | |
| 553 | |
| 554 if (!NILP (Vcoding_system_for_write) && | |
| 555 NILP (outcode = (find_coding_system_for_text_file | |
| 556 (Vcoding_system_for_write, 0)))) | |
| 557 signal_error (Qinvalid_state, | |
| 558 "Bogus value for `coding-system-for-write'", | |
| 559 Vcoding_system_for_write); | |
| 560 | |
| 853 | 561 event_stream_create_io_streams (in, out, err, |
| 562 &p->pipe_instream, | |
| 563 &p->pipe_outstream, | |
| 564 &p->pipe_errstream, | |
| 565 &in_usid, &err_usid, | |
| 566 flags); | |
| 428 | 567 |
| 853 | 568 if (in_usid == USID_ERROR || err_usid == USID_ERROR) |
| 563 | 569 signal_error (Qprocess_error, "Setting up communication with subprocess", |
| 853 | 570 wrap_process (p)); |
| 428 | 571 |
| 853 | 572 if (in_usid != USID_DONTHASH) |
| 428 | 573 { |
| 444 | 574 Lisp_Object process = Qnil; |
| 793 | 575 process = wrap_process (p); |
| 853 | 576 puthash ((const void*) in_usid, LISP_TO_VOID (process), usid_to_process); |
| 428 | 577 } |
| 578 | |
| 853 | 579 if (err_usid != USID_DONTHASH) |
| 580 { | |
| 581 Lisp_Object process = Qnil; | |
| 582 process = wrap_process (p); | |
| 583 puthash ((const void*) err_usid, LISP_TO_VOID (process), | |
| 584 usid_to_process); | |
| 585 } | |
| 586 | |
| 587 MAYBE_PROCMETH (init_process_io_handles, (p, in, out, err, flags)); | |
| 428 | 588 |
| 771 | 589 p->coding_instream = |
| 800 | 590 make_coding_input_stream (XLSTREAM (p->pipe_instream), incode, |
| 591 CODING_DECODE, 0); | |
| 853 | 592 if (!NILP (p->pipe_errstream)) |
| 593 p->coding_errstream = | |
| 594 make_coding_input_stream | |
| 595 (XLSTREAM (p->pipe_errstream), incode, CODING_DECODE, 0); | |
| 771 | 596 p->coding_outstream = |
| 800 | 597 make_coding_output_stream (XLSTREAM (p->pipe_outstream), outcode, |
| 598 CODING_ENCODE, 0); | |
| 428 | 599 } |
| 600 | |
| 601 static void | |
| 602 create_process (Lisp_Object process, Lisp_Object *argv, int nargv, | |
| 853 | 603 Lisp_Object program, Lisp_Object cur_dir, |
| 604 int separate_err) | |
| 428 | 605 { |
| 440 | 606 Lisp_Process *p = XPROCESS (process); |
| 428 | 607 int pid; |
| 608 | |
| 609 /* *_create_process may change status_symbol, if the process | |
| 610 is a kind of "fire-and-forget" (no I/O, unwaitable) */ | |
| 611 p->status_symbol = Qrun; | |
| 612 p->exit_code = 0; | |
| 613 | |
| 853 | 614 pid = PROCMETH (create_process, (p, argv, nargv, program, cur_dir, |
| 615 separate_err)); | |
| 428 | 616 |
| 617 p->pid = make_int (pid); | |
| 863 | 618 if (PROCESS_READABLE_P (p)) |
| 853 | 619 event_stream_select_process (p, 1, 1); |
| 428 | 620 } |
| 621 | |
| 622 /* This function is the unwind_protect form for Fstart_process_internal. If | |
| 444 | 623 PROCESS doesn't have its pid set, then we know someone has signalled |
| 428 | 624 an error and the process wasn't started successfully, so we should |
| 625 remove it from the process list. */ | |
| 444 | 626 static void remove_process (Lisp_Object process); |
| 428 | 627 static Lisp_Object |
| 444 | 628 start_process_unwind (Lisp_Object process) |
| 428 | 629 { |
| 444 | 630 /* Was PROCESS started successfully? */ |
| 631 if (EQ (XPROCESS (process)->pid, Qnil)) | |
| 632 remove_process (process); | |
| 428 | 633 return Qnil; |
| 634 } | |
| 635 | |
| 636 DEFUN ("start-process-internal", Fstart_process_internal, 3, MANY, 0, /* | |
| 853 | 637 Internal function to start a program in a subprocess. |
| 638 Lisp callers should use `start-process' instead. | |
| 639 | |
| 640 Returns the process object for it. | |
| 428 | 641 Args are NAME BUFFER PROGRAM &rest PROGRAM-ARGS |
| 642 NAME is name for process. It is modified if necessary to make it unique. | |
| 643 BUFFER is the buffer or (buffer-name) to associate with the process. | |
| 644 Process output goes at end of that buffer, unless you specify | |
| 645 an output stream or filter function to handle the output. | |
| 646 BUFFER may be also nil, meaning that this process is not associated | |
| 853 | 647 with any buffer. |
| 648 BUFFER can also have the form (REAL-BUFFER STDERR-BUFFER); in that case, | |
| 649 REAL-BUFFER says what to do with standard output, as above, | |
| 650 while STDERR-BUFFER says what to do with standard error in the child. | |
| 651 STDERR-BUFFER may be nil (discard standard error output, unless a stderr | |
| 652 filter is set). Note that if you do not use this form at process creation, | |
| 653 stdout and stderr will be mixed in the output buffer, and this cannot be | |
| 654 changed, even by setting a stderr filter. | |
| 428 | 655 Third arg is program file name. It is searched for as in the shell. |
| 656 Remaining arguments are strings to give program as arguments. | |
| 853 | 657 |
| 658 Read and write coding systems for the process are determined from | |
| 659 `coding-system-for-read' and `coding-system-for-write' (intended as | |
| 660 overriding coding systems to be *bound* by Lisp code, not set), or | |
| 661 from `default-process-coding-system' if either or both are nil. You can | |
| 662 change the coding systems later on using `set-process-coding-system', | |
| 663 `set-process-input-coding-system', or `set-process-output-coding-system'. | |
| 664 | |
| 665 See also `set-process-filter' and `set-process-stderr-filter'. | |
|
4693
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3025
diff
changeset
|
666 |
|
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3025
diff
changeset
|
667 arguments: (NAME BUFFER PROGRAM &rest PROGRAM-ARGS) |
| 428 | 668 */ |
| 669 (int nargs, Lisp_Object *args)) | |
| 670 { | |
| 671 /* This function can call lisp */ | |
| 853 | 672 Lisp_Object buffer, stderr_buffer, name, program, process, current_dir; |
| 673 int separate_stderr; | |
| 428 | 674 Lisp_Object tem; |
| 910 | 675 int i; |
| 428 | 676 int speccount = specpdl_depth (); |
| 677 struct gcpro gcpro1, gcpro2, gcpro3; | |
| 678 | |
| 679 name = args[0]; | |
| 680 buffer = args[1]; | |
| 681 program = args[2]; | |
| 682 current_dir = Qnil; | |
| 683 | |
| 684 /* Protect against various file handlers doing GCs below. */ | |
| 685 GCPRO3 (buffer, program, current_dir); | |
| 686 | |
| 853 | 687 if (CONSP (buffer)) |
| 688 { | |
| 689 if (!CONSP (XCDR (buffer))) | |
| 690 invalid_argument ("Invalid BUFFER argument to `start-process'", | |
| 691 buffer); | |
| 692 if (!NILP (XCDR (XCDR (buffer)))) | |
| 693 invalid_argument ("Invalid BUFFER argument to `start-process'", | |
| 694 buffer); | |
| 695 stderr_buffer = XCAR (XCDR (buffer)); | |
| 696 buffer = XCAR (buffer); | |
| 697 separate_stderr = 1; | |
| 698 } | |
| 699 else | |
| 700 { | |
| 701 stderr_buffer = Qnil; | |
| 702 separate_stderr = 0; | |
| 703 } | |
| 704 | |
| 428 | 705 if (!NILP (buffer)) |
| 706 buffer = Fget_buffer_create (buffer); | |
| 853 | 707 if (!NILP (stderr_buffer)) |
| 708 stderr_buffer = Fget_buffer_create (stderr_buffer); | |
| 428 | 709 |
| 710 CHECK_STRING (name); | |
| 711 CHECK_STRING (program); | |
| 910 | 712 for (i = 3; i < nargs; ++i) |
| 713 CHECK_STRING (args[i]); | |
| 428 | 714 |
| 715 /* Make sure that the child will be able to chdir to the current | |
| 502 | 716 buffer's current directory, or its unhandled equivalent. [[ We |
| 428 | 717 can't just have the child check for an error when it does the |
| 502 | 718 chdir, since it's in a vfork. ]] -- not any more, we don't use |
| 719 vfork. -ben | |
| 428 | 720 |
| 502 | 721 Note: These calls are spread out to insure that the return values |
| 722 of the calls (which may be newly-created strings) are properly | |
| 723 GC-protected. */ | |
| 428 | 724 current_dir = current_buffer->directory; |
| 502 | 725 /* If the current dir has no terminating slash, we'll get undesirable |
| 726 results, so put the slash back. */ | |
| 727 current_dir = Ffile_name_as_directory (current_dir); | |
| 428 | 728 current_dir = Funhandled_file_name_directory (current_dir); |
| 729 current_dir = expand_and_dir_to_file (current_dir, Qnil); | |
| 730 | |
| 731 #if 0 /* This loser breaks ange-ftp */ | |
| 732 /* dmoore - if you re-enable this code, you have to gcprotect | |
| 733 current_buffer through the above calls. */ | |
| 734 if (NILP (Ffile_accessible_directory_p (current_dir))) | |
| 563 | 735 signal_error (Qprocess_error, "Setting current directory", |
| 736 current_buffer->directory); | |
| 428 | 737 #endif /* 0 */ |
| 738 | |
| 739 /* If program file name is not absolute, search our path for it */ | |
| 826 | 740 if (!IS_DIRECTORY_SEP (string_byte (program, 0)) |
| 428 | 741 && !(XSTRING_LENGTH (program) > 1 |
| 826 | 742 && IS_DEVICE_SEP (string_byte (program, 1)))) |
| 428 | 743 { |
| 744 struct gcpro ngcpro1; | |
| 745 | |
| 746 tem = Qnil; | |
| 747 NGCPRO1 (tem); | |
| 748 locate_file (Vexec_path, program, Vlisp_EXEC_SUFFIXES, &tem, X_OK); | |
| 749 if (NILP (tem)) | |
| 563 | 750 signal_error (Qprocess_error, "Searching for program", program); |
| 428 | 751 program = Fexpand_file_name (tem, Qnil); |
| 752 NUNGCPRO; | |
| 753 } | |
| 754 else | |
| 755 { | |
| 442 | 756 /* we still need to canonicalize it and ensure it has the proper |
| 757 ending, e.g. .exe */ | |
| 758 struct gcpro ngcpro1; | |
| 759 | |
| 760 tem = Qnil; | |
| 761 NGCPRO1 (tem); | |
| 762 locate_file (list1 (build_string ("")), program, Vlisp_EXEC_SUFFIXES, | |
| 763 &tem, X_OK); | |
| 764 if (NILP (tem)) | |
| 563 | 765 signal_error (Qprocess_error, "Searching for program", program); |
| 442 | 766 program = tem; |
| 767 NUNGCPRO; | |
| 428 | 768 } |
| 769 | |
| 442 | 770 if (!NILP (Ffile_directory_p (program))) |
| 771 invalid_operation ("Specified program for new process is a directory", | |
| 772 program); | |
| 773 | |
| 444 | 774 process = make_process_internal (name); |
| 428 | 775 |
| 444 | 776 XPROCESS (process)->buffer = buffer; |
| 853 | 777 XPROCESS (process)->stderr_buffer = stderr_buffer; |
| 778 XPROCESS (process)->separate_stderr = separate_stderr; | |
| 814 | 779 XPROCESS (process)->command = Flist (nargs - 2, args + 2); |
| 428 | 780 |
| 781 /* Make the process marker point into the process buffer (if any). */ | |
| 782 if (!NILP (buffer)) | |
| 444 | 783 Fset_marker (XPROCESS (process)->mark, |
| 428 | 784 make_int (BUF_ZV (XBUFFER (buffer))), buffer); |
| 853 | 785 if (!NILP (stderr_buffer)) |
| 786 Fset_marker (XPROCESS (process)->stderr_mark, | |
| 787 make_int (BUF_ZV (XBUFFER (stderr_buffer))), stderr_buffer); | |
| 428 | 788 |
| 789 /* If an error occurs and we can't start the process, we want to | |
| 790 remove it from the process list. This means that each error | |
| 791 check in create_process doesn't need to call remove_process | |
| 792 itself; it's all taken care of here. */ | |
| 444 | 793 record_unwind_protect (start_process_unwind, process); |
| 428 | 794 |
| 853 | 795 create_process (process, args + 3, nargs - 3, program, current_dir, |
| 796 separate_stderr); | |
| 428 | 797 |
| 798 UNGCPRO; | |
| 771 | 799 return unbind_to_1 (speccount, process); |
| 428 | 800 } |
| 801 | |
| 802 | |
| 803 #ifdef HAVE_SOCKETS | |
| 804 | |
| 805 | |
| 806 /* #### The network support is fairly synthetical. What we actually | |
| 807 need is a single function, which supports all datagram, stream and | |
| 808 packet stream connections, arbitrary protocol families should they | |
| 809 be supported by the target system, multicast groups, in both data | |
| 810 and control rooted/nonrooted flavors, service quality etc whatever | |
| 811 is supported by the underlying network. | |
| 812 | |
| 813 It must accept a property list describing the connection. The current | |
| 814 functions must then go to lisp and provide a suitable list for the | |
| 815 generalized connection function. | |
| 816 | |
| 817 Both UNIX and Win32 support BSD sockets, and there are many extensions | |
| 818 available (Sockets 2 spec). | |
| 819 | |
| 820 A todo is define a consistent set of properties abstracting a | |
| 821 network connection. -kkm | |
| 822 */ | |
| 823 | |
| 824 | |
| 825 /* open a TCP network connection to a given HOST/SERVICE. Treated | |
| 826 exactly like a normal process when reading and writing. Only | |
| 827 differences are in status display and process deletion. A network | |
| 828 connection has no PID; you cannot signal it. All you can do is | |
| 829 deactivate and close it via delete-process */ | |
| 830 | |
| 442 | 831 DEFUN ("open-network-stream-internal", Fopen_network_stream_internal, 4, 5, |
| 832 0, /* | |
| 428 | 833 Open a TCP connection for a service to a host. |
| 444 | 834 Return a process object to represent the connection. |
| 428 | 835 Input and output work as for subprocesses; `delete-process' closes it. |
| 836 | |
| 837 NAME is name for process. It is modified if necessary to make it unique. | |
| 838 BUFFER is the buffer (or buffer-name) to associate with the process. | |
| 839 Process output goes at end of that buffer, unless you specify | |
| 840 an output stream or filter function to handle the output. | |
| 841 BUFFER may also be nil, meaning that this process is not associated | |
| 842 with any buffer. | |
| 444 | 843 Third arg HOST (a string) is the name of the host to connect to, |
| 844 or its IP address. | |
| 845 Fourth arg SERVICE is the name of the service desired (a string), | |
| 846 or an integer specifying a port number to connect to. | |
| 3025 | 847 Optional fifth arg PROTOCOL is a network protocol. Currently only `tcp' |
| 848 (Transmission Control Protocol) and `udp' (User Datagram Protocol) are | |
| 849 supported. When omitted, `tcp' is assumed. | |
| 428 | 850 |
| 442 | 851 Output via `process-send-string' and input via buffer or filter (see |
| 428 | 852 `set-process-filter') are stream-oriented. That means UDP datagrams are |
| 853 not guaranteed to be sent and received in discrete packets. (But small | |
| 854 datagrams around 500 bytes that are not truncated by `process-send-string' | |
| 444 | 855 are usually fine.) Note further that the UDP protocol does not guard |
| 856 against lost packets. | |
| 428 | 857 */ |
| 858 (name, buffer, host, service, protocol)) | |
| 859 { | |
| 860 /* This function can GC */ | |
| 444 | 861 Lisp_Object process = Qnil; |
| 428 | 862 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, ngcpro1; |
| 863 void *inch, *outch; | |
| 864 | |
| 865 GCPRO5 (name, buffer, host, service, protocol); | |
| 866 CHECK_STRING (name); | |
| 867 | |
| 771 | 868 if (NILP (protocol)) |
| 428 | 869 protocol = Qtcp; |
| 870 else | |
| 871 CHECK_SYMBOL (protocol); | |
| 872 | |
| 873 /* Since this code is inside HAVE_SOCKETS, existence of | |
| 874 open_network_stream is mandatory */ | |
| 875 PROCMETH (open_network_stream, (name, host, service, protocol, | |
| 876 &inch, &outch)); | |
| 877 | |
| 878 if (!NILP (buffer)) | |
| 879 buffer = Fget_buffer_create (buffer); | |
| 444 | 880 process = make_process_internal (name); |
| 881 NGCPRO1 (process); | |
| 428 | 882 |
| 444 | 883 XPROCESS (process)->pid = Fcons (service, host); |
| 884 XPROCESS (process)->buffer = buffer; | |
| 771 | 885 init_process_io_handles (XPROCESS (process), (void *) inch, (void *) outch, |
| 853 | 886 (void *) -1, |
| 428 | 887 STREAM_NETWORK_CONNECTION); |
| 888 | |
| 853 | 889 event_stream_select_process (XPROCESS (process), 1, 1); |
| 428 | 890 |
| 1204 | 891 NUNGCPRO; |
| 428 | 892 UNGCPRO; |
| 444 | 893 return process; |
| 428 | 894 } |
| 895 | |
| 896 #ifdef HAVE_MULTICAST | |
| 897 | |
| 898 DEFUN ("open-multicast-group-internal", Fopen_multicast_group_internal, 5, 5, 0, /* | |
| 899 Open a multicast connection on the specified dest/port/ttl. | |
| 444 | 900 Return a process object to represent the connection. |
| 428 | 901 Input and output work as for subprocesses; `delete-process' closes it. |
| 902 | |
| 903 NAME is name for process. It is modified if necessary to make it unique. | |
| 904 BUFFER is the buffer (or buffer-name) to associate with the process. | |
| 905 Process output goes at end of that buffer, unless you specify | |
| 906 an output stream or filter function to handle the output. | |
| 907 BUFFER may also be nil, meaning that this process is not associated | |
| 908 with any buffer. | |
| 909 Third, fourth and fifth args are the multicast destination group, port and ttl. | |
| 910 dest must be an internet address between 224.0.0.0 and 239.255.255.255 | |
| 911 port is a communication port like in traditional unicast | |
| 912 ttl is the time-to-live (15 for site, 63 for region and 127 for world) | |
| 913 */ | |
| 914 (name, buffer, dest, port, ttl)) | |
| 915 { | |
| 916 /* This function can GC */ | |
| 444 | 917 Lisp_Object process = Qnil; |
| 428 | 918 struct gcpro gcpro1; |
| 919 void *inch, *outch; | |
| 920 | |
| 921 CHECK_STRING (name); | |
| 922 | |
| 923 /* Since this code is inside HAVE_MULTICAST, existence of | |
| 771 | 924 open_multicast_group is mandatory */ |
| 428 | 925 PROCMETH (open_multicast_group, (name, dest, port, ttl, |
| 926 &inch, &outch)); | |
| 927 | |
| 928 if (!NILP (buffer)) | |
| 929 buffer = Fget_buffer_create (buffer); | |
| 930 | |
| 444 | 931 process = make_process_internal (name); |
| 932 GCPRO1 (process); | |
| 428 | 933 |
| 444 | 934 XPROCESS (process)->pid = Fcons (port, dest); |
| 935 XPROCESS (process)->buffer = buffer; | |
| 853 | 936 init_process_io_handles (XPROCESS (process), (void *) inch, (void *) outch, |
| 937 (void *) -1, | |
| 428 | 938 STREAM_NETWORK_CONNECTION); |
| 939 | |
| 853 | 940 event_stream_select_process (XPROCESS (process), 1, 1); |
| 428 | 941 |
| 942 UNGCPRO; | |
| 444 | 943 return process; |
| 428 | 944 } |
| 945 #endif /* HAVE_MULTICAST */ | |
| 946 | |
| 947 #endif /* HAVE_SOCKETS */ | |
| 948 | |
| 949 Lisp_Object | |
| 950 canonicalize_host_name (Lisp_Object host) | |
| 951 { | |
| 952 return PROCMETH_OR_GIVEN (canonicalize_host_name, (host), host); | |
| 953 } | |
| 954 | |
| 955 | |
| 956 DEFUN ("set-process-window-size", Fset_process_window_size, 3, 3, 0, /* | |
| 957 Tell PROCESS that it has logical window size HEIGHT and WIDTH. | |
| 958 */ | |
| 444 | 959 (process, height, width)) |
| 428 | 960 { |
| 444 | 961 CHECK_PROCESS (process); |
| 428 | 962 CHECK_NATNUM (height); |
| 963 CHECK_NATNUM (width); | |
| 964 return | |
| 444 | 965 MAYBE_INT_PROCMETH (set_window_size, |
| 966 (XPROCESS (process), XINT (height), XINT (width))) <= 0 | |
| 428 | 967 ? Qnil : Qt; |
| 968 } | |
| 969 | |
| 970 | |
| 971 /************************************************************************/ | |
| 972 /* Process I/O */ | |
| 973 /************************************************************************/ | |
| 974 | |
| 844 | 975 /* Set up PROCESS's buffer for insertion of process data at PROCESS's |
| 976 mark. | |
| 977 | |
| 978 Sets the current buffer to PROCESS's buffer, inhibits read only, | |
| 979 remembers current point, sets point to PROCESS'S mark, widens if | |
| 980 necessary. | |
| 981 */ | |
| 982 static int | |
| 853 | 983 process_setup_for_insertion (Lisp_Object process, int read_stderr) |
| 844 | 984 { |
| 985 Lisp_Process *p = XPROCESS (process); | |
| 986 int spec = specpdl_depth (); | |
| 853 | 987 Lisp_Object buffer = read_stderr ? p->stderr_buffer : p->buffer; |
| 988 Lisp_Object mark = read_stderr ? p->stderr_mark : p->mark; | |
| 989 struct buffer *buf = XBUFFER (buffer); | |
| 844 | 990 Charbpos output_pt; |
| 991 | |
| 992 if (buf != current_buffer) | |
| 993 { | |
| 994 record_unwind_protect (save_current_buffer_restore, | |
| 995 Fcurrent_buffer ()); | |
| 996 set_buffer_internal (buf); | |
| 997 } | |
| 998 | |
| 999 record_unwind_protect (save_excursion_restore, save_excursion_save ()); | |
| 1000 specbind (Qinhibit_read_only, Qt); | |
| 854 | 1001 |
| 844 | 1002 /* Insert new output into buffer |
| 1003 at the current end-of-output marker, | |
| 1004 thus preserving logical ordering of input and output. */ | |
| 853 | 1005 if (XMARKER (mark)->buffer) |
| 1006 output_pt = marker_position (mark); | |
| 844 | 1007 else |
| 1008 output_pt = BUF_ZV (buf); | |
| 1009 | |
| 1010 /* If the output marker is outside of the visible region, save | |
| 1011 the restriction and widen. */ | |
| 1012 if (! (BUF_BEGV (buf) <= output_pt && output_pt <= BUF_ZV (buf))) | |
| 1013 { | |
| 1014 record_unwind_protect (save_restriction_restore, | |
| 1015 save_restriction_save (buf)); | |
| 1016 Fwiden (wrap_buffer (buf)); | |
| 1017 } | |
| 1018 | |
| 1019 BUF_SET_PT (buf, output_pt); | |
| 1020 return spec; | |
| 1021 } | |
| 1022 | |
| 428 | 1023 /* Read pending output from the process channel, |
| 1024 starting with our buffered-ahead character if we have one. | |
| 1025 Yield number of characters read. | |
| 1026 | |
| 1027 This function reads at most 1024 bytes. | |
| 1028 If you want to read all available subprocess output, | |
| 1029 you must call it repeatedly until it returns zero. */ | |
| 1030 | |
| 1031 Charcount | |
| 853 | 1032 read_process_output (Lisp_Object process, int read_stderr) |
| 428 | 1033 { |
| 1034 /* This function can GC */ | |
| 1035 Bytecount nbytes, nchars; | |
| 867 | 1036 Ibyte chars[1025]; |
| 428 | 1037 Lisp_Object outstream; |
| 444 | 1038 Lisp_Process *p = XPROCESS (process); |
| 853 | 1039 Lisp_Object filter = read_stderr ? p->stderr_filter : p->filter; |
| 1040 Lisp_Object buffer = read_stderr ? p->stderr_buffer : p->buffer; | |
| 1041 Lisp_Object mark = read_stderr ? p->stderr_mark : p->mark; | |
| 428 | 1042 |
| 1043 /* If there is a lot of output from the subprocess, the loop in | |
| 1044 execute_internal_event() might call read_process_output() more | |
| 1045 than once. If the filter that was executed from one of these | |
| 1046 calls set the filter to t, we have to stop now. Return -1 rather | |
| 1047 than 0 so execute_internal_event() doesn't close the process. | |
| 1048 Really, the loop in execute_internal_event() should check itself | |
| 1049 for a process-filter change, like in status_notify(); but the | |
| 1050 struct Lisp_Process is not exported outside of this file. */ | |
| 863 | 1051 if (!PROCESS_READABLE_P (p)) |
| 853 | 1052 { |
| 1053 errno = 0; | |
| 1054 return -1; /* already closed */ | |
| 1055 } | |
| 428 | 1056 |
| 853 | 1057 if (!NILP (filter) && (p->filter_does_read)) |
| 428 | 1058 { |
| 1059 Lisp_Object filter_result; | |
| 1060 | |
| 1061 /* Some weird FSFmacs crap here with | |
| 853 | 1062 Vdeactivate_mark and current_buffer->keymap. |
| 1063 Some FSF junk with running_asynch_code, to preserve the match | |
| 1064 data. Not necessary because we don't call process filters | |
| 1065 asynchronously (i.e. from within QUIT). */ | |
| 1066 /* Don't catch errors here; we're not in any critical code. */ | |
| 1067 filter_result = call2 (filter, process, Qnil); | |
| 428 | 1068 CHECK_INT (filter_result); |
| 1069 return XINT (filter_result); | |
| 1070 } | |
| 1071 | |
| 853 | 1072 nbytes = Lstream_read (read_stderr ? XLSTREAM (DATA_ERRSTREAM (p)) : |
| 1073 XLSTREAM (DATA_INSTREAM (p)), chars, | |
| 771 | 1074 sizeof (chars) - 1); |
| 428 | 1075 if (nbytes <= 0) return nbytes; |
| 1076 | |
| 771 | 1077 if (debug_process_io) |
| 1078 { | |
| 1079 chars[nbytes] = '\0'; | |
| 1080 stderr_out ("Read: %s\n", chars); | |
| 1081 } | |
| 1082 | |
| 1083 /* !!#### if the coding system changed as a result of reading, we | |
| 1084 need to change the output coding system accordingly. */ | |
| 428 | 1085 nchars = bytecount_to_charcount (chars, nbytes); |
| 853 | 1086 outstream = filter; |
| 428 | 1087 if (!NILP (outstream)) |
| 1088 { | |
| 853 | 1089 /* Some FSF junk with running_asynch_code, to preserve the match |
| 1090 data. Not necessary because we don't call process filters | |
| 1091 asynchronously (i.e. from within QUIT). */ | |
| 1092 /* Don't catch errors here; we're not in any critical code. */ | |
| 1093 call2 (outstream, process, make_string (chars, nbytes)); | |
| 428 | 1094 return nchars; |
| 1095 } | |
| 1096 | |
| 1097 /* If no filter, write into buffer if it isn't dead. */ | |
| 853 | 1098 if (!NILP (buffer) && BUFFER_LIVE_P (XBUFFER (buffer))) |
| 428 | 1099 { |
| 844 | 1100 struct gcpro gcpro1; |
| 853 | 1101 struct buffer *buf = XBUFFER (buffer); |
| 1102 int spec = process_setup_for_insertion (process, read_stderr); | |
| 428 | 1103 |
| 844 | 1104 GCPRO1 (process); |
| 428 | 1105 |
| 1106 #if 0 | |
| 1107 /* This screws up initial display of the window. jla */ | |
| 1108 | |
| 1109 /* Insert before markers in case we are inserting where | |
| 1110 the buffer's mark is, and the user's next command is Meta-y. */ | |
| 1111 buffer_insert_raw_string_1 (buf, -1, chars, | |
| 1112 nbytes, INSDEL_BEFORE_MARKERS); | |
| 1113 #else | |
| 1114 buffer_insert_raw_string (buf, chars, nbytes); | |
| 1115 #endif | |
| 1116 | |
| 853 | 1117 Fset_marker (mark, make_int (BUF_PT (buf)), buffer); |
| 1118 | |
| 428 | 1119 MARK_MODELINE_CHANGED; |
| 844 | 1120 unbind_to (spec); |
| 428 | 1121 UNGCPRO; |
| 1122 } | |
| 1123 return nchars; | |
| 1124 } | |
| 853 | 1125 |
| 1126 int | |
| 1127 process_has_separate_stderr (Lisp_Object process) | |
| 1128 { | |
| 1129 return XPROCESS (process)->separate_stderr; | |
| 1130 } | |
| 1131 | |
| 859 | 1132 DEFUN ("process-has-separate-stderr-p", Fprocess_has_separate_stderr_p, 1, 1, |
| 1133 0, /* | |
| 1134 Return non-nil if process has stderr separate from stdout. | |
| 1135 */ | |
| 1136 (process)) | |
| 1137 { | |
| 1138 CHECK_PROCESS (process); | |
| 1139 return process_has_separate_stderr (process) ? Qt : Qnil; | |
| 1140 } | |
| 1141 | |
| 428 | 1142 |
| 1143 /* Sending data to subprocess */ | |
| 1144 | |
| 444 | 1145 /* send some data to process PROCESS. If NONRELOCATABLE is non-NULL, it |
| 428 | 1146 specifies the address of the data. Otherwise, the data comes from the |
| 1147 object RELOCATABLE (either a string or a buffer). START and LEN | |
| 1148 specify the offset and length of the data to send. | |
| 1149 | |
| 665 | 1150 Note that START and LEN are in Charbpos's if RELOCATABLE is a buffer, |
| 428 | 1151 and in Bytecounts otherwise. */ |
| 1152 | |
| 1153 void | |
| 444 | 1154 send_process (Lisp_Object process, |
| 867 | 1155 Lisp_Object relocatable, const Ibyte *nonrelocatable, |
| 428 | 1156 int start, int len) |
| 1157 { | |
| 1158 /* This function can GC */ | |
| 1159 struct gcpro gcpro1, gcpro2; | |
| 1160 Lisp_Object lstream = Qnil; | |
| 1161 | |
| 444 | 1162 GCPRO2 (process, lstream); |
| 428 | 1163 |
| 444 | 1164 if (NILP (DATA_OUTSTREAM (XPROCESS (process)))) |
| 563 | 1165 invalid_operation ("Process not open for writing", process); |
| 428 | 1166 |
| 1167 if (nonrelocatable) | |
| 1168 lstream = | |
| 1169 make_fixed_buffer_input_stream (nonrelocatable + start, len); | |
| 1170 else if (BUFFERP (relocatable)) | |
| 1171 lstream = make_lisp_buffer_input_stream (XBUFFER (relocatable), | |
| 1172 start, start + len, 0); | |
| 1173 else | |
| 1174 lstream = make_lisp_string_input_stream (relocatable, start, len); | |
| 1175 | |
| 771 | 1176 if (debug_process_io) |
| 1177 { | |
| 1178 if (nonrelocatable) | |
| 1179 stderr_out ("Writing: %s\n", nonrelocatable); | |
| 1180 else | |
| 1181 { | |
| 1182 stderr_out ("Writing: "); | |
| 1183 print_internal (relocatable, Qexternal_debugging_output, 0); | |
| 1184 } | |
| 1185 } | |
| 1186 | |
| 444 | 1187 PROCMETH (send_process, (process, XLSTREAM (lstream))); |
| 428 | 1188 |
| 1189 UNGCPRO; | |
| 1190 Lstream_delete (XLSTREAM (lstream)); | |
| 1191 } | |
| 1192 | |
| 1193 DEFUN ("process-tty-name", Fprocess_tty_name, 1, 1, 0, /* | |
| 1194 Return the name of the terminal PROCESS uses, or nil if none. | |
| 1195 This is the terminal that the process itself reads and writes on, | |
| 1196 not the name of the pty that Emacs uses to talk with that terminal. | |
| 1197 */ | |
| 444 | 1198 (process)) |
| 428 | 1199 { |
| 444 | 1200 CHECK_PROCESS (process); |
| 1204 | 1201 return XPROCESS (process)->tty_name; |
| 428 | 1202 } |
| 1203 | |
| 1204 DEFUN ("set-process-buffer", Fset_process_buffer, 2, 2, 0, /* | |
| 1205 Set buffer associated with PROCESS to BUFFER (a buffer, or nil). | |
| 2297 | 1206 Output from PROCESS is inserted in this buffer unless PROCESS has a filter. |
| 428 | 1207 */ |
| 444 | 1208 (process, buffer)) |
| 428 | 1209 { |
| 444 | 1210 CHECK_PROCESS (process); |
| 428 | 1211 if (!NILP (buffer)) |
| 1212 CHECK_BUFFER (buffer); | |
| 444 | 1213 XPROCESS (process)->buffer = buffer; |
| 428 | 1214 return buffer; |
| 1215 } | |
| 1216 | |
| 1217 DEFUN ("process-buffer", Fprocess_buffer, 1, 1, 0, /* | |
| 1218 Return the buffer PROCESS is associated with. | |
| 2297 | 1219 Output from PROCESS is inserted in this buffer unless PROCESS has a filter. |
| 1220 Set the buffer with `set-process-buffer'. | |
| 428 | 1221 */ |
| 444 | 1222 (process)) |
| 428 | 1223 { |
| 444 | 1224 CHECK_PROCESS (process); |
| 1225 return XPROCESS (process)->buffer; | |
| 428 | 1226 } |
| 1227 | |
| 853 | 1228 DEFUN ("set-process-stderr-buffer", Fset_process_stderr_buffer, 2, 2, 0, /* |
| 2297 | 1229 Output from the stderr of PROCESS is inserted in this buffer unless |
| 1230 PROCESS has a stderr filter. | |
| 853 | 1231 Set stderr buffer associated with PROCESS to BUFFER (a buffer, or nil). |
| 1232 */ | |
| 1233 (process, buffer)) | |
| 1234 { | |
| 1235 CHECK_PROCESS (process); | |
| 1236 if (!XPROCESS (process)->separate_stderr) | |
| 1237 invalid_change ("stdout and stderr not separate", process); | |
| 1238 if (!NILP (buffer)) | |
| 1239 CHECK_BUFFER (buffer); | |
| 1240 XPROCESS (process)->stderr_buffer = buffer; | |
| 1241 return buffer; | |
| 1242 } | |
| 1243 | |
| 1244 DEFUN ("process-stderr-buffer", Fprocess_stderr_buffer, 1, 1, 0, /* | |
| 1245 Return the stderr buffer PROCESS is associated with. | |
| 2297 | 1246 Output from the stderr of PROCESS is inserted in this buffer unless PROCESS |
| 1247 has a stderr filter. Set the buffer with `set-process-stderr-buffer'. | |
| 853 | 1248 */ |
| 1249 (process)) | |
| 1250 { | |
| 1251 CHECK_PROCESS (process); | |
| 1252 if (!XPROCESS (process)->separate_stderr) | |
| 1253 invalid_change ("stdout and stderr not separate", process); | |
| 1254 return XPROCESS (process)->stderr_buffer; | |
| 1255 } | |
| 1256 | |
| 428 | 1257 DEFUN ("process-mark", Fprocess_mark, 1, 1, 0, /* |
| 1258 Return the marker for the end of the last output from PROCESS. | |
| 1259 */ | |
| 444 | 1260 (process)) |
| 428 | 1261 { |
| 444 | 1262 CHECK_PROCESS (process); |
| 1263 return XPROCESS (process)->mark; | |
| 428 | 1264 } |
| 1265 | |
| 853 | 1266 DEFUN ("process-stderr-mark", Fprocess_stderr_mark, 1, 1, 0, /* |
| 1267 Return the marker for the end of the last stderr output from PROCESS. | |
| 1268 */ | |
| 1269 (process)) | |
| 1270 { | |
| 1271 CHECK_PROCESS (process); | |
| 1272 if (!XPROCESS (process)->separate_stderr) | |
| 1273 invalid_operation ("stdout and stderr not separate", process); | |
| 1274 return XPROCESS (process)->stderr_mark; | |
| 1275 } | |
| 1276 | |
| 428 | 1277 void |
| 853 | 1278 set_process_filter (Lisp_Object process, Lisp_Object filter, |
| 1279 int filter_does_read, int set_stderr) | |
| 428 | 1280 { |
| 444 | 1281 CHECK_PROCESS (process); |
| 853 | 1282 if (set_stderr && !XPROCESS (process)->separate_stderr) |
| 1283 invalid_change ("stdout and stderr not separate", process); | |
| 863 | 1284 if (PROCESS_READABLE_P (XPROCESS (process))) |
| 853 | 1285 { |
| 1286 if (EQ (filter, Qt)) | |
| 1287 event_stream_unselect_process (XPROCESS (process), !set_stderr, | |
| 1288 set_stderr); | |
| 1289 else | |
| 1290 event_stream_select_process (XPROCESS (process), !set_stderr, | |
| 1291 set_stderr); | |
| 1292 } | |
| 428 | 1293 |
| 853 | 1294 if (set_stderr) |
| 1295 XPROCESS (process)->stderr_filter = filter; | |
| 1296 else | |
| 1297 XPROCESS (process)->filter = filter; | |
| 444 | 1298 XPROCESS (process)->filter_does_read = filter_does_read; |
| 428 | 1299 } |
| 1300 | |
| 1301 DEFUN ("set-process-filter", Fset_process_filter, 2, 2, 0, /* | |
| 1302 Give PROCESS the filter function FILTER; nil means no filter. | |
| 853 | 1303 t means stop accepting output from the process. (If process was created |
| 854 | 1304 with |
| 853 | 1305 When a process has a filter, each time it does output |
| 1306 the entire string of output is passed to the filter. | |
| 1307 The filter gets two arguments: the process and the string of output. | |
| 1308 If the process has a filter, its buffer is not used for output. | |
| 1309 */ | |
| 1310 (process, filter)) | |
| 1311 { | |
| 1312 set_process_filter (process, filter, 0, 0); | |
| 1313 return filter; | |
| 1314 } | |
| 1315 | |
| 1316 DEFUN ("set-process-stderr-filter", Fset_process_stderr_filter, 2, 2, 0, /* | |
| 1317 Give PROCESS the stderr filter function FILTER; nil means no filter. | |
| 428 | 1318 t means stop accepting output from the process. |
| 1319 When a process has a filter, each time it does output | |
| 1320 the entire string of output is passed to the filter. | |
| 1321 The filter gets two arguments: the process and the string of output. | |
| 1322 If the process has a filter, its buffer is not used for output. | |
| 1323 */ | |
| 444 | 1324 (process, filter)) |
| 428 | 1325 { |
| 853 | 1326 set_process_filter (process, filter, 0, 1); |
| 428 | 1327 return filter; |
| 1328 } | |
| 1329 | |
| 1330 DEFUN ("process-filter", Fprocess_filter, 1, 1, 0, /* | |
| 1331 Return the filter function of PROCESS; nil if none. | |
| 1332 See `set-process-filter' for more info on filter functions. | |
| 1333 */ | |
| 444 | 1334 (process)) |
| 428 | 1335 { |
| 444 | 1336 CHECK_PROCESS (process); |
| 1337 return XPROCESS (process)->filter; | |
| 428 | 1338 } |
| 1339 | |
| 853 | 1340 DEFUN ("process-stderr-filter", Fprocess_stderr_filter, 1, 1, 0, /* |
| 1341 Return the filter function of PROCESS; nil if none. | |
| 1342 See `set-process-stderr-filter' for more info on filter functions. | |
| 1343 */ | |
| 1344 (process)) | |
| 1345 { | |
| 1346 CHECK_PROCESS (process); | |
| 1347 if (!XPROCESS (process)->separate_stderr) | |
| 1348 invalid_operation ("stdout and stderr not separate", process); | |
| 1349 return XPROCESS (process)->stderr_filter; | |
| 1350 } | |
| 1351 | |
| 442 | 1352 DEFUN ("process-send-region", Fprocess_send_region, 3, 4, 0, /* |
| 1353 Send current contents of the region between START and END as input to PROCESS. | |
| 444 | 1354 PROCESS may be a process or the name of a process, or a buffer or the |
| 1355 name of a buffer, in which case the buffer's process is used. If it | |
| 1356 is nil, the current buffer's process is used. | |
| 442 | 1357 BUFFER specifies the buffer to look in; if nil, the current buffer is used. |
| 853 | 1358 If the region is more than 100 or so characters long, it may be sent in |
| 1359 several chunks. This may happen even for shorter regions. Output | |
| 444 | 1360 from processes can arrive in between chunks. |
| 428 | 1361 */ |
| 442 | 1362 (process, start, end, buffer)) |
| 428 | 1363 { |
| 1364 /* This function can GC */ | |
| 665 | 1365 Charbpos bstart, bend; |
| 442 | 1366 struct buffer *buf = decode_buffer (buffer, 0); |
| 428 | 1367 |
| 793 | 1368 buffer = wrap_buffer (buf); |
| 444 | 1369 process = get_process (process); |
| 1370 get_buffer_range_char (buf, start, end, &bstart, &bend, 0); | |
| 442 | 1371 |
| 444 | 1372 send_process (process, buffer, 0, bstart, bend - bstart); |
| 428 | 1373 return Qnil; |
| 1374 } | |
| 1375 | |
| 1376 DEFUN ("process-send-string", Fprocess_send_string, 2, 4, 0, /* | |
| 1377 Send PROCESS the contents of STRING as input. | |
| 444 | 1378 PROCESS may be a process or the name of a process, or a buffer or the |
| 1379 name of a buffer, in which case the buffer's process is used. If it | |
| 1380 is nil, the current buffer's process is used. | |
| 1381 Optional arguments START and END specify part of STRING; see `substring'. | |
| 1382 If STRING is more than 100 or so characters long, it may be sent in | |
| 1383 several chunks. This may happen even for shorter strings. Output | |
| 1384 from processes can arrive in between chunks. | |
| 428 | 1385 */ |
| 444 | 1386 (process, string, start, end)) |
| 428 | 1387 { |
| 1388 /* This function can GC */ | |
| 444 | 1389 Bytecount bstart, bend; |
| 428 | 1390 |
| 444 | 1391 process = get_process (process); |
| 428 | 1392 CHECK_STRING (string); |
| 444 | 1393 get_string_range_byte (string, start, end, &bstart, &bend, |
| 428 | 1394 GB_HISTORICAL_STRING_BEHAVIOR); |
| 1395 | |
| 444 | 1396 send_process (process, string, 0, bstart, bend - bstart); |
| 428 | 1397 return Qnil; |
| 1398 } | |
| 1399 | |
| 1400 | |
| 1401 DEFUN ("process-input-coding-system", Fprocess_input_coding_system, 1, 1, 0, /* | |
| 1402 Return PROCESS's input coding system. | |
| 1403 */ | |
| 1404 (process)) | |
| 1405 { | |
| 1406 process = get_process (process); | |
| 863 | 1407 CHECK_READABLE_PROCESS (process); |
| 771 | 1408 return (coding_stream_detected_coding_system |
| 1409 (XLSTREAM (XPROCESS (process)->coding_instream))); | |
| 428 | 1410 } |
| 1411 | |
| 1412 DEFUN ("process-output-coding-system", Fprocess_output_coding_system, 1, 1, 0, /* | |
| 1413 Return PROCESS's output coding system. | |
| 1414 */ | |
| 1415 (process)) | |
| 1416 { | |
| 1417 process = get_process (process); | |
| 440 | 1418 CHECK_LIVE_PROCESS (process); |
| 771 | 1419 return (coding_stream_coding_system |
| 1420 (XLSTREAM (XPROCESS (process)->coding_outstream))); | |
| 428 | 1421 } |
| 1422 | |
| 1423 DEFUN ("process-coding-system", Fprocess_coding_system, 1, 1, 0, /* | |
| 1424 Return a pair of coding-system for decoding and encoding of PROCESS. | |
| 1425 */ | |
| 1426 (process)) | |
| 1427 { | |
| 1428 process = get_process (process); | |
| 863 | 1429 CHECK_READABLE_PROCESS (process); |
| 771 | 1430 return Fcons (coding_stream_detected_coding_system |
| 428 | 1431 (XLSTREAM (XPROCESS (process)->coding_instream)), |
| 771 | 1432 coding_stream_coding_system |
| 428 | 1433 (XLSTREAM (XPROCESS (process)->coding_outstream))); |
| 1434 } | |
| 1435 | |
| 1436 DEFUN ("set-process-input-coding-system", Fset_process_input_coding_system, | |
| 1437 2, 2, 0, /* | |
| 1438 Set PROCESS's input coding system to CODESYS. | |
| 771 | 1439 This is used for reading data from PROCESS. |
| 428 | 1440 */ |
| 1441 (process, codesys)) | |
| 1442 { | |
| 771 | 1443 codesys = get_coding_system_for_text_file (codesys, 1); |
| 428 | 1444 process = get_process (process); |
| 863 | 1445 CHECK_READABLE_PROCESS (process); |
| 440 | 1446 |
| 771 | 1447 set_coding_stream_coding_system |
| 428 | 1448 (XLSTREAM (XPROCESS (process)->coding_instream), codesys); |
| 1449 return Qnil; | |
| 1450 } | |
| 1451 | |
| 1452 DEFUN ("set-process-output-coding-system", Fset_process_output_coding_system, | |
| 1453 2, 2, 0, /* | |
| 1454 Set PROCESS's output coding system to CODESYS. | |
| 771 | 1455 This is used for writing data to PROCESS. |
| 428 | 1456 */ |
| 1457 (process, codesys)) | |
| 1458 { | |
| 771 | 1459 codesys = get_coding_system_for_text_file (codesys, 0); |
| 428 | 1460 process = get_process (process); |
| 440 | 1461 CHECK_LIVE_PROCESS (process); |
| 1462 | |
| 771 | 1463 set_coding_stream_coding_system |
| 428 | 1464 (XLSTREAM (XPROCESS (process)->coding_outstream), codesys); |
| 1465 return Qnil; | |
| 1466 } | |
| 1467 | |
| 1468 DEFUN ("set-process-coding-system", Fset_process_coding_system, | |
| 1469 1, 3, 0, /* | |
| 1470 Set coding-systems of PROCESS to DECODING and ENCODING. | |
| 440 | 1471 DECODING will be used to decode subprocess output and ENCODING to |
| 1472 encode subprocess input. | |
| 428 | 1473 */ |
| 1474 (process, decoding, encoding)) | |
| 1475 { | |
| 1476 if (!NILP (decoding)) | |
| 1477 Fset_process_input_coding_system (process, decoding); | |
| 1478 | |
| 1479 if (!NILP (encoding)) | |
| 1480 Fset_process_output_coding_system (process, encoding); | |
| 1481 | |
| 1482 return Qnil; | |
| 1483 } | |
| 1484 | |
| 1485 | |
| 1486 /************************************************************************/ | |
| 1487 /* process status */ | |
| 1488 /************************************************************************/ | |
| 1489 | |
| 1490 static Lisp_Object | |
| 1491 exec_sentinel_unwind (Lisp_Object datum) | |
| 1492 { | |
| 853 | 1493 XPROCESS (XCAR (datum))->sentinel = XCDR (datum); |
| 1494 free_cons (datum); | |
| 428 | 1495 return Qnil; |
| 1496 } | |
| 1497 | |
| 1498 static void | |
| 444 | 1499 exec_sentinel (Lisp_Object process, Lisp_Object reason) |
| 428 | 1500 { |
| 1501 /* This function can GC */ | |
| 1502 int speccount = specpdl_depth (); | |
| 444 | 1503 Lisp_Process *p = XPROCESS (process); |
| 428 | 1504 Lisp_Object sentinel = p->sentinel; |
| 1505 | |
| 1506 if (NILP (sentinel)) | |
| 1507 return; | |
| 1508 | |
| 1509 /* Some weird FSFmacs crap here with | |
| 1510 Vdeactivate_mark and current_buffer->keymap */ | |
| 1511 | |
| 853 | 1512 /* Some FSF junk with running_asynch_code, to preserve the match |
| 1513 data. Not necessary because we don't call process filters | |
| 1514 asynchronously (i.e. from within QUIT). */ | |
| 1515 | |
| 428 | 1516 /* Zilch the sentinel while it's running, to avoid recursive invocations; |
| 853 | 1517 assure that it gets restored no matter how the sentinel exits. |
| 1518 | |
| 1519 (#### Why is this necessary? Probably another relic of asynchronous | |
| 1520 calling of process filters/sentinels.) */ | |
| 428 | 1521 p->sentinel = Qnil; |
| 853 | 1522 record_unwind_protect (exec_sentinel_unwind, |
| 1523 noseeum_cons (process, sentinel)); | |
| 1524 /* Don't catch errors here; we're not in any critical code. */ | |
| 1525 call2 (sentinel, process, reason); | |
| 771 | 1526 unbind_to (speccount); |
| 428 | 1527 } |
| 1528 | |
| 1529 DEFUN ("set-process-sentinel", Fset_process_sentinel, 2, 2, 0, /* | |
| 1530 Give PROCESS the sentinel SENTINEL; nil for none. | |
| 1531 The sentinel is called as a function when the process changes state. | |
| 1532 It gets two arguments: the process, and a string describing the change. | |
| 1533 */ | |
| 444 | 1534 (process, sentinel)) |
| 428 | 1535 { |
| 444 | 1536 CHECK_PROCESS (process); |
| 1537 XPROCESS (process)->sentinel = sentinel; | |
| 428 | 1538 return sentinel; |
| 1539 } | |
| 1540 | |
| 1541 DEFUN ("process-sentinel", Fprocess_sentinel, 1, 1, 0, /* | |
| 1542 Return the sentinel of PROCESS; nil if none. | |
| 1543 See `set-process-sentinel' for more info on sentinels. | |
| 1544 */ | |
| 444 | 1545 (process)) |
| 428 | 1546 { |
| 444 | 1547 CHECK_PROCESS (process); |
| 1548 return XPROCESS (process)->sentinel; | |
| 428 | 1549 } |
| 1550 | |
| 1551 | |
| 442 | 1552 const char * |
| 428 | 1553 signal_name (int signum) |
| 1554 { | |
| 1555 if (signum >= 0 && signum < NSIG) | |
| 442 | 1556 return (const char *) sys_siglist[signum]; |
| 428 | 1557 |
| 442 | 1558 return (const char *) GETTEXT ("unknown signal"); |
| 428 | 1559 } |
| 1560 | |
| 1561 void | |
| 1562 update_process_status (Lisp_Object p, | |
| 1563 Lisp_Object status_symbol, | |
| 1564 int exit_code, | |
| 1565 int core_dumped) | |
| 1566 { | |
| 1567 XPROCESS (p)->tick++; | |
| 1568 process_tick++; | |
| 1569 XPROCESS (p)->status_symbol = status_symbol; | |
| 1570 XPROCESS (p)->exit_code = exit_code; | |
| 1571 XPROCESS (p)->core_dumped = core_dumped; | |
| 1572 } | |
| 1573 | |
| 1574 /* Return a string describing a process status list. */ | |
| 1575 | |
| 1576 static Lisp_Object | |
| 440 | 1577 status_message (Lisp_Process *p) |
| 428 | 1578 { |
| 1579 Lisp_Object symbol = p->status_symbol; | |
| 1580 int code = p->exit_code; | |
| 1581 int coredump = p->core_dumped; | |
| 1582 Lisp_Object string, string2; | |
| 1583 | |
| 1584 if (EQ (symbol, Qsignal) || EQ (symbol, Qstop)) | |
| 1585 { | |
| 1586 string = build_string (signal_name (code)); | |
| 1587 if (coredump) | |
| 771 | 1588 string2 = build_msg_string (" (core dumped)\n"); |
| 428 | 1589 else |
| 1590 string2 = build_string ("\n"); | |
| 793 | 1591 set_string_char (string, 0, |
| 867 | 1592 DOWNCASE (0, string_ichar (string, 0))); |
| 428 | 1593 return concat2 (string, string2); |
| 1594 } | |
| 1595 else if (EQ (symbol, Qexit)) | |
| 1596 { | |
| 1597 if (code == 0) | |
| 771 | 1598 return build_msg_string ("finished\n"); |
| 428 | 1599 string = Fnumber_to_string (make_int (code)); |
| 1600 if (coredump) | |
| 771 | 1601 string2 = build_msg_string (" (core dumped)\n"); |
| 428 | 1602 else |
| 1603 string2 = build_string ("\n"); | |
| 771 | 1604 return concat2 (build_msg_string ("exited abnormally with code "), |
| 428 | 1605 concat2 (string, string2)); |
| 1606 } | |
| 1607 else | |
| 1608 return Fcopy_sequence (Fsymbol_name (symbol)); | |
| 1609 } | |
| 1610 | |
| 1611 /* Tell status_notify() to check for terminated processes. We do this | |
| 1612 because on some systems we sometimes miss SIGCHLD calls. (Not sure | |
| 853 | 1613 why.) This is also used under Mswin. */ |
| 428 | 1614 |
| 1615 void | |
| 1616 kick_status_notify (void) | |
| 1617 { | |
| 1618 process_tick++; | |
| 1619 } | |
| 1620 | |
| 1621 | |
| 1622 /* Report all recent events of a change in process status | |
| 1623 (either run the sentinel or output a message). | |
| 1624 This is done while Emacs is waiting for keyboard input. */ | |
| 1625 | |
| 1626 void | |
| 1627 status_notify (void) | |
| 1628 { | |
| 1629 /* This function can GC */ | |
| 1630 Lisp_Object tail = Qnil; | |
| 1631 Lisp_Object symbol = Qnil; | |
| 1632 Lisp_Object msg = Qnil; | |
| 1633 struct gcpro gcpro1, gcpro2, gcpro3; | |
| 1634 /* process_tick is volatile, so we have to remember it now. | |
| 444 | 1635 Otherwise, we get a race condition if SIGCHLD happens during |
| 428 | 1636 this function. |
| 1637 | |
| 1638 (Actually, this is not the case anymore. The code to | |
| 1639 update the process structures has been moved out of the | |
| 1640 SIGCHLD handler. But for the moment I'm leaving this | |
| 1641 stuff in -- it can't hurt.) */ | |
| 1642 int temp_process_tick; | |
| 1643 | |
| 1644 MAYBE_PROCMETH (reap_exited_processes, ()); | |
| 1645 | |
| 1646 temp_process_tick = process_tick; | |
| 1647 | |
| 1648 if (update_tick == temp_process_tick) | |
| 1649 return; | |
| 1650 | |
| 1651 /* We need to gcpro tail; if read_process_output calls a filter | |
| 1652 which deletes a process and removes the cons to which tail points | |
| 1653 from Vprocess_alist, and then causes a GC, tail is an unprotected | |
| 1654 reference. */ | |
| 1655 GCPRO3 (tail, symbol, msg); | |
| 1656 | |
| 1657 for (tail = Vprocess_list; CONSP (tail); tail = XCDR (tail)) | |
| 1658 { | |
| 444 | 1659 Lisp_Object process = XCAR (tail); |
| 1660 Lisp_Process *p = XPROCESS (process); | |
| 428 | 1661 /* p->tick is also volatile. Same thing as above applies. */ |
| 1662 int this_process_tick; | |
| 1663 | |
| 1664 /* #### extra check for terminated processes, in case a SIGCHLD | |
| 1665 got missed (this seems to happen sometimes, I'm not sure why). | |
| 1666 */ | |
| 1667 if (INTP (p->pid)) | |
| 1668 MAYBE_PROCMETH (update_status_if_terminated, (p)); | |
| 1669 | |
| 1670 this_process_tick = p->tick; | |
| 1671 if (this_process_tick != p->update_tick) | |
| 1672 { | |
| 1673 p->update_tick = this_process_tick; | |
| 1674 | |
| 1675 /* If process is still active, read any output that remains. */ | |
| 1676 while (!EQ (p->filter, Qt) | |
| 853 | 1677 && read_process_output (process, 0) > 0) |
| 1678 ; | |
| 1679 while (p->separate_stderr && !EQ (p->stderr_filter, Qt) | |
| 1680 && read_process_output (process, 1) > 0) | |
| 428 | 1681 ; |
| 1682 | |
| 1683 /* Get the text to use for the message. */ | |
| 1684 msg = status_message (p); | |
| 1685 | |
| 1686 /* If process is terminated, deactivate it or delete it. */ | |
| 1687 symbol = p->status_symbol; | |
| 1688 | |
| 1689 if (EQ (symbol, Qsignal) | |
| 1690 || EQ (symbol, Qexit)) | |
| 1691 { | |
| 1692 if (delete_exited_processes) | |
| 444 | 1693 remove_process (process); |
| 428 | 1694 else |
| 444 | 1695 deactivate_process (process); |
| 428 | 1696 } |
| 1697 | |
| 1698 /* Now output the message suitably. */ | |
| 1699 if (!NILP (p->sentinel)) | |
| 444 | 1700 exec_sentinel (process, msg); |
| 428 | 1701 /* Don't bother with a message in the buffer |
| 1702 when a process becomes runnable. */ | |
| 844 | 1703 else if (!EQ (symbol, Qrun) && !NILP (p->buffer) && |
| 1704 /* Avoid error if buffer is deleted | |
| 1705 (probably that's why the process is dead, too) */ | |
| 1706 BUFFER_LIVE_P (XBUFFER (p->buffer))) | |
| 428 | 1707 { |
| 844 | 1708 struct gcpro ngcpro1; |
| 853 | 1709 int spec = process_setup_for_insertion (process, 0); |
| 428 | 1710 |
| 844 | 1711 NGCPRO1 (process); |
| 428 | 1712 buffer_insert_c_string (current_buffer, "\nProcess "); |
| 1713 Finsert (1, &p->name); | |
| 1714 buffer_insert_c_string (current_buffer, " "); | |
| 1715 Finsert (1, &msg); | |
| 1716 Fset_marker (p->mark, make_int (BUF_PT (current_buffer)), | |
| 1717 p->buffer); | |
| 1718 | |
| 844 | 1719 unbind_to (spec); |
| 428 | 1720 NUNGCPRO; |
| 1721 } | |
| 1722 } | |
| 1723 } /* end for */ | |
| 1724 | |
| 1725 /* in case buffers use %s in modeline-format */ | |
| 1726 MARK_MODELINE_CHANGED; | |
| 1727 redisplay (); | |
| 1728 | |
| 1729 update_tick = temp_process_tick; | |
| 1730 | |
| 1731 UNGCPRO; | |
| 1732 } | |
| 1733 | |
| 1734 DEFUN ("process-status", Fprocess_status, 1, 1, 0, /* | |
| 1735 Return the status of PROCESS. | |
| 1736 This is a symbol, one of these: | |
| 1737 | |
| 1738 run -- for a process that is running. | |
| 1739 stop -- for a process stopped but continuable. | |
| 1740 exit -- for a process that has exited. | |
| 1741 signal -- for a process that has got a fatal signal. | |
| 1742 open -- for a network stream connection that is open. | |
| 1743 closed -- for a network stream connection that is closed. | |
| 1744 nil -- if arg is a process name and no such process exists. | |
| 1745 | |
| 1746 PROCESS may be a process, a buffer, the name of a process or buffer, or | |
| 1747 nil, indicating the current buffer's process. | |
| 1748 */ | |
| 444 | 1749 (process)) |
| 428 | 1750 { |
| 1751 Lisp_Object status_symbol; | |
| 1752 | |
| 444 | 1753 if (STRINGP (process)) |
| 1754 process = Fget_process (process); | |
| 428 | 1755 else |
| 444 | 1756 process = get_process (process); |
| 428 | 1757 |
| 444 | 1758 if (NILP (process)) |
| 428 | 1759 return Qnil; |
| 1760 | |
| 444 | 1761 status_symbol = XPROCESS (process)->status_symbol; |
| 1762 if (network_connection_p (process)) | |
| 428 | 1763 { |
| 1764 if (EQ (status_symbol, Qrun)) | |
| 1765 status_symbol = Qopen; | |
| 1766 else if (EQ (status_symbol, Qexit)) | |
| 1767 status_symbol = Qclosed; | |
| 1768 } | |
| 1769 return status_symbol; | |
| 1770 } | |
| 1771 | |
| 1772 DEFUN ("process-exit-status", Fprocess_exit_status, 1, 1, 0, /* | |
| 1773 Return the exit status of PROCESS or the signal number that killed it. | |
| 1774 If PROCESS has not yet exited or died, return 0. | |
| 1775 */ | |
| 444 | 1776 (process)) |
| 428 | 1777 { |
| 444 | 1778 CHECK_PROCESS (process); |
| 1779 return make_int (XPROCESS (process)->exit_code); | |
| 428 | 1780 } |
| 1781 | |
| 1782 | |
| 1783 | |
| 442 | 1784 static int |
| 1785 decode_signal (Lisp_Object signal_) | |
| 428 | 1786 { |
| 442 | 1787 if (INTP (signal_)) |
| 1788 return XINT (signal_); | |
| 428 | 1789 else |
| 1790 { | |
| 867 | 1791 Ibyte *name; |
| 428 | 1792 |
| 442 | 1793 CHECK_SYMBOL (signal_); |
| 793 | 1794 name = XSTRING_DATA (XSYMBOL (signal_)->name); |
| 428 | 1795 |
| 793 | 1796 #define handle_signal(sym) do { \ |
| 2367 | 1797 if (!qxestrcmp_ascii ( name, #sym)) \ |
| 793 | 1798 return sym; \ |
| 442 | 1799 } while (0) |
| 428 | 1800 |
| 1801 handle_signal (SIGINT); /* ANSI */ | |
| 1802 handle_signal (SIGILL); /* ANSI */ | |
| 1803 handle_signal (SIGABRT); /* ANSI */ | |
| 1804 handle_signal (SIGFPE); /* ANSI */ | |
| 1805 handle_signal (SIGSEGV); /* ANSI */ | |
| 1806 handle_signal (SIGTERM); /* ANSI */ | |
| 1807 | |
| 1808 #ifdef SIGHUP | |
| 1809 handle_signal (SIGHUP); /* POSIX */ | |
| 1810 #endif | |
| 1811 #ifdef SIGQUIT | |
| 1812 handle_signal (SIGQUIT); /* POSIX */ | |
| 1813 #endif | |
| 1814 #ifdef SIGTRAP | |
| 1815 handle_signal (SIGTRAP); /* POSIX */ | |
| 1816 #endif | |
| 1817 #ifdef SIGKILL | |
| 1818 handle_signal (SIGKILL); /* POSIX */ | |
| 1819 #endif | |
| 1820 #ifdef SIGUSR1 | |
| 1821 handle_signal (SIGUSR1); /* POSIX */ | |
| 1822 #endif | |
| 1823 #ifdef SIGUSR2 | |
| 1824 handle_signal (SIGUSR2); /* POSIX */ | |
| 1825 #endif | |
| 1826 #ifdef SIGPIPE | |
| 1827 handle_signal (SIGPIPE); /* POSIX */ | |
| 1828 #endif | |
| 1829 #ifdef SIGALRM | |
| 1830 handle_signal (SIGALRM); /* POSIX */ | |
| 1831 #endif | |
| 1832 #ifdef SIGCHLD | |
| 1833 handle_signal (SIGCHLD); /* POSIX */ | |
| 1834 #endif | |
| 1835 #ifdef SIGCONT | |
| 1836 handle_signal (SIGCONT); /* POSIX */ | |
| 1837 #endif | |
| 1838 #ifdef SIGSTOP | |
| 1839 handle_signal (SIGSTOP); /* POSIX */ | |
| 1840 #endif | |
| 1841 #ifdef SIGTSTP | |
| 1842 handle_signal (SIGTSTP); /* POSIX */ | |
| 1843 #endif | |
| 1844 #ifdef SIGTTIN | |
| 1845 handle_signal (SIGTTIN); /* POSIX */ | |
| 1846 #endif | |
| 1847 #ifdef SIGTTOU | |
| 1848 handle_signal (SIGTTOU); /* POSIX */ | |
| 1849 #endif | |
| 1850 | |
| 1851 #ifdef SIGBUS | |
| 1852 handle_signal (SIGBUS); /* XPG5 */ | |
| 1853 #endif | |
| 1854 #ifdef SIGPOLL | |
| 1855 handle_signal (SIGPOLL); /* XPG5 */ | |
| 1856 #endif | |
| 1857 #ifdef SIGPROF | |
| 1858 handle_signal (SIGPROF); /* XPG5 */ | |
| 1859 #endif | |
| 1860 #ifdef SIGSYS | |
| 1861 handle_signal (SIGSYS); /* XPG5 */ | |
| 1862 #endif | |
| 1863 #ifdef SIGURG | |
| 1864 handle_signal (SIGURG); /* XPG5 */ | |
| 1865 #endif | |
| 1866 #ifdef SIGXCPU | |
| 1867 handle_signal (SIGXCPU); /* XPG5 */ | |
| 1868 #endif | |
| 1869 #ifdef SIGXFSZ | |
| 1870 handle_signal (SIGXFSZ); /* XPG5 */ | |
| 1871 #endif | |
| 1872 #ifdef SIGVTALRM | |
| 1873 handle_signal (SIGVTALRM); /* XPG5 */ | |
| 1874 #endif | |
| 1875 | |
| 1876 #ifdef SIGIO | |
| 1877 handle_signal (SIGIO); /* BSD 4.2 */ | |
| 1878 #endif | |
| 1879 #ifdef SIGWINCH | |
| 1880 handle_signal (SIGWINCH); /* BSD 4.3 */ | |
| 1881 #endif | |
| 1882 | |
| 1883 #ifdef SIGEMT | |
| 1884 handle_signal (SIGEMT); | |
| 1885 #endif | |
| 1886 #ifdef SIGINFO | |
| 1887 handle_signal (SIGINFO); | |
| 1888 #endif | |
| 1889 #ifdef SIGHWE | |
| 1890 handle_signal (SIGHWE); | |
| 1891 #endif | |
| 1892 #ifdef SIGPRE | |
| 1893 handle_signal (SIGPRE); | |
| 1894 #endif | |
| 1895 #ifdef SIGUME | |
| 1896 handle_signal (SIGUME); | |
| 1897 #endif | |
| 1898 #ifdef SIGDLK | |
| 1899 handle_signal (SIGDLK); | |
| 1900 #endif | |
| 1901 #ifdef SIGCPULIM | |
| 1902 handle_signal (SIGCPULIM); | |
| 1903 #endif | |
| 1904 #ifdef SIGIOT | |
| 1905 handle_signal (SIGIOT); | |
| 1906 #endif | |
| 1907 #ifdef SIGLOST | |
| 1908 handle_signal (SIGLOST); | |
| 1909 #endif | |
| 1910 #ifdef SIGSTKFLT | |
| 1911 handle_signal (SIGSTKFLT); | |
| 1912 #endif | |
| 1913 #ifdef SIGUNUSED | |
| 1914 handle_signal (SIGUNUSED); | |
| 1915 #endif | |
| 1916 #ifdef SIGDANGER | |
| 1917 handle_signal (SIGDANGER); /* AIX */ | |
| 1918 #endif | |
| 1919 #ifdef SIGMSG | |
| 1920 handle_signal (SIGMSG); | |
| 1921 #endif | |
| 1922 #ifdef SIGSOUND | |
| 1923 handle_signal (SIGSOUND); | |
| 1924 #endif | |
| 1925 #ifdef SIGRETRACT | |
| 1926 handle_signal (SIGRETRACT); | |
| 1927 #endif | |
| 1928 #ifdef SIGGRANT | |
| 1929 handle_signal (SIGGRANT); | |
| 1930 #endif | |
| 1931 #ifdef SIGPWR | |
| 1932 handle_signal (SIGPWR); | |
| 1933 #endif | |
| 1934 | |
| 1935 #undef handle_signal | |
| 1936 | |
| 563 | 1937 invalid_constant ("Undefined signal name", signal_); |
| 1204 | 1938 RETURN_NOT_REACHED (0); |
| 442 | 1939 } |
| 1940 } | |
| 1941 | |
| 1942 /* Send signal number SIGNO to PROCESS. | |
| 1943 CURRENT-GROUP non-nil means send signal to the current | |
| 1944 foreground process group of the process's controlling terminal rather | |
| 1945 than to the process's own process group. | |
| 1946 This is used for various commands in shell mode. | |
| 1947 If NOMSG is zero, insert signal-announcements into process's buffers | |
| 1948 right away. | |
| 1949 | |
| 1950 If we can, we try to signal PROCESS by sending control characters | |
| 1951 down the pty. This allows us to signal inferiors who have changed | |
| 1952 their uid, for which kill() would return an EPERM error, or to | |
| 1953 processes running on another computer through a remote login. */ | |
| 1954 | |
| 1955 static void | |
| 1956 process_send_signal (Lisp_Object process, int signo, | |
| 1957 int current_group, int nomsg) | |
| 1958 { | |
| 1959 /* This function can GC */ | |
| 444 | 1960 process = get_process (process); |
| 442 | 1961 |
| 444 | 1962 if (network_connection_p (process)) |
| 563 | 1963 invalid_operation ("Network connection is not a subprocess", process); |
| 444 | 1964 CHECK_LIVE_PROCESS (process); |
| 442 | 1965 |
| 444 | 1966 MAYBE_PROCMETH (kill_child_process, (process, signo, current_group, nomsg)); |
| 442 | 1967 } |
| 1968 | |
| 1969 DEFUN ("process-send-signal", Fprocess_send_signal, 1, 3, 0, /* | |
| 1970 Send signal SIGNAL to process PROCESS. | |
| 1971 SIGNAL may be an integer, or a symbol naming a signal, like `SIGSEGV'. | |
| 1972 PROCESS may be a process, a buffer, the name of a process or buffer, or | |
| 1973 nil, indicating the current buffer's process. | |
| 1974 Third arg CURRENT-GROUP non-nil means send signal to the current | |
| 1975 foreground process group of the process's controlling terminal rather | |
| 1976 than to the process's own process group. | |
| 1977 If the process is a shell that supports job control, this means | |
| 1978 send the signal to the current subjob rather than the shell. | |
| 1979 */ | |
| 1980 (signal_, process, current_group)) | |
| 1981 { | |
| 1982 /* This function can GC */ | |
| 1983 process_send_signal (process, decode_signal (signal_), | |
| 1984 !NILP (current_group), 0); | |
| 1985 return process; | |
| 1986 } | |
| 1987 | |
| 1988 DEFUN ("interrupt-process", Finterrupt_process, 0, 2, 0, /* | |
| 1989 Interrupt process PROCESS. | |
| 1990 See function `process-send-signal' for more details on usage. | |
| 1991 */ | |
| 1992 (process, current_group)) | |
| 1993 { | |
| 1994 /* This function can GC */ | |
| 1995 process_send_signal (process, SIGINT, !NILP (current_group), 0); | |
| 1996 return process; | |
| 1997 } | |
| 1998 | |
| 1999 DEFUN ("kill-process", Fkill_process, 0, 2, 0, /* | |
| 2000 Kill process PROCESS. | |
| 2001 See function `process-send-signal' for more details on usage. | |
| 2002 */ | |
| 2003 (process, current_group)) | |
| 2004 { | |
| 2005 /* This function can GC */ | |
| 2006 #ifdef SIGKILL | |
| 2007 process_send_signal (process, SIGKILL, !NILP (current_group), 0); | |
| 2008 #else | |
| 563 | 2009 signal_error (Qunimplemented, |
| 2010 "kill-process: Not supported on this system", | |
| 2011 Qunbound); | |
| 442 | 2012 #endif |
| 2013 return process; | |
| 2014 } | |
| 2015 | |
| 2016 DEFUN ("quit-process", Fquit_process, 0, 2, 0, /* | |
| 2017 Send QUIT signal to process PROCESS. | |
| 2018 See function `process-send-signal' for more details on usage. | |
| 2019 */ | |
| 2020 (process, current_group)) | |
| 2021 { | |
| 2022 /* This function can GC */ | |
| 2023 #ifdef SIGQUIT | |
| 2024 process_send_signal (process, SIGQUIT, !NILP (current_group), 0); | |
| 2025 #else | |
| 563 | 2026 signal_error (Qunimplemented, |
| 2027 "quit-process: Not supported on this system", | |
| 2028 Qunbound); | |
| 442 | 2029 #endif |
| 2030 return process; | |
| 2031 } | |
| 2032 | |
| 2033 DEFUN ("stop-process", Fstop_process, 0, 2, 0, /* | |
| 2034 Stop process PROCESS. | |
| 2035 See function `process-send-signal' for more details on usage. | |
| 2036 */ | |
| 2037 (process, current_group)) | |
| 2038 { | |
| 2039 /* This function can GC */ | |
| 2040 #ifdef SIGTSTP | |
| 2041 process_send_signal (process, SIGTSTP, !NILP (current_group), 0); | |
| 2042 #else | |
| 563 | 2043 signal_error (Qunimplemented, |
| 2044 "stop-process: Not supported on this system", | |
| 2045 Qunbound); | |
| 442 | 2046 #endif |
| 2047 return process; | |
| 2048 } | |
| 2049 | |
| 2050 DEFUN ("continue-process", Fcontinue_process, 0, 2, 0, /* | |
| 2051 Continue process PROCESS. | |
| 2052 See function `process-send-signal' for more details on usage. | |
| 2053 */ | |
| 2054 (process, current_group)) | |
| 2055 { | |
| 2056 /* This function can GC */ | |
| 2057 #ifdef SIGCONT | |
| 2058 process_send_signal (process, SIGCONT, !NILP (current_group), 0); | |
| 2059 #else | |
| 563 | 2060 signal_error (Qunimplemented, |
| 2061 "continue-process: Not supported on this system", | |
| 2062 Qunbound); | |
| 442 | 2063 #endif |
| 2064 return process; | |
| 2065 } | |
| 2066 | |
| 2067 DEFUN ("signal-process", Fsignal_process, 2, 2, | |
| 2068 "nProcess number: \nnSignal code: ", /* | |
| 2069 Send the process with process id PID the signal with code SIGNAL. | |
| 2070 PID must be an integer. The process need not be a child of this Emacs. | |
| 2071 SIGNAL may be an integer, or a symbol naming a signal, like `SIGSEGV'. | |
| 2072 */ | |
| 2073 (pid, signal_)) | |
| 2074 { | |
| 2075 CHECK_INT (pid); | |
| 2076 | |
| 428 | 2077 return make_int (PROCMETH_OR_GIVEN (kill_process_by_pid, |
| 442 | 2078 (XINT (pid), decode_signal (signal_)), |
| 2079 -1)); | |
| 428 | 2080 } |
| 2081 | |
| 2082 DEFUN ("process-send-eof", Fprocess_send_eof, 0, 1, 0, /* | |
| 2083 Make PROCESS see end-of-file in its input. | |
| 2084 PROCESS may be a process, a buffer, the name of a process or buffer, or | |
| 2085 nil, indicating the current buffer's process. | |
| 2086 If PROCESS is a network connection, or is a process communicating | |
| 2087 through a pipe (as opposed to a pty), then you cannot send any more | |
| 2088 text to PROCESS after you call this function. | |
| 2089 */ | |
| 2090 (process)) | |
| 2091 { | |
| 2092 /* This function can GC */ | |
| 444 | 2093 process = get_process (process); |
| 428 | 2094 |
| 2095 /* Make sure the process is really alive. */ | |
| 444 | 2096 if (! EQ (XPROCESS (process)->status_symbol, Qrun)) |
| 563 | 2097 invalid_operation ("Process not running", process); |
| 428 | 2098 |
| 444 | 2099 if (!MAYBE_INT_PROCMETH (process_send_eof, (process))) |
| 428 | 2100 { |
| 444 | 2101 if (!NILP (DATA_OUTSTREAM (XPROCESS (process)))) |
| 428 | 2102 { |
| 853 | 2103 USID humpty, dumpty; |
| 444 | 2104 Lstream_close (XLSTREAM (DATA_OUTSTREAM (XPROCESS (process)))); |
| 853 | 2105 event_stream_delete_io_streams (Qnil, |
| 2106 XPROCESS (process)->pipe_outstream, | |
| 2107 Qnil, &humpty, &dumpty); | |
| 444 | 2108 XPROCESS (process)->pipe_outstream = Qnil; |
| 2109 XPROCESS (process)->coding_outstream = Qnil; | |
| 428 | 2110 } |
| 2111 } | |
| 2112 | |
| 2113 return process; | |
| 2114 } | |
| 2115 | |
| 2116 | |
| 2117 /************************************************************************/ | |
| 2118 /* deleting a process */ | |
| 2119 /************************************************************************/ | |
| 2120 | |
| 2121 void | |
| 444 | 2122 deactivate_process (Lisp_Object process) |
| 428 | 2123 { |
| 444 | 2124 Lisp_Process *p = XPROCESS (process); |
| 853 | 2125 USID in_usid, err_usid; |
| 428 | 2126 |
| 2127 /* It's possible that we got as far in the process-creation | |
| 2128 process as creating the descriptors but didn't get so | |
| 2129 far as selecting the process for input. In this | |
| 2130 case, p->pid is nil: p->pid is set at the same time that | |
| 2131 the process is selected for input. */ | |
| 2132 /* #### The comment does not look correct. event_stream_unselect_process | |
| 853 | 2133 is guarded by process->*_selected, so this is not a problem. - kkm*/ |
| 428 | 2134 /* Must call this before setting the streams to nil */ |
| 853 | 2135 event_stream_unselect_process (p, 1, 1); |
| 428 | 2136 |
| 2137 if (!NILP (DATA_OUTSTREAM (p))) | |
| 2138 Lstream_close (XLSTREAM (DATA_OUTSTREAM (p))); | |
| 2139 if (!NILP (DATA_INSTREAM (p))) | |
| 2140 Lstream_close (XLSTREAM (DATA_INSTREAM (p))); | |
| 853 | 2141 if (!NILP (DATA_ERRSTREAM (p))) |
| 2142 Lstream_close (XLSTREAM (DATA_ERRSTREAM (p))); | |
| 428 | 2143 |
| 2144 /* Provide minimal implementation for deactivate_process | |
| 2145 if there's no process-specific one */ | |
| 2146 if (HAS_PROCMETH_P (deactivate_process)) | |
| 853 | 2147 PROCMETH (deactivate_process, (p, &in_usid, &err_usid)); |
| 428 | 2148 else |
| 853 | 2149 event_stream_delete_io_streams (p->pipe_instream, |
| 2150 p->pipe_outstream, | |
| 2151 p->pipe_errstream, | |
| 2152 &in_usid, &err_usid); | |
| 428 | 2153 |
| 853 | 2154 if (in_usid != USID_DONTHASH) |
| 2367 | 2155 remhash ((const void *) in_usid, usid_to_process); |
| 853 | 2156 if (err_usid != USID_DONTHASH) |
| 2367 | 2157 remhash ((const void *) err_usid, usid_to_process); |
| 428 | 2158 |
| 2159 p->pipe_instream = Qnil; | |
| 2160 p->pipe_outstream = Qnil; | |
| 853 | 2161 p->pipe_errstream = Qnil; |
| 428 | 2162 p->coding_instream = Qnil; |
| 2163 p->coding_outstream = Qnil; | |
| 853 | 2164 p->coding_errstream = Qnil; |
| 428 | 2165 } |
| 2166 | |
| 2167 static void | |
| 444 | 2168 remove_process (Lisp_Object process) |
| 428 | 2169 { |
| 444 | 2170 Vprocess_list = delq_no_quit (process, Vprocess_list); |
| 428 | 2171 |
| 444 | 2172 deactivate_process (process); |
| 428 | 2173 } |
| 2174 | |
| 2175 DEFUN ("delete-process", Fdelete_process, 1, 1, 0, /* | |
| 2176 Delete PROCESS: kill it and forget about it immediately. | |
| 2177 PROCESS may be a process or the name of one, or a buffer name. | |
| 2178 */ | |
| 444 | 2179 (process)) |
| 428 | 2180 { |
| 2181 /* This function can GC */ | |
| 440 | 2182 Lisp_Process *p; |
| 444 | 2183 process = get_process (process); |
| 2184 p = XPROCESS (process); | |
| 2185 if (network_connection_p (process)) | |
| 428 | 2186 { |
| 2187 p->status_symbol = Qexit; | |
| 2188 p->exit_code = 0; | |
| 2189 p->core_dumped = 0; | |
| 2190 p->tick++; | |
| 2191 process_tick++; | |
| 2192 } | |
| 440 | 2193 else if (PROCESS_LIVE_P (p)) |
| 428 | 2194 { |
| 444 | 2195 Fkill_process (process, Qnil); |
| 428 | 2196 /* Do this now, since remove_process will make sigchld_handler do nothing. */ |
| 2197 p->status_symbol = Qsignal; | |
| 2198 p->exit_code = SIGKILL; | |
| 2199 p->core_dumped = 0; | |
| 2200 p->tick++; | |
| 2201 process_tick++; | |
| 2202 status_notify (); | |
| 2203 } | |
| 444 | 2204 remove_process (process); |
| 428 | 2205 return Qnil; |
| 2206 } | |
| 2207 | |
| 2208 /* Kill all processes associated with `buffer'. | |
| 2209 If `buffer' is nil, kill all processes */ | |
| 2210 | |
| 2211 void | |
| 2212 kill_buffer_processes (Lisp_Object buffer) | |
| 2213 { | |
| 444 | 2214 LIST_LOOP_2 (process, Vprocess_list) |
| 2215 if ((NILP (buffer) || EQ (XPROCESS (process)->buffer, buffer))) | |
| 2216 { | |
| 2217 if (network_connection_p (process)) | |
| 2218 Fdelete_process (process); | |
| 2219 else if (PROCESS_LIVE_P (XPROCESS (process))) | |
| 2220 process_send_signal (process, SIGHUP, 0, 1); | |
| 2221 } | |
| 428 | 2222 } |
| 2223 | |
| 2224 DEFUN ("process-kill-without-query", Fprocess_kill_without_query, 1, 2, 0, /* | |
| 2225 Say no query needed if PROCESS is running when Emacs is exited. | |
| 2226 Optional second argument if non-nil says to require a query. | |
| 2227 Value is t if a query was formerly required. | |
| 2228 */ | |
| 444 | 2229 (process, require_query_p)) |
| 428 | 2230 { |
| 2231 int tem; | |
| 2232 | |
| 444 | 2233 CHECK_PROCESS (process); |
| 2234 tem = XPROCESS (process)->kill_without_query; | |
| 2235 XPROCESS (process)->kill_without_query = NILP (require_query_p); | |
| 428 | 2236 |
| 2237 return tem ? Qnil : Qt; | |
| 2238 } | |
| 2239 | |
| 2240 DEFUN ("process-kill-without-query-p", Fprocess_kill_without_query_p, 1, 1, 0, /* | |
| 444 | 2241 Return t if PROCESS will be killed without query when emacs is exited. |
| 428 | 2242 */ |
| 444 | 2243 (process)) |
| 428 | 2244 { |
| 444 | 2245 CHECK_PROCESS (process); |
| 2246 return XPROCESS (process)->kill_without_query ? Qt : Qnil; | |
| 428 | 2247 } |
| 2248 | |
| 2249 | |
| 2250 #if 0 | |
| 2251 | |
| 826 | 2252 DEFUN ("process-connection", Fprocess_connection, 0, 1, 0, /* |
| 428 | 2253 Return the connection type of `PROCESS'. This can be nil (pipe), |
| 2254 t or pty (pty) or stream (socket connection). | |
| 2255 */ | |
| 2256 (process)) | |
| 2257 { | |
| 2258 return XPROCESS (process)->type; | |
| 2259 } | |
| 2260 | |
| 2261 #endif /* 0 */ | |
| 2262 | |
| 814 | 2263 |
| 2264 static int | |
| 867 | 2265 getenv_internal (const Ibyte *var, |
| 814 | 2266 Bytecount varlen, |
| 867 | 2267 Ibyte **value, |
| 814 | 2268 Bytecount *valuelen) |
| 2269 { | |
| 2270 Lisp_Object scan; | |
| 2271 | |
| 2272 assert (env_initted); | |
| 2273 | |
| 2274 for (scan = Vprocess_environment; CONSP (scan); scan = XCDR (scan)) | |
| 2275 { | |
| 2276 Lisp_Object entry = XCAR (scan); | |
| 2277 | |
| 2278 if (STRINGP (entry) | |
| 2279 && XSTRING_LENGTH (entry) > varlen | |
| 826 | 2280 && string_byte (entry, varlen) == '=' |
| 814 | 2281 #ifdef WIN32_NATIVE |
| 2282 /* NT environment variables are case insensitive. */ | |
| 2283 && ! memicmp (XSTRING_DATA (entry), var, varlen) | |
| 2284 #else /* not WIN32_NATIVE */ | |
| 2285 && ! memcmp (XSTRING_DATA (entry), var, varlen) | |
| 2286 #endif /* not WIN32_NATIVE */ | |
| 2287 ) | |
| 2288 { | |
| 2289 *value = XSTRING_DATA (entry) + (varlen + 1); | |
| 2290 *valuelen = XSTRING_LENGTH (entry) - (varlen + 1); | |
| 2291 return 1; | |
| 2292 } | |
| 2293 } | |
| 2294 | |
| 2295 return 0; | |
| 2296 } | |
| 2297 | |
| 2298 static void | |
| 867 | 2299 putenv_internal (const Ibyte *var, |
| 814 | 2300 Bytecount varlen, |
| 867 | 2301 const Ibyte *value, |
| 814 | 2302 Bytecount valuelen) |
| 2303 { | |
| 2304 Lisp_Object scan; | |
| 2305 | |
| 2306 assert (env_initted); | |
| 2307 | |
| 2308 for (scan = Vprocess_environment; CONSP (scan); scan = XCDR (scan)) | |
| 2309 { | |
| 2310 Lisp_Object entry = XCAR (scan); | |
| 2311 | |
| 2312 if (STRINGP (entry) | |
| 2313 && XSTRING_LENGTH (entry) > varlen | |
| 826 | 2314 && string_byte (entry, varlen) == '=' |
| 814 | 2315 #ifdef WIN32_NATIVE |
| 2316 /* NT environment variables are case insensitive. */ | |
| 2317 && ! memicmp (XSTRING_DATA (entry), var, varlen) | |
| 2318 #else /* not WIN32_NATIVE */ | |
| 2319 && ! memcmp (XSTRING_DATA (entry), var, varlen) | |
| 2320 #endif /* not WIN32_NATIVE */ | |
| 2321 ) | |
| 2322 { | |
| 2323 XCAR (scan) = concat3 (make_string (var, varlen), | |
| 2324 build_string ("="), | |
| 2325 make_string (value, valuelen)); | |
| 2326 return; | |
| 2327 } | |
| 2328 } | |
| 2329 | |
| 2330 Vprocess_environment = Fcons (concat3 (make_string (var, varlen), | |
| 2331 build_string ("="), | |
| 2332 make_string (value, valuelen)), | |
| 2333 Vprocess_environment); | |
| 2334 } | |
| 2335 | |
| 2336 /* NOTE: | |
| 2337 | |
| 2338 FSF has this as a Lisp function, as follows. Generally moving things | |
| 2339 out of C and into Lisp is a good idea, but in this case the Lisp | |
| 2340 function is used so early in the startup sequence that it would be ugly | |
| 2341 to rearrange the early dumped code to accommodate this. | |
| 854 | 2342 |
| 814 | 2343 (defun getenv (variable) |
| 2344 "Get the value of environment variable VARIABLE. | |
| 2345 VARIABLE should be a string. Value is nil if VARIABLE is undefined in | |
| 2346 the environment. Otherwise, value is a string. | |
| 2347 | |
| 2348 This function consults the variable `process-environment' | |
| 2349 for its value." | |
| 2350 (interactive (list (read-envvar-name "Get environment variable: " t))) | |
| 2351 (let ((value (getenv-internal variable))) | |
| 2352 (when (interactive-p) | |
| 2353 (message "%s" (if value value "Not set"))) | |
| 2354 value)) | |
| 2355 */ | |
| 2356 | |
| 2357 DEFUN ("getenv", Fgetenv, 1, 2, "sEnvironment variable: \np", /* | |
| 2358 Return the value of environment variable VAR, as a string. | |
| 2359 VAR is a string, the name of the variable. | |
| 2360 When invoked interactively, prints the value in the echo area. | |
| 2361 */ | |
| 2362 (var, interactivep)) | |
| 2363 { | |
| 867 | 2364 Ibyte *value; |
| 814 | 2365 Bytecount valuelen; |
| 2366 Lisp_Object v = Qnil; | |
| 2367 struct gcpro gcpro1; | |
| 2368 | |
| 2369 CHECK_STRING (var); | |
| 2370 GCPRO1 (v); | |
| 2371 if (getenv_internal (XSTRING_DATA (var), XSTRING_LENGTH (var), | |
| 2372 &value, &valuelen)) | |
| 2373 v = make_string (value, valuelen); | |
| 2374 if (!NILP (interactivep)) | |
| 2375 { | |
| 2376 if (NILP (v)) | |
| 2377 message ("%s not defined in environment", XSTRING_DATA (var)); | |
| 2378 else | |
| 2379 /* #### Should use Fprin1_to_string or Fprin1 to handle string | |
| 2380 containing quotes correctly. */ | |
| 2381 message ("\"%s\"", value); | |
| 2382 } | |
| 2383 RETURN_UNGCPRO (v); | |
| 2384 } | |
| 2385 | |
| 2386 /* A version of getenv that consults Vprocess_environment, easily | |
| 2387 callable from C. | |
| 2388 | |
| 2389 (At init time, Vprocess_environment is initialized from the | |
| 2390 environment, stored in the global variable environ. [Note that | |
| 2391 at startup time, `environ' should be the same as the envp parameter | |
| 2392 passed to main(); however, later calls to putenv() may change | |
| 2393 `environ', making the envp parameter inaccurate.] Calls to getenv() | |
| 2394 and putenv() consult and modify `environ'. However, once | |
| 2395 Vprocess_environment is initted, XEmacs C code should *NEVER* call | |
| 2396 getenv() or putenv() directly, because (1) Lisp code that modifies | |
| 2397 the environment only modifies Vprocess_environment, not `environ'; | |
| 2398 and (2) Vprocess_environment is in internal format but `environ' | |
| 2399 is in some external format, and getenv()/putenv() are not Mule- | |
| 2400 encapsulated. | |
| 2401 | |
| 2402 WARNING: This value points into Lisp string data and thus will become | |
| 2403 invalid after a GC. */ | |
| 2404 | |
| 867 | 2405 Ibyte * |
| 2406 egetenv (const CIbyte *var) | |
| 814 | 2407 { |
| 2408 /* This cannot GC -- 7-28-00 ben */ | |
| 867 | 2409 Ibyte *value; |
| 814 | 2410 Bytecount valuelen; |
| 2411 | |
| 867 | 2412 if (getenv_internal ((const Ibyte *) var, strlen (var), &value, &valuelen)) |
| 814 | 2413 return value; |
| 2414 else | |
| 2415 return 0; | |
| 2416 } | |
| 2417 | |
| 2418 void | |
| 867 | 2419 eputenv (const CIbyte *var, const CIbyte *value) |
| 814 | 2420 { |
| 867 | 2421 putenv_internal ((Ibyte *) var, strlen (var), (Ibyte *) value, |
| 814 | 2422 strlen (value)); |
| 2423 } | |
| 2424 | |
| 2425 | |
| 2426 /* This is not named init_process in order to avoid a conflict with NS 3.3 */ | |
| 2427 void | |
| 2428 init_xemacs_process (void) | |
| 2429 { | |
| 2430 /* This function can GC */ | |
| 2431 | |
| 2432 MAYBE_PROCMETH (init_process, ()); | |
| 2433 | |
| 2434 Vprocess_list = Qnil; | |
| 2435 | |
| 2436 if (usid_to_process) | |
| 2437 clrhash (usid_to_process); | |
| 2438 else | |
| 2439 usid_to_process = make_hash_table (32); | |
| 854 | 2440 |
| 814 | 2441 { |
| 2442 /* jwz: always initialize Vprocess_environment, so that egetenv() | |
| 2443 works in temacs. */ | |
| 2367 | 2444 Extbyte **envp; |
| 814 | 2445 Vprocess_environment = Qnil; |
| 2367 | 2446 #ifdef WIN32_NATIVE |
| 2447 _wgetenv (L""); /* force initialization of _wenviron */ | |
| 2448 for (envp = (Extbyte **) _wenviron; envp && *envp; envp++) | |
| 2449 Vprocess_environment = | |
| 2450 Fcons (build_ext_string (*envp, Qmswindows_unicode), | |
| 2451 Vprocess_environment); | |
| 2452 #else | |
| 814 | 2453 for (envp = environ; envp && *envp; envp++) |
| 2454 Vprocess_environment = | |
| 2455 Fcons (build_ext_string (*envp, Qnative), Vprocess_environment); | |
| 2367 | 2456 #endif |
| 814 | 2457 /* This gets set back to 0 in disksave_object_finalization() */ |
| 2458 env_initted = 1; | |
| 2459 } | |
| 2460 | |
| 2461 { | |
| 2462 /* Initialize shell-file-name from environment variables or best guess. */ | |
| 2463 #ifdef WIN32_NATIVE | |
| 867 | 2464 const Ibyte *shell = egetenv ("SHELL"); |
| 814 | 2465 if (!shell) shell = egetenv ("COMSPEC"); |
| 2466 /* Should never happen! */ | |
| 2467 if (!shell) shell = | |
| 867 | 2468 (Ibyte *) (GetVersion () & 0x80000000 ? "command" : "cmd"); |
| 814 | 2469 #else /* not WIN32_NATIVE */ |
| 867 | 2470 const Ibyte *shell = egetenv ("SHELL"); |
| 2471 if (!shell) shell = (Ibyte *) "/bin/sh"; | |
| 814 | 2472 #endif |
| 2473 | |
| 2474 #if 0 /* defined (WIN32_NATIVE) */ | |
| 2475 /* BAD BAD BAD. We do not wanting to be passing an XEmacs-created | |
| 2476 SHELL var down to some inferior Cygwin process, which might get | |
| 2477 screwed up. | |
| 854 | 2478 |
| 814 | 2479 There are a few broken apps (eterm/term.el, eterm/tshell.el, |
| 2480 os-utils/terminal.el, texinfo/tex-mode.el) where this will | |
| 2481 cause problems. Those broken apps don't look at | |
| 2482 shell-file-name, instead just at explicit-shell-file-name, | |
| 2483 ESHELL and SHELL. They are apparently attempting to borrow | |
| 2484 what `M-x shell' uses, but that latter also looks at | |
| 2485 shell-file-name. What we want is for all of these apps to look | |
| 2486 at shell-file-name, so that the user can change the value of | |
| 2487 shell-file-name and everything will work out hunky-dorey. | |
| 2488 */ | |
| 854 | 2489 |
| 814 | 2490 if (!egetenv ("SHELL")) |
| 2491 { | |
| 2367 | 2492 Ibyte *faux_var = alloca_ibytes (7 + qxestrlen (shell)); |
| 814 | 2493 qxesprintf (faux_var, "SHELL=%s", shell); |
| 2494 Vprocess_environment = Fcons (build_intstring (faux_var), | |
| 2495 Vprocess_environment); | |
| 2496 } | |
| 2497 #endif /* 0 */ | |
| 2498 | |
| 2499 Vshell_file_name = build_intstring (shell); | |
| 2500 } | |
| 2501 } | |
| 2502 | |
| 428 | 2503 void |
| 2504 syms_of_process (void) | |
| 2505 { | |
| 442 | 2506 INIT_LRECORD_IMPLEMENTATION (process); |
| 2507 | |
| 563 | 2508 DEFSYMBOL (Qprocessp); |
| 2509 DEFSYMBOL (Qprocess_live_p); | |
| 2510 DEFSYMBOL (Qrun); | |
| 2511 DEFSYMBOL (Qstop); | |
| 2512 DEFSYMBOL (Qopen); | |
| 2513 DEFSYMBOL (Qclosed); | |
| 863 | 2514 #if 0 |
| 2515 /* see comment at Fprocess_readable_p */ | |
| 2516 DEFSYMBOL (&Qprocess_readable_p); | |
| 2517 #endif | |
| 563 | 2518 DEFSYMBOL (Qtcp); |
| 2519 DEFSYMBOL (Qudp); | |
| 428 | 2520 |
| 2521 #ifdef HAVE_MULTICAST | |
| 563 | 2522 DEFSYMBOL (Qmulticast); /* Used for occasional warnings */ |
| 428 | 2523 #endif |
| 2524 | |
| 563 | 2525 DEFERROR_STANDARD (Qprocess_error, Qio_error); |
| 2526 DEFERROR_STANDARD (Qnetwork_error, Qio_error); | |
| 2527 | |
| 428 | 2528 DEFSUBR (Fprocessp); |
| 440 | 2529 DEFSUBR (Fprocess_live_p); |
| 863 | 2530 #if 0 |
| 2531 /* see comment at Fprocess_readable_p */ | |
| 2532 DEFSUBR (Fprocess_readable_p); | |
| 2533 #endif | |
| 428 | 2534 DEFSUBR (Fget_process); |
| 2535 DEFSUBR (Fget_buffer_process); | |
| 2536 DEFSUBR (Fdelete_process); | |
| 2537 DEFSUBR (Fprocess_status); | |
| 2538 DEFSUBR (Fprocess_exit_status); | |
| 2539 DEFSUBR (Fprocess_id); | |
| 2540 DEFSUBR (Fprocess_name); | |
| 2541 DEFSUBR (Fprocess_tty_name); | |
| 2542 DEFSUBR (Fprocess_command); | |
| 859 | 2543 DEFSUBR (Fprocess_has_separate_stderr_p); |
| 428 | 2544 DEFSUBR (Fset_process_buffer); |
| 853 | 2545 DEFSUBR (Fset_process_stderr_buffer); |
| 428 | 2546 DEFSUBR (Fprocess_buffer); |
| 2547 DEFSUBR (Fprocess_mark); | |
| 853 | 2548 DEFSUBR (Fprocess_stderr_buffer); |
| 2549 DEFSUBR (Fprocess_stderr_mark); | |
| 428 | 2550 DEFSUBR (Fset_process_filter); |
| 2551 DEFSUBR (Fprocess_filter); | |
| 853 | 2552 DEFSUBR (Fset_process_stderr_filter); |
| 2553 DEFSUBR (Fprocess_stderr_filter); | |
| 428 | 2554 DEFSUBR (Fset_process_window_size); |
| 2555 DEFSUBR (Fset_process_sentinel); | |
| 2556 DEFSUBR (Fprocess_sentinel); | |
| 2557 DEFSUBR (Fprocess_kill_without_query); | |
| 2558 DEFSUBR (Fprocess_kill_without_query_p); | |
| 2559 DEFSUBR (Fprocess_list); | |
| 2560 DEFSUBR (Fstart_process_internal); | |
| 2561 #ifdef HAVE_SOCKETS | |
| 2562 DEFSUBR (Fopen_network_stream_internal); | |
| 2563 #ifdef HAVE_MULTICAST | |
| 2564 DEFSUBR (Fopen_multicast_group_internal); | |
| 2565 #endif /* HAVE_MULTICAST */ | |
| 2566 #endif /* HAVE_SOCKETS */ | |
| 2567 DEFSUBR (Fprocess_send_region); | |
| 2568 DEFSUBR (Fprocess_send_string); | |
| 442 | 2569 DEFSUBR (Fprocess_send_signal); |
| 428 | 2570 DEFSUBR (Finterrupt_process); |
| 2571 DEFSUBR (Fkill_process); | |
| 2572 DEFSUBR (Fquit_process); | |
| 2573 DEFSUBR (Fstop_process); | |
| 2574 DEFSUBR (Fcontinue_process); | |
| 2575 DEFSUBR (Fprocess_send_eof); | |
| 2576 DEFSUBR (Fsignal_process); | |
| 2577 /* DEFSUBR (Fprocess_connection); */ | |
| 2578 DEFSUBR (Fprocess_input_coding_system); | |
| 2579 DEFSUBR (Fprocess_output_coding_system); | |
| 2580 DEFSUBR (Fset_process_input_coding_system); | |
| 2581 DEFSUBR (Fset_process_output_coding_system); | |
| 2582 DEFSUBR (Fprocess_coding_system); | |
| 2583 DEFSUBR (Fset_process_coding_system); | |
| 814 | 2584 DEFSUBR (Fgetenv); |
| 428 | 2585 } |
| 2586 | |
| 2587 void | |
| 2588 vars_of_process (void) | |
| 2589 { | |
| 2590 Fprovide (intern ("subprocesses")); | |
| 2591 #ifdef HAVE_SOCKETS | |
| 2592 Fprovide (intern ("network-streams")); | |
| 2593 #ifdef HAVE_MULTICAST | |
| 2594 Fprovide (intern ("multicast")); | |
| 2595 #endif /* HAVE_MULTICAST */ | |
| 2596 #endif /* HAVE_SOCKETS */ | |
| 2597 staticpro (&Vprocess_list); | |
| 2598 | |
| 2599 DEFVAR_BOOL ("delete-exited-processes", &delete_exited_processes /* | |
| 2600 *Non-nil means delete processes immediately when they exit. | |
| 2601 nil means don't delete them until `list-processes' is run. | |
| 2602 */ ); | |
| 2603 | |
| 2604 delete_exited_processes = 1; | |
| 2605 | |
| 442 | 2606 DEFVAR_CONST_LISP ("null-device", &Vnull_device /* |
| 2607 Name of the null device, which differs from system to system. | |
| 2608 The null device is a filename that acts as a sink for arbitrary amounts of | |
| 2609 data, which is discarded, or as a source for a zero-length file. | |
| 2610 It is available on all the systems that we currently support, but with | |
| 2611 different names (typically either `/dev/null' or `nul'). | |
| 2612 | |
| 2613 Note that there is also a /dev/zero on most modern Unix versions (including | |
| 2614 Cygwin), which acts like /dev/null when used as a sink, but as a source | |
| 2615 it sends a non-ending stream of zero bytes. It's used most often along | |
| 2616 with memory-mapping. We don't provide a Lisp variable for this because | |
| 2617 the operations needing this are lower level than what ELisp programs | |
| 2618 typically do, and in any case no equivalent exists under native MS Windows. | |
| 2619 */ ); | |
| 2620 Vnull_device = build_string (NULL_DEVICE); | |
| 2621 | |
| 428 | 2622 DEFVAR_LISP ("process-connection-type", &Vprocess_connection_type /* |
| 2623 Control type of device used to communicate with subprocesses. | |
| 2624 Values are nil to use a pipe, or t or `pty' to use a pty. | |
| 2625 The value has no effect if the system has no ptys or if all ptys are busy: | |
| 2626 then a pipe is used in any case. | |
| 2627 The value takes effect when `start-process' is called. | |
| 2628 */ ); | |
| 2629 Vprocess_connection_type = Qt; | |
| 2630 | |
| 2631 DEFVAR_BOOL ("windowed-process-io", &windowed_process_io /* | |
| 2632 Enables input/output on standard handles of a windowed process. | |
| 2633 When this variable is nil (the default), XEmacs does not attempt to read | |
| 2634 standard output handle of a windowed process. Instead, the process is | |
| 2635 immediately marked as exited immediately upon successful launching. This is | |
| 2636 done because normal windowed processes do not use standard I/O, as they are | |
| 2637 not connected to any console. | |
| 2638 | |
| 2639 When launching a specially crafted windowed process, which expects to be | |
| 2640 launched by XEmacs, or by other program which pipes its standard input and | |
| 2641 output, this variable must be set to non-nil, in which case XEmacs will | |
| 2642 treat this process just like a console process. | |
| 2643 | |
| 2644 NOTE: You should never set this variable, only bind it. | |
| 2645 | |
| 2646 Only Windows processes can be "windowed" or "console". This variable has no | |
| 2647 effect on UNIX processes, because all UNIX processes are "console". | |
| 2648 */ ); | |
| 2649 windowed_process_io = 0; | |
| 2650 | |
| 771 | 2651 DEFVAR_INT ("debug-process-io", &debug_process_io /* |
| 2652 If non-zero, display data sent to or received from a process. | |
| 2653 */ ); | |
| 2654 debug_process_io = 0; | |
| 2655 | |
| 2656 DEFVAR_LISP ("default-process-coding-system", | |
| 2657 &Vdefault_process_coding_system /* | |
| 2658 Cons of coding systems used for process I/O by default. | |
| 2659 The car part is used for reading (decoding) data from a process, and | |
| 2660 the cdr part is used for writing (encoding) data to a process. | |
| 2661 */ ); | |
| 2662 /* This below will get its default set correctly in code-init.el. */ | |
| 2663 Vdefault_process_coding_system = Fcons (Qundecided, Qnil); | |
| 2664 | |
| 853 | 2665 DEFVAR_LISP ("default-network-coding-system", |
| 2666 &Vdefault_network_coding_system /* | |
| 2667 Cons of coding systems used for network I/O by default. | |
| 2668 The car part is used for reading (decoding) data from a process, and | |
| 2669 the cdr part is used for writing (encoding) data to a process. | |
| 2670 */ ); | |
| 2671 Vdefault_network_coding_system = Fcons (Qundecided, Qnil); | |
| 2672 | |
| 428 | 2673 #ifdef PROCESS_IO_BLOCKING |
| 2674 DEFVAR_LISP ("network-stream-blocking-port-list", &network_stream_blocking_port_list /* | |
| 2675 List of port numbers or port names to set a blocking I/O mode with connection. | |
| 862 | 2676 Nil value means to set a default (non-blocking) I/O mode. |
| 428 | 2677 The value takes effect when `open-network-stream-internal' is called. |
| 2678 */ ); | |
| 2679 network_stream_blocking_port_list = Qnil; | |
| 2680 #endif /* PROCESS_IO_BLOCKING */ | |
| 814 | 2681 |
| 2682 /* This function can GC */ | |
| 2683 DEFVAR_LISP ("shell-file-name", &Vshell_file_name /* | |
| 2684 *File name to load inferior shells from. | |
| 2685 Initialized from the SHELL environment variable. | |
| 2686 */ ); | |
| 428 | 2687 |
| 814 | 2688 DEFVAR_LISP ("process-environment", &Vprocess_environment /* |
| 2689 List of environment variables for subprocesses to inherit. | |
| 2690 Each element should be a string of the form ENVVARNAME=VALUE. | |
| 2691 The environment which Emacs inherits is placed in this variable | |
| 2692 when Emacs starts. | |
| 2693 */ ); | |
| 2694 | |
| 2695 Vlisp_EXEC_SUFFIXES = build_string (EXEC_SUFFIXES); | |
| 2696 staticpro (&Vlisp_EXEC_SUFFIXES); | |
| 2697 } |
