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