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