Mercurial > hg > xemacs-beta
comparison src/process.c @ 853:2b6fa2618f76
[xemacs-hg @ 2002-05-28 08:44:22 by ben]
merge my stderr-proc ws
make-docfile.c: Fix places where we forget to check for EOF.
code-init.el: Don't use CRLF conversion by default on process output. CMD.EXE and
friends work both ways but Cygwin programs don't like the CRs.
code-process.el, multicast.el, process.el: Removed.
Improvements to call-process-internal:
-- allows a buffer to be specified for input and stderr output
-- use it on all systems
-- implement C-g as documented
-- clean up and comment
call-process-region uses new call-process facilities; no temp file.
remove duplicate funs in process.el.
comment exactly how coding systems work and fix various problems.
open-multicast-group now does similar coding-system frobbing to
open-network-stream.
dumped-lisp.el, faces.el, msw-faces.el: Fix some hidden errors due to code not being defined at the right time.
xemacs.mak: Add -DSTRICT.
================================================================
ALLOW SEPARATION OF STDOUT AND STDERR IN PROCESSES
================================================================
Standard output and standard error can be processed separately in
a process. Each can have its own buffer, its own mark in that buffer,
and its filter function. You can specify a separate buffer for stderr
in `start-process' to get things started, or use the new primitives:
set-process-stderr-buffer
process-stderr-buffer
process-stderr-mark
set-process-stderr-filter
process-stderr-filter
Also, process-send-region takes a 4th optional arg, a buffer.
Currently always uses a pipe() under Unix to read the error output.
(#### Would a PTY be better?)
sysdep.h, sysproc.h, unexfreebsd.c, unexsunos4.c, nt.c, emacs.c, callproc.c, symsinit.h, sysdep.c, Makefile.in.in, process-unix.c: Delete callproc.c. Move child_setup() to process-unix.c.
wait_for_termination() now only needed on a few really old systems.
console-msw.h, event-Xt.c, event-msw.c, event-stream.c, event-tty.c, event-unixoid.c, events.h, process-nt.c, process-unix.c, process.c, process.h, procimpl.h: Rewrite the process methods to handle a separate channel for
error input. Create Lstreams for reading in the error channel.
Many process methods need change. In general the changes are
fairly clear as they involve duplicating what's used for reading
the normal stdout and changing for stderr -- although tedious,
as such changes are required throughout the entire process code.
Rewrote the code that reads process output to do two loops, one
for stdout and one for stderr.
gpmevent.c, tooltalk.c: set_process_filter takes an argument for stderr.
================================================================
NEW ERROR-TRAPPING MECHANISM
================================================================
Totally rewrite error trapping code to be unified and support more
features. Basic function is call_trapping_problems(), which lets
you specify, by means of flags, what sorts of problems you want
trapped. these can include
-- quit
-- errors
-- throws past the function
-- creation of "display objects" (e.g. buffers)
-- deletion of already-existing "display objects" (e.g. buffers)
-- modification of already-existing buffers
-- entering the debugger
-- gc
-- errors->warnings (ala suspended errors)
etc. All other error funs rewritten in terms of this one.
Various older mechanisms removed or rewritten.
window.c, insdel.c, console.c, buffer.c, device.c, frame.c: When creating a display object, added call to
note_object_created(), for use with trapping_problems mechanism.
When deleting, call check_allowed_operation() and note_object
deleted().
The trapping-problems code records the objects created since the
call-trapping-problems began. Those objects can be deleted, but
none others (i.e. previously existing ones).
bytecode.c, cmdloop.c: internal_catch takes another arg.
eval.c: Add long comments describing the "five lists" used to maintain
state (backtrace, gcpro, specbind, etc.) in the Lisp engine.
backtrace.h, eval.c: Implement trapping-problems mechanism, eliminate old mechanisms or
redo in terms of new one.
frame.c, gutter.c: Flush out the concept of "critical display section", defined by
the in_display() var. Use an internal_bind() to get it reset,
rather than just doing it at end, because there may be a non-local
exit.
event-msw.c, event-stream.c, console-msw.h, device.c, dialog-msw.c, frame.c, frame.h, intl.c, toolbar.c, menubar-msw.c, redisplay.c, alloc.c, menubar-x.c: Make use of new trapping-errors stuff and rewrite code based on
old mechanisms.
glyphs-widget.c, redisplay.h: Protect calling Lisp in redisplay.
insdel.c: Protect hooks against deleting existing buffers.
frame-msw.c: Use EQ, not EQUAL in hash tables whose keys are just numbers.
Otherwise we run into stickiness in redisplay because
internal_equal() can QUIT.
================================================================
SIGNAL, C-G CHANGES
================================================================
Here we change the way that C-g interacts with event reading. The
idea is that a C-g occurring while we're reading a user event
should be read as C-g, but elsewhere should be a QUIT. The former
code did all sorts of bizarreness -- requiring that no QUIT occurs
anywhere in event-reading code (impossible to enforce given the
stuff called or Lisp code invoked), and having some weird system
involving enqueue/dequeue of a C-g and interaction with Vquit_flag
-- and it didn't work.
Now, we simply enclose all code where we want C-g read as an event
with {begin/end}_dont_check_for_quit(). This completely turns off
the mechanism that checks (and may remove or alter) C-g in the
read-ahead queues, so we just get the C-g normal.
Signal.c documents this very carefully.
cmdloop.c: Correct use of dont_check_for_quit to new scheme, remove old
out-of-date comments.
event-stream.c: Fix C-g handling to actually work.
device-x.c: Disable quit checking when err out.
signal.c: Cleanup. Add large descriptive comment.
process-unix.c, process-nt.c, sysdep.c: Use QUIT instead of REALLY_QUIT.
It's not necessary to use REALLY_QUIT and just confuses the issue.
lisp.h: Comment quit handlers.
================================================================
CONS CHANGES
================================================================
free_cons() now takes a Lisp_Object not the result of XCONS().
car and cdr have been renamed so that they don't get used directly;
go through XCAR(), XCDR() instead.
alloc.c, dired.c, editfns.c, emodules.c, fns.c, glyphs-msw.c, glyphs-x.c, glyphs.c, keymap.c, minibuf.c, search.c, eval.c, lread.c, lisp.h: Correct free_cons calling convention: now takes Lisp_Object,
not Lisp_Cons
chartab.c: Eliminate direct use of ->car, ->cdr, should be black box.
callint.c: Rewrote using EXTERNAL_LIST_LOOP to avoid use of Lisp_Cons.
================================================================
USE INTERNAL-BIND-*
================================================================
eval.c: Cleanups of these funs.
alloc.c, fileio.c, undo.c, specifier.c, text.c, profile.c, lread.c, redisplay.c, menubar-x.c, macros.c: Rewrote to use internal_bind_int() and internal_bind_lisp_object()
in place of whatever varied and cumbersome mechanisms were
formerly there.
================================================================
SPECBIND SANITY
================================================================
backtrace.h: - Improved comments
backtrace.h, bytecode.c, eval.c: Add new mechanism check_specbind_stack_sanity() for sanity
checking code each time the catchlist or specbind stack change.
Removed older prototype of same mechanism.
================================================================
MISC
================================================================
lisp.h, insdel.c, window.c, device.c, console.c, buffer.c: Fleshed out authorship.
device-msw.c: Correct bad Unicode-ization.
print.c: Be more careful when not initialized or in fatal error handling.
search.c: Eliminate running_asynch_code, an FSF holdover.
alloc.c: Added comments about gc-cons-threshold.
dialog-x.c: Use begin_gc_forbidden() around code to build up a widget value
tree, like in menubar-x.c.
gui.c: Use Qunbound not Qnil as the default for
gethash.
lisp-disunion.h, lisp-union.h: Added warnings on use of VOID_TO_LISP().
lisp.h: Use ERROR_CHECK_STRUCTURES to turn on
ERROR_CHECK_TRAPPING_PROBLEMS and ERROR_CHECK_TYPECHECK
lisp.h: Add assert_with_message.
lisp.h: Add macros for gcproing entire arrays. (You could do this before
but it required manual twiddling the gcpro structure.)
lisp.h: Add prototypes for new functions defined elsewhere.
author | ben |
---|---|
date | Tue, 28 May 2002 08:45:36 +0000 |
parents | 047d37eb70d7 |
children | 1d8fb2eee1bb |
comparison
equal
deleted
inserted
replaced
852:d83885ef293b | 853:2b6fa2618f76 |
---|---|
26 /* This file has been split into process.c and process-unix.c by | 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 | 27 Kirill M. Katsnelson <kkm@kis.ru>, so please bash him and not |
28 the original author(s). | 28 the original author(s). |
29 | 29 |
30 Non-synch-subprocess stuff (mostly process environment) moved from | 30 Non-synch-subprocess stuff (mostly process environment) moved from |
31 callproc.c, 4-3-02, Ben Wing. */ | 31 callproc.c, 4-3-02, Ben Wing. |
32 | |
33 callproc.c deleted entirely 5-23-02, Ben Wing. Good riddance! | |
34 */ | |
32 | 35 |
33 #include <config.h> | 36 #include <config.h> |
34 | 37 |
35 #if defined (NO_SUBPROCESSES) | 38 #if defined (NO_SUBPROCESSES) |
36 #error "We don't support this anymore." | 39 #error "We don't support this anymore." |
99 static int update_tick; | 102 static int update_tick; |
100 | 103 |
101 /* Nonzero means delete a process right away if it exits. */ | 104 /* Nonzero means delete a process right away if it exits. */ |
102 int delete_exited_processes; | 105 int delete_exited_processes; |
103 | 106 |
104 /* Hash table which maps USIDs as returned by create_stream_pair_cb to | 107 /* Hash table which maps USIDs as returned by create_io_streams_cb to |
105 process objects. Processes are not GC-protected through this! */ | 108 process objects. Processes are not GC-protected through this! */ |
106 struct hash_table *usid_to_process; | 109 struct hash_table *usid_to_process; |
107 | 110 |
108 /* List of process objects. */ | 111 /* List of process objects. */ |
109 Lisp_Object Vprocess_list; | 112 Lisp_Object Vprocess_list; |
111 Lisp_Object Vnull_device; | 114 Lisp_Object Vnull_device; |
112 | 115 |
113 /* Cons of coding systems used to initialize process I/O on a newly- | 116 /* Cons of coding systems used to initialize process I/O on a newly- |
114 created process. */ | 117 created process. */ |
115 Lisp_Object Vdefault_process_coding_system; | 118 Lisp_Object Vdefault_process_coding_system; |
119 /* Same for a network connection. */ | |
120 Lisp_Object Vdefault_network_coding_system; | |
116 | 121 |
117 Lisp_Object Qprocess_error; | 122 Lisp_Object Qprocess_error; |
118 Lisp_Object Qnetwork_error; | 123 Lisp_Object Qnetwork_error; |
119 | 124 |
120 Fixnum debug_process_io; | 125 Fixnum debug_process_io; |
139 Lisp_Process *process = XPROCESS (object); | 144 Lisp_Process *process = XPROCESS (object); |
140 MAYBE_PROCMETH (mark_process_data, (process)); | 145 MAYBE_PROCMETH (mark_process_data, (process)); |
141 mark_object (process->name); | 146 mark_object (process->name); |
142 mark_object (process->command); | 147 mark_object (process->command); |
143 mark_object (process->filter); | 148 mark_object (process->filter); |
149 mark_object (process->stderr_filter); | |
144 mark_object (process->sentinel); | 150 mark_object (process->sentinel); |
145 mark_object (process->buffer); | 151 mark_object (process->buffer); |
146 mark_object (process->mark); | 152 mark_object (process->mark); |
153 mark_object (process->stderr_buffer); | |
154 mark_object (process->stderr_mark); | |
147 mark_object (process->pid); | 155 mark_object (process->pid); |
148 mark_object (process->pipe_instream); | 156 mark_object (process->pipe_instream); |
149 mark_object (process->pipe_outstream); | 157 mark_object (process->pipe_outstream); |
158 mark_object (process->pipe_errstream); | |
150 mark_object (process->coding_instream); | 159 mark_object (process->coding_instream); |
151 mark_object (process->coding_outstream); | 160 mark_object (process->coding_outstream); |
161 mark_object (process->coding_errstream); | |
152 return process->status_symbol; | 162 return process->status_symbol; |
153 } | 163 } |
154 | 164 |
155 static void | 165 static void |
156 print_process (Lisp_Object object, Lisp_Object printcharfun, int escapeflag) | 166 print_process (Lisp_Object object, Lisp_Object printcharfun, int escapeflag) |
213 /************************************************************************/ | 223 /************************************************************************/ |
214 | 224 |
215 /* This function returns low-level streams, connected directly to the child | 225 /* This function returns low-level streams, connected directly to the child |
216 process, rather than en/decoding streams */ | 226 process, rather than en/decoding streams */ |
217 void | 227 void |
218 get_process_streams (Lisp_Process *p, Lisp_Object *instr, Lisp_Object *outstr) | 228 get_process_streams (Lisp_Process *p, Lisp_Object *instr, Lisp_Object *outstr, |
229 Lisp_Object *errstr) | |
219 { | 230 { |
220 assert (p); | 231 assert (p); |
221 assert (NILP (p->pipe_instream) || LSTREAMP(p->pipe_instream)); | 232 assert (NILP (p->pipe_instream) || LSTREAMP (p->pipe_instream)); |
222 assert (NILP (p->pipe_outstream) || LSTREAMP(p->pipe_outstream)); | 233 assert (NILP (p->pipe_outstream) || LSTREAMP (p->pipe_outstream)); |
234 assert (NILP (p->pipe_errstream) || LSTREAMP (p->pipe_errstream)); | |
223 *instr = p->pipe_instream; | 235 *instr = p->pipe_instream; |
224 *outstr = p->pipe_outstream; | 236 *outstr = p->pipe_outstream; |
225 } | 237 *errstr = p->pipe_errstream; |
226 | 238 } |
239 | |
240 /* Given a USID referring to either a process's instream or errstream, | |
241 return the associated process. */ | |
227 Lisp_Process * | 242 Lisp_Process * |
228 get_process_from_usid (USID usid) | 243 get_process_from_usid (USID usid) |
229 { | 244 { |
230 const void *vval; | 245 const void *vval; |
231 | 246 |
240 else | 255 else |
241 return 0; | 256 return 0; |
242 } | 257 } |
243 | 258 |
244 int | 259 int |
245 get_process_selected_p (Lisp_Process *p) | 260 get_process_selected_p (Lisp_Process *p, int do_err) |
246 { | 261 { |
247 return p->selected; | 262 return do_err ? p->err_selected : p->in_selected; |
248 } | 263 } |
249 | 264 |
250 void | 265 void |
251 set_process_selected_p (Lisp_Process *p, int selected_p) | 266 set_process_selected_p (Lisp_Process *p, int in_selected, int err_selected) |
252 { | 267 { |
253 p->selected = !!selected_p; | 268 p->in_selected = !!in_selected; |
269 p->err_selected = !!err_selected; | |
254 } | 270 } |
255 | 271 |
256 int | 272 int |
257 connected_via_filedesc_p (Lisp_Process *p) | 273 connected_via_filedesc_p (Lisp_Process *p) |
258 { | 274 { |
464 name = name1; | 480 name = name1; |
465 p->name = name; | 481 p->name = name; |
466 | 482 |
467 p->command = Qnil; | 483 p->command = Qnil; |
468 p->filter = Qnil; | 484 p->filter = Qnil; |
485 p->stderr_filter = Qnil; | |
469 p->sentinel = Qnil; | 486 p->sentinel = Qnil; |
470 p->buffer = Qnil; | 487 p->buffer = Qnil; |
471 p->mark = Fmake_marker (); | 488 p->mark = Fmake_marker (); |
489 p->stderr_buffer = Qnil; | |
490 p->stderr_mark = Fmake_marker (); | |
472 p->pid = Qnil; | 491 p->pid = Qnil; |
473 p->status_symbol = Qrun; | 492 p->status_symbol = Qrun; |
474 p->exit_code = 0; | 493 p->exit_code = 0; |
475 p->core_dumped = 0; | 494 p->core_dumped = 0; |
476 p->filter_does_read = 0; | 495 p->filter_does_read = 0; |
477 p->kill_without_query = 0; | 496 p->kill_without_query = 0; |
478 p->selected = 0; | 497 p->separate_stderr = 0; |
498 p->in_selected = 0; | |
499 p->err_selected = 0; | |
479 p->tick = 0; | 500 p->tick = 0; |
480 p->update_tick = 0; | 501 p->update_tick = 0; |
481 p->pipe_instream = Qnil; | 502 p->pipe_instream = Qnil; |
482 p->pipe_outstream = Qnil; | 503 p->pipe_outstream = Qnil; |
504 p->pipe_errstream = Qnil; | |
483 p->coding_instream = Qnil; | 505 p->coding_instream = Qnil; |
484 p->coding_outstream = Qnil; | 506 p->coding_outstream = Qnil; |
507 p->coding_errstream = Qnil; | |
485 | 508 |
486 p->process_data = 0; | 509 p->process_data = 0; |
487 MAYBE_PROCMETH (alloc_process_data, (p)); | 510 MAYBE_PROCMETH (alloc_process_data, (p)); |
488 | 511 |
489 val = wrap_process (p); | 512 val = wrap_process (p); |
491 Vprocess_list = Fcons (val, Vprocess_list); | 514 Vprocess_list = Fcons (val, Vprocess_list); |
492 return val; | 515 return val; |
493 } | 516 } |
494 | 517 |
495 void | 518 void |
496 init_process_io_handles (Lisp_Process *p, void* in, void* out, int flags) | 519 init_process_io_handles (Lisp_Process *p, void* in, void* out, void* err, |
497 { | 520 int flags) |
498 USID usid; | 521 { |
522 USID in_usid, err_usid; | |
499 Lisp_Object incode, outcode; | 523 Lisp_Object incode, outcode; |
500 | 524 |
501 if (!CONSP (Vdefault_process_coding_system) || | 525 if (flags & STREAM_NETWORK_CONNECTION) |
502 NILP (incode = (find_coding_system_for_text_file | 526 { |
503 (Fcar (Vdefault_process_coding_system), 1))) || | 527 if (!CONSP (Vdefault_network_coding_system) || |
504 NILP (outcode = (find_coding_system_for_text_file | 528 NILP (incode = (find_coding_system_for_text_file |
505 (Fcdr (Vdefault_process_coding_system), 0)))) | 529 (Fcar (Vdefault_network_coding_system), 1))) || |
506 signal_error (Qinvalid_state, | 530 NILP (outcode = (find_coding_system_for_text_file |
507 "Bogus value for `default-process-coding-system'", | 531 (Fcdr (Vdefault_network_coding_system), 0)))) |
508 Vdefault_process_coding_system); | 532 signal_error (Qinvalid_state, |
533 "Bogus value for `default-network-coding-system'", | |
534 Vdefault_network_coding_system); | |
535 } | |
536 else | |
537 { | |
538 if (!CONSP (Vdefault_process_coding_system) || | |
539 NILP (incode = (find_coding_system_for_text_file | |
540 (Fcar (Vdefault_process_coding_system), 1))) || | |
541 NILP (outcode = (find_coding_system_for_text_file | |
542 (Fcdr (Vdefault_process_coding_system), 0)))) | |
543 signal_error (Qinvalid_state, | |
544 "Bogus value for `default-process-coding-system'", | |
545 Vdefault_process_coding_system); | |
546 } | |
509 | 547 |
510 if (!NILP (Vcoding_system_for_read) && | 548 if (!NILP (Vcoding_system_for_read) && |
511 NILP (incode = (find_coding_system_for_text_file | 549 NILP (incode = (find_coding_system_for_text_file |
512 (Vcoding_system_for_read, 1)))) | 550 (Vcoding_system_for_read, 1)))) |
513 signal_error (Qinvalid_state, | 551 signal_error (Qinvalid_state, |
519 (Vcoding_system_for_write, 0)))) | 557 (Vcoding_system_for_write, 0)))) |
520 signal_error (Qinvalid_state, | 558 signal_error (Qinvalid_state, |
521 "Bogus value for `coding-system-for-write'", | 559 "Bogus value for `coding-system-for-write'", |
522 Vcoding_system_for_write); | 560 Vcoding_system_for_write); |
523 | 561 |
524 usid = event_stream_create_stream_pair (in, out, | 562 event_stream_create_io_streams (in, out, err, |
525 &p->pipe_instream, | 563 &p->pipe_instream, |
526 &p->pipe_outstream, | 564 &p->pipe_outstream, |
527 flags); | 565 &p->pipe_errstream, |
528 | 566 &in_usid, &err_usid, |
529 if (usid == USID_ERROR) | 567 flags); |
568 | |
569 if (in_usid == USID_ERROR || err_usid == USID_ERROR) | |
530 signal_error (Qprocess_error, "Setting up communication with subprocess", | 570 signal_error (Qprocess_error, "Setting up communication with subprocess", |
531 Qunbound); | 571 wrap_process (p)); |
532 | 572 |
533 if (usid != USID_DONTHASH) | 573 if (in_usid != USID_DONTHASH) |
534 { | 574 { |
535 Lisp_Object process = Qnil; | 575 Lisp_Object process = Qnil; |
536 process = wrap_process (p); | 576 process = wrap_process (p); |
537 puthash ((const void *) usid, LISP_TO_VOID (process), usid_to_process); | 577 puthash ((const void*) in_usid, LISP_TO_VOID (process), usid_to_process); |
538 } | 578 } |
539 | 579 |
540 MAYBE_PROCMETH (init_process_io_handles, (p, in, out, flags)); | 580 if (err_usid != USID_DONTHASH) |
581 { | |
582 Lisp_Object process = Qnil; | |
583 process = wrap_process (p); | |
584 puthash ((const void*) err_usid, LISP_TO_VOID (process), | |
585 usid_to_process); | |
586 } | |
587 | |
588 MAYBE_PROCMETH (init_process_io_handles, (p, in, out, err, flags)); | |
541 | 589 |
542 p->coding_instream = | 590 p->coding_instream = |
543 make_coding_input_stream (XLSTREAM (p->pipe_instream), incode, | 591 make_coding_input_stream (XLSTREAM (p->pipe_instream), incode, |
544 CODING_DECODE, 0); | 592 CODING_DECODE, 0); |
593 if (!NILP (p->pipe_errstream)) | |
594 p->coding_errstream = | |
595 make_coding_input_stream | |
596 (XLSTREAM (p->pipe_errstream), incode, CODING_DECODE, 0); | |
545 p->coding_outstream = | 597 p->coding_outstream = |
546 make_coding_output_stream (XLSTREAM (p->pipe_outstream), outcode, | 598 make_coding_output_stream (XLSTREAM (p->pipe_outstream), outcode, |
547 CODING_ENCODE, 0); | 599 CODING_ENCODE, 0); |
548 } | 600 } |
549 | 601 |
550 static void | 602 static void |
551 create_process (Lisp_Object process, Lisp_Object *argv, int nargv, | 603 create_process (Lisp_Object process, Lisp_Object *argv, int nargv, |
552 Lisp_Object program, Lisp_Object cur_dir) | 604 Lisp_Object program, Lisp_Object cur_dir, |
605 int separate_err) | |
553 { | 606 { |
554 Lisp_Process *p = XPROCESS (process); | 607 Lisp_Process *p = XPROCESS (process); |
555 int pid; | 608 int pid; |
556 | 609 |
557 /* *_create_process may change status_symbol, if the process | 610 /* *_create_process may change status_symbol, if the process |
558 is a kind of "fire-and-forget" (no I/O, unwaitable) */ | 611 is a kind of "fire-and-forget" (no I/O, unwaitable) */ |
559 p->status_symbol = Qrun; | 612 p->status_symbol = Qrun; |
560 p->exit_code = 0; | 613 p->exit_code = 0; |
561 | 614 |
562 pid = PROCMETH (create_process, (p, argv, nargv, program, cur_dir)); | 615 pid = PROCMETH (create_process, (p, argv, nargv, program, cur_dir, |
616 separate_err)); | |
563 | 617 |
564 p->pid = make_int (pid); | 618 p->pid = make_int (pid); |
565 if (PROCESS_LIVE_P (p)) | 619 if (PROCESS_LIVE_P (p)) |
566 event_stream_select_process (p); | 620 event_stream_select_process (p, 1, 1); |
567 } | 621 } |
568 | 622 |
569 /* This function is the unwind_protect form for Fstart_process_internal. If | 623 /* This function is the unwind_protect form for Fstart_process_internal. If |
570 PROCESS doesn't have its pid set, then we know someone has signalled | 624 PROCESS doesn't have its pid set, then we know someone has signalled |
571 an error and the process wasn't started successfully, so we should | 625 an error and the process wasn't started successfully, so we should |
579 remove_process (process); | 633 remove_process (process); |
580 return Qnil; | 634 return Qnil; |
581 } | 635 } |
582 | 636 |
583 DEFUN ("start-process-internal", Fstart_process_internal, 3, MANY, 0, /* | 637 DEFUN ("start-process-internal", Fstart_process_internal, 3, MANY, 0, /* |
584 Start a program in a subprocess. Return the process object for it. | 638 Internal function to start a program in a subprocess. |
639 Lisp callers should use `start-process' instead. | |
640 | |
641 Returns the process object for it. | |
585 Args are NAME BUFFER PROGRAM &rest PROGRAM-ARGS | 642 Args are NAME BUFFER PROGRAM &rest PROGRAM-ARGS |
586 NAME is name for process. It is modified if necessary to make it unique. | 643 NAME is name for process. It is modified if necessary to make it unique. |
587 BUFFER is the buffer or (buffer-name) to associate with the process. | 644 BUFFER is the buffer or (buffer-name) to associate with the process. |
588 Process output goes at end of that buffer, unless you specify | 645 Process output goes at end of that buffer, unless you specify |
589 an output stream or filter function to handle the output. | 646 an output stream or filter function to handle the output. |
590 BUFFER may be also nil, meaning that this process is not associated | 647 BUFFER may be also nil, meaning that this process is not associated |
591 with any buffer | 648 with any buffer. |
649 BUFFER can also have the form (REAL-BUFFER STDERR-BUFFER); in that case, | |
650 REAL-BUFFER says what to do with standard output, as above, | |
651 while STDERR-BUFFER says what to do with standard error in the child. | |
652 STDERR-BUFFER may be nil (discard standard error output, unless a stderr | |
653 filter is set). Note that if you do not use this form at process creation, | |
654 stdout and stderr will be mixed in the output buffer, and this cannot be | |
655 changed, even by setting a stderr filter. | |
592 Third arg is program file name. It is searched for as in the shell. | 656 Third arg is program file name. It is searched for as in the shell. |
593 Remaining arguments are strings to give program as arguments. | 657 Remaining arguments are strings to give program as arguments. |
594 INCODE and OUTCODE specify the coding-system objects used in input/output | 658 |
595 from/to the process. | 659 Read and write coding systems for the process are determined from |
660 `coding-system-for-read' and `coding-system-for-write' (intended as | |
661 overriding coding systems to be *bound* by Lisp code, not set), or | |
662 from `default-process-coding-system' if either or both are nil. You can | |
663 change the coding systems later on using `set-process-coding-system', | |
664 `set-process-input-coding-system', or `set-process-output-coding-system'. | |
665 | |
666 See also `set-process-filter' and `set-process-stderr-filter'. | |
596 */ | 667 */ |
597 (int nargs, Lisp_Object *args)) | 668 (int nargs, Lisp_Object *args)) |
598 { | 669 { |
599 /* This function can call lisp */ | 670 /* This function can call lisp */ |
600 Lisp_Object buffer, name, program, process, current_dir; | 671 Lisp_Object buffer, stderr_buffer, name, program, process, current_dir; |
672 int separate_stderr; | |
601 Lisp_Object tem; | 673 Lisp_Object tem; |
602 int speccount = specpdl_depth (); | 674 int speccount = specpdl_depth (); |
603 struct gcpro gcpro1, gcpro2, gcpro3; | 675 struct gcpro gcpro1, gcpro2, gcpro3; |
604 | 676 |
605 name = args[0]; | 677 name = args[0]; |
608 current_dir = Qnil; | 680 current_dir = Qnil; |
609 | 681 |
610 /* Protect against various file handlers doing GCs below. */ | 682 /* Protect against various file handlers doing GCs below. */ |
611 GCPRO3 (buffer, program, current_dir); | 683 GCPRO3 (buffer, program, current_dir); |
612 | 684 |
685 if (CONSP (buffer)) | |
686 { | |
687 if (!CONSP (XCDR (buffer))) | |
688 invalid_argument ("Invalid BUFFER argument to `start-process'", | |
689 buffer); | |
690 if (!NILP (XCDR (XCDR (buffer)))) | |
691 invalid_argument ("Invalid BUFFER argument to `start-process'", | |
692 buffer); | |
693 stderr_buffer = XCAR (XCDR (buffer)); | |
694 buffer = XCAR (buffer); | |
695 separate_stderr = 1; | |
696 } | |
697 else | |
698 { | |
699 stderr_buffer = Qnil; | |
700 separate_stderr = 0; | |
701 } | |
702 | |
613 if (!NILP (buffer)) | 703 if (!NILP (buffer)) |
614 buffer = Fget_buffer_create (buffer); | 704 buffer = Fget_buffer_create (buffer); |
705 if (!NILP (stderr_buffer)) | |
706 stderr_buffer = Fget_buffer_create (stderr_buffer); | |
615 | 707 |
616 CHECK_STRING (name); | 708 CHECK_STRING (name); |
617 CHECK_STRING (program); | 709 CHECK_STRING (program); |
618 | 710 |
619 /* Make sure that the child will be able to chdir to the current | 711 /* Make sure that the child will be able to chdir to the current |
676 program); | 768 program); |
677 | 769 |
678 process = make_process_internal (name); | 770 process = make_process_internal (name); |
679 | 771 |
680 XPROCESS (process)->buffer = buffer; | 772 XPROCESS (process)->buffer = buffer; |
773 XPROCESS (process)->stderr_buffer = stderr_buffer; | |
774 XPROCESS (process)->separate_stderr = separate_stderr; | |
681 XPROCESS (process)->command = Flist (nargs - 2, args + 2); | 775 XPROCESS (process)->command = Flist (nargs - 2, args + 2); |
682 | 776 |
683 /* Make the process marker point into the process buffer (if any). */ | 777 /* Make the process marker point into the process buffer (if any). */ |
684 if (!NILP (buffer)) | 778 if (!NILP (buffer)) |
685 Fset_marker (XPROCESS (process)->mark, | 779 Fset_marker (XPROCESS (process)->mark, |
686 make_int (BUF_ZV (XBUFFER (buffer))), buffer); | 780 make_int (BUF_ZV (XBUFFER (buffer))), buffer); |
781 if (!NILP (stderr_buffer)) | |
782 Fset_marker (XPROCESS (process)->stderr_mark, | |
783 make_int (BUF_ZV (XBUFFER (stderr_buffer))), stderr_buffer); | |
687 | 784 |
688 /* If an error occurs and we can't start the process, we want to | 785 /* If an error occurs and we can't start the process, we want to |
689 remove it from the process list. This means that each error | 786 remove it from the process list. This means that each error |
690 check in create_process doesn't need to call remove_process | 787 check in create_process doesn't need to call remove_process |
691 itself; it's all taken care of here. */ | 788 itself; it's all taken care of here. */ |
692 record_unwind_protect (start_process_unwind, process); | 789 record_unwind_protect (start_process_unwind, process); |
693 | 790 |
694 create_process (process, args + 3, nargs - 3, program, current_dir); | 791 create_process (process, args + 3, nargs - 3, program, current_dir, |
792 separate_stderr); | |
695 | 793 |
696 UNGCPRO; | 794 UNGCPRO; |
697 return unbind_to_1 (speccount, process); | 795 return unbind_to_1 (speccount, process); |
698 } | 796 } |
699 | 797 |
779 NGCPRO1 (process); | 877 NGCPRO1 (process); |
780 | 878 |
781 XPROCESS (process)->pid = Fcons (service, host); | 879 XPROCESS (process)->pid = Fcons (service, host); |
782 XPROCESS (process)->buffer = buffer; | 880 XPROCESS (process)->buffer = buffer; |
783 init_process_io_handles (XPROCESS (process), (void *) inch, (void *) outch, | 881 init_process_io_handles (XPROCESS (process), (void *) inch, (void *) outch, |
882 (void *) -1, | |
784 STREAM_NETWORK_CONNECTION); | 883 STREAM_NETWORK_CONNECTION); |
785 | 884 |
786 event_stream_select_process (XPROCESS (process)); | 885 event_stream_select_process (XPROCESS (process), 1, 1); |
787 | 886 |
788 UNGCPRO; | 887 UNGCPRO; |
789 NUNGCPRO; | 888 NUNGCPRO; |
790 return process; | 889 return process; |
791 } | 890 } |
828 process = make_process_internal (name); | 927 process = make_process_internal (name); |
829 GCPRO1 (process); | 928 GCPRO1 (process); |
830 | 929 |
831 XPROCESS (process)->pid = Fcons (port, dest); | 930 XPROCESS (process)->pid = Fcons (port, dest); |
832 XPROCESS (process)->buffer = buffer; | 931 XPROCESS (process)->buffer = buffer; |
833 init_process_io_handles (XPROCESS (process), (void*)inch, (void*)outch, | 932 init_process_io_handles (XPROCESS (process), (void *) inch, (void *) outch, |
933 (void *) -1, | |
834 STREAM_NETWORK_CONNECTION); | 934 STREAM_NETWORK_CONNECTION); |
835 | 935 |
836 event_stream_select_process (XPROCESS (process)); | 936 event_stream_select_process (XPROCESS (process), 1, 1); |
837 | 937 |
838 UNGCPRO; | 938 UNGCPRO; |
839 return process; | 939 return process; |
840 } | 940 } |
841 #endif /* HAVE_MULTICAST */ | 941 #endif /* HAVE_MULTICAST */ |
874 Sets the current buffer to PROCESS's buffer, inhibits read only, | 974 Sets the current buffer to PROCESS's buffer, inhibits read only, |
875 remembers current point, sets point to PROCESS'S mark, widens if | 975 remembers current point, sets point to PROCESS'S mark, widens if |
876 necessary. | 976 necessary. |
877 */ | 977 */ |
878 static int | 978 static int |
879 process_setup_for_insertion (Lisp_Object process) | 979 process_setup_for_insertion (Lisp_Object process, int read_stderr) |
880 { | 980 { |
881 Lisp_Process *p = XPROCESS (process); | 981 Lisp_Process *p = XPROCESS (process); |
882 int spec = specpdl_depth (); | 982 int spec = specpdl_depth (); |
883 struct buffer *buf = XBUFFER (p->buffer); | 983 Lisp_Object buffer = read_stderr ? p->stderr_buffer : p->buffer; |
984 Lisp_Object mark = read_stderr ? p->stderr_mark : p->mark; | |
985 struct buffer *buf = XBUFFER (buffer); | |
884 Charbpos output_pt; | 986 Charbpos output_pt; |
885 | 987 |
886 if (buf != current_buffer) | 988 if (buf != current_buffer) |
887 { | 989 { |
888 record_unwind_protect (save_current_buffer_restore, | 990 record_unwind_protect (save_current_buffer_restore, |
894 specbind (Qinhibit_read_only, Qt); | 996 specbind (Qinhibit_read_only, Qt); |
895 | 997 |
896 /* Insert new output into buffer | 998 /* Insert new output into buffer |
897 at the current end-of-output marker, | 999 at the current end-of-output marker, |
898 thus preserving logical ordering of input and output. */ | 1000 thus preserving logical ordering of input and output. */ |
899 if (XMARKER (p->mark)->buffer) | 1001 if (XMARKER (mark)->buffer) |
900 output_pt = marker_position (p->mark); | 1002 output_pt = marker_position (mark); |
901 else | 1003 else |
902 output_pt = BUF_ZV (buf); | 1004 output_pt = BUF_ZV (buf); |
903 | 1005 |
904 /* If the output marker is outside of the visible region, save | 1006 /* If the output marker is outside of the visible region, save |
905 the restriction and widen. */ | 1007 the restriction and widen. */ |
921 This function reads at most 1024 bytes. | 1023 This function reads at most 1024 bytes. |
922 If you want to read all available subprocess output, | 1024 If you want to read all available subprocess output, |
923 you must call it repeatedly until it returns zero. */ | 1025 you must call it repeatedly until it returns zero. */ |
924 | 1026 |
925 Charcount | 1027 Charcount |
926 read_process_output (Lisp_Object process) | 1028 read_process_output (Lisp_Object process, int read_stderr) |
927 { | 1029 { |
928 /* This function can GC */ | 1030 /* This function can GC */ |
929 Bytecount nbytes, nchars; | 1031 Bytecount nbytes, nchars; |
930 Intbyte chars[1025]; | 1032 Intbyte chars[1025]; |
931 Lisp_Object outstream; | 1033 Lisp_Object outstream; |
932 Lisp_Process *p = XPROCESS (process); | 1034 Lisp_Process *p = XPROCESS (process); |
1035 Lisp_Object filter = read_stderr ? p->stderr_filter : p->filter; | |
1036 Lisp_Object buffer = read_stderr ? p->stderr_buffer : p->buffer; | |
1037 Lisp_Object mark = read_stderr ? p->stderr_mark : p->mark; | |
933 | 1038 |
934 /* If there is a lot of output from the subprocess, the loop in | 1039 /* If there is a lot of output from the subprocess, the loop in |
935 execute_internal_event() might call read_process_output() more | 1040 execute_internal_event() might call read_process_output() more |
936 than once. If the filter that was executed from one of these | 1041 than once. If the filter that was executed from one of these |
937 calls set the filter to t, we have to stop now. Return -1 rather | 1042 calls set the filter to t, we have to stop now. Return -1 rather |
938 than 0 so execute_internal_event() doesn't close the process. | 1043 than 0 so execute_internal_event() doesn't close the process. |
939 Really, the loop in execute_internal_event() should check itself | 1044 Really, the loop in execute_internal_event() should check itself |
940 for a process-filter change, like in status_notify(); but the | 1045 for a process-filter change, like in status_notify(); but the |
941 struct Lisp_Process is not exported outside of this file. */ | 1046 struct Lisp_Process is not exported outside of this file. */ |
942 if (!PROCESS_LIVE_P (p)) | 1047 if (!PROCESS_LIVE_P (p)) |
943 return -1; /* already closed */ | 1048 { |
944 | 1049 errno = 0; |
945 if (!NILP (p->filter) && (p->filter_does_read)) | 1050 return -1; /* already closed */ |
1051 } | |
1052 | |
1053 if (!NILP (filter) && (p->filter_does_read)) | |
946 { | 1054 { |
947 Lisp_Object filter_result; | 1055 Lisp_Object filter_result; |
948 | 1056 |
949 /* Some weird FSFmacs crap here with | 1057 /* Some weird FSFmacs crap here with |
950 Vdeactivate_mark and current_buffer->keymap */ | 1058 Vdeactivate_mark and current_buffer->keymap. |
951 running_asynch_code = 1; | 1059 Some FSF junk with running_asynch_code, to preserve the match |
952 filter_result = call2_trapping_errors ("Error in process filter", | 1060 data. Not necessary because we don't call process filters |
953 p->filter, process, Qnil); | 1061 asynchronously (i.e. from within QUIT). */ |
954 running_asynch_code = 0; | 1062 /* Don't catch errors here; we're not in any critical code. */ |
955 restore_match_data (); | 1063 filter_result = call2 (filter, process, Qnil); |
956 CHECK_INT (filter_result); | 1064 CHECK_INT (filter_result); |
957 return XINT (filter_result); | 1065 return XINT (filter_result); |
958 } | 1066 } |
959 | 1067 |
960 nbytes = Lstream_read (XLSTREAM (DATA_INSTREAM (p)), chars, | 1068 nbytes = Lstream_read (read_stderr ? XLSTREAM (DATA_ERRSTREAM (p)) : |
1069 XLSTREAM (DATA_INSTREAM (p)), chars, | |
961 sizeof (chars) - 1); | 1070 sizeof (chars) - 1); |
962 if (nbytes <= 0) return nbytes; | 1071 if (nbytes <= 0) return nbytes; |
963 | 1072 |
964 if (debug_process_io) | 1073 if (debug_process_io) |
965 { | 1074 { |
968 } | 1077 } |
969 | 1078 |
970 /* !!#### if the coding system changed as a result of reading, we | 1079 /* !!#### if the coding system changed as a result of reading, we |
971 need to change the output coding system accordingly. */ | 1080 need to change the output coding system accordingly. */ |
972 nchars = bytecount_to_charcount (chars, nbytes); | 1081 nchars = bytecount_to_charcount (chars, nbytes); |
973 outstream = p->filter; | 1082 outstream = filter; |
974 if (!NILP (outstream)) | 1083 if (!NILP (outstream)) |
975 { | 1084 { |
976 /* We used to bind inhibit-quit to t here, but | 1085 /* Some FSF junk with running_asynch_code, to preserve the match |
977 call2_trapping_errors() does that for us. */ | 1086 data. Not necessary because we don't call process filters |
978 running_asynch_code = 1; | 1087 asynchronously (i.e. from within QUIT). */ |
979 call2_trapping_errors ("Error in process filter", | 1088 /* Don't catch errors here; we're not in any critical code. */ |
980 outstream, process, make_string (chars, nbytes)); | 1089 call2 (outstream, process, make_string (chars, nbytes)); |
981 running_asynch_code = 0; | |
982 restore_match_data (); | |
983 return nchars; | 1090 return nchars; |
984 } | 1091 } |
985 | 1092 |
986 /* If no filter, write into buffer if it isn't dead. */ | 1093 /* If no filter, write into buffer if it isn't dead. */ |
987 if (!NILP (p->buffer) && BUFFER_LIVE_P (XBUFFER (p->buffer))) | 1094 if (!NILP (buffer) && BUFFER_LIVE_P (XBUFFER (buffer))) |
988 { | 1095 { |
989 struct gcpro gcpro1; | 1096 struct gcpro gcpro1; |
990 struct buffer *buf = XBUFFER (p->buffer); | 1097 struct buffer *buf = XBUFFER (buffer); |
991 int spec = process_setup_for_insertion (process); | 1098 int spec = process_setup_for_insertion (process, read_stderr); |
992 | 1099 |
993 GCPRO1 (process); | 1100 GCPRO1 (process); |
994 | 1101 |
995 #if 0 | 1102 #if 0 |
996 /* This screws up initial display of the window. jla */ | 1103 /* This screws up initial display of the window. jla */ |
1001 nbytes, INSDEL_BEFORE_MARKERS); | 1108 nbytes, INSDEL_BEFORE_MARKERS); |
1002 #else | 1109 #else |
1003 buffer_insert_raw_string (buf, chars, nbytes); | 1110 buffer_insert_raw_string (buf, chars, nbytes); |
1004 #endif | 1111 #endif |
1005 | 1112 |
1006 Fset_marker (p->mark, make_int (BUF_PT (buf)), p->buffer); | 1113 Fset_marker (mark, make_int (BUF_PT (buf)), buffer); |
1114 | |
1007 MARK_MODELINE_CHANGED; | 1115 MARK_MODELINE_CHANGED; |
1008 unbind_to (spec); | 1116 unbind_to (spec); |
1009 UNGCPRO; | 1117 UNGCPRO; |
1010 } | 1118 } |
1011 return nchars; | 1119 return nchars; |
1012 } | 1120 } |
1121 | |
1122 int | |
1123 process_has_separate_stderr (Lisp_Object process) | |
1124 { | |
1125 return XPROCESS (process)->separate_stderr; | |
1126 } | |
1127 | |
1013 | 1128 |
1014 /* Sending data to subprocess */ | 1129 /* Sending data to subprocess */ |
1015 | 1130 |
1016 /* send some data to process PROCESS. If NONRELOCATABLE is non-NULL, it | 1131 /* send some data to process PROCESS. If NONRELOCATABLE is non-NULL, it |
1017 specifies the address of the data. Otherwise, the data comes from the | 1132 specifies the address of the data. Otherwise, the data comes from the |
1093 { | 1208 { |
1094 CHECK_PROCESS (process); | 1209 CHECK_PROCESS (process); |
1095 return XPROCESS (process)->buffer; | 1210 return XPROCESS (process)->buffer; |
1096 } | 1211 } |
1097 | 1212 |
1213 DEFUN ("set-process-stderr-buffer", Fset_process_stderr_buffer, 2, 2, 0, /* | |
1214 Set stderr buffer associated with PROCESS to BUFFER (a buffer, or nil). | |
1215 */ | |
1216 (process, buffer)) | |
1217 { | |
1218 CHECK_PROCESS (process); | |
1219 if (!XPROCESS (process)->separate_stderr) | |
1220 invalid_change ("stdout and stderr not separate", process); | |
1221 if (!NILP (buffer)) | |
1222 CHECK_BUFFER (buffer); | |
1223 XPROCESS (process)->stderr_buffer = buffer; | |
1224 return buffer; | |
1225 } | |
1226 | |
1227 DEFUN ("process-stderr-buffer", Fprocess_stderr_buffer, 1, 1, 0, /* | |
1228 Return the stderr buffer PROCESS is associated with. | |
1229 Output from the stderr of PROCESS is inserted in this buffer | |
1230 unless PROCESS has a stderr filter. | |
1231 */ | |
1232 (process)) | |
1233 { | |
1234 CHECK_PROCESS (process); | |
1235 if (!XPROCESS (process)->separate_stderr) | |
1236 invalid_change ("stdout and stderr not separate", process); | |
1237 return XPROCESS (process)->stderr_buffer; | |
1238 } | |
1239 | |
1098 DEFUN ("process-mark", Fprocess_mark, 1, 1, 0, /* | 1240 DEFUN ("process-mark", Fprocess_mark, 1, 1, 0, /* |
1099 Return the marker for the end of the last output from PROCESS. | 1241 Return the marker for the end of the last output from PROCESS. |
1100 */ | 1242 */ |
1101 (process)) | 1243 (process)) |
1102 { | 1244 { |
1103 CHECK_PROCESS (process); | 1245 CHECK_PROCESS (process); |
1104 return XPROCESS (process)->mark; | 1246 return XPROCESS (process)->mark; |
1105 } | 1247 } |
1106 | 1248 |
1249 DEFUN ("process-stderr-mark", Fprocess_stderr_mark, 1, 1, 0, /* | |
1250 Return the marker for the end of the last stderr output from PROCESS. | |
1251 */ | |
1252 (process)) | |
1253 { | |
1254 CHECK_PROCESS (process); | |
1255 if (!XPROCESS (process)->separate_stderr) | |
1256 invalid_operation ("stdout and stderr not separate", process); | |
1257 return XPROCESS (process)->stderr_mark; | |
1258 } | |
1259 | |
1107 void | 1260 void |
1108 set_process_filter (Lisp_Object process, Lisp_Object filter, int filter_does_read) | 1261 set_process_filter (Lisp_Object process, Lisp_Object filter, |
1262 int filter_does_read, int set_stderr) | |
1109 { | 1263 { |
1110 CHECK_PROCESS (process); | 1264 CHECK_PROCESS (process); |
1111 if (PROCESS_LIVE_P (XPROCESS (process))) { | 1265 if (set_stderr && !XPROCESS (process)->separate_stderr) |
1112 if (EQ (filter, Qt)) | 1266 invalid_change ("stdout and stderr not separate", process); |
1113 event_stream_unselect_process (XPROCESS (process)); | 1267 if (PROCESS_LIVE_P (XPROCESS (process))) |
1114 else | 1268 { |
1115 event_stream_select_process (XPROCESS (process)); | 1269 if (EQ (filter, Qt)) |
1116 } | 1270 event_stream_unselect_process (XPROCESS (process), !set_stderr, |
1117 | 1271 set_stderr); |
1118 XPROCESS (process)->filter = filter; | 1272 else |
1273 event_stream_select_process (XPROCESS (process), !set_stderr, | |
1274 set_stderr); | |
1275 } | |
1276 | |
1277 if (set_stderr) | |
1278 XPROCESS (process)->stderr_filter = filter; | |
1279 else | |
1280 XPROCESS (process)->filter = filter; | |
1119 XPROCESS (process)->filter_does_read = filter_does_read; | 1281 XPROCESS (process)->filter_does_read = filter_does_read; |
1120 } | 1282 } |
1121 | 1283 |
1122 DEFUN ("set-process-filter", Fset_process_filter, 2, 2, 0, /* | 1284 DEFUN ("set-process-filter", Fset_process_filter, 2, 2, 0, /* |
1123 Give PROCESS the filter function FILTER; nil means no filter. | 1285 Give PROCESS the filter function FILTER; nil means no filter. |
1286 t means stop accepting output from the process. (If process was created | |
1287 with | |
1288 When a process has a filter, each time it does output | |
1289 the entire string of output is passed to the filter. | |
1290 The filter gets two arguments: the process and the string of output. | |
1291 If the process has a filter, its buffer is not used for output. | |
1292 */ | |
1293 (process, filter)) | |
1294 { | |
1295 set_process_filter (process, filter, 0, 0); | |
1296 return filter; | |
1297 } | |
1298 | |
1299 DEFUN ("set-process-stderr-filter", Fset_process_stderr_filter, 2, 2, 0, /* | |
1300 Give PROCESS the stderr filter function FILTER; nil means no filter. | |
1124 t means stop accepting output from the process. | 1301 t means stop accepting output from the process. |
1125 When a process has a filter, each time it does output | 1302 When a process has a filter, each time it does output |
1126 the entire string of output is passed to the filter. | 1303 the entire string of output is passed to the filter. |
1127 The filter gets two arguments: the process and the string of output. | 1304 The filter gets two arguments: the process and the string of output. |
1128 If the process has a filter, its buffer is not used for output. | 1305 If the process has a filter, its buffer is not used for output. |
1129 */ | 1306 */ |
1130 (process, filter)) | 1307 (process, filter)) |
1131 { | 1308 { |
1132 set_process_filter (process, filter, 0); | 1309 set_process_filter (process, filter, 0, 1); |
1133 return filter; | 1310 return filter; |
1134 } | 1311 } |
1135 | 1312 |
1136 DEFUN ("process-filter", Fprocess_filter, 1, 1, 0, /* | 1313 DEFUN ("process-filter", Fprocess_filter, 1, 1, 0, /* |
1137 Return the filter function of PROCESS; nil if none. | 1314 Return the filter function of PROCESS; nil if none. |
1139 */ | 1316 */ |
1140 (process)) | 1317 (process)) |
1141 { | 1318 { |
1142 CHECK_PROCESS (process); | 1319 CHECK_PROCESS (process); |
1143 return XPROCESS (process)->filter; | 1320 return XPROCESS (process)->filter; |
1321 } | |
1322 | |
1323 DEFUN ("process-stderr-filter", Fprocess_stderr_filter, 1, 1, 0, /* | |
1324 Return the filter function of PROCESS; nil if none. | |
1325 See `set-process-stderr-filter' for more info on filter functions. | |
1326 */ | |
1327 (process)) | |
1328 { | |
1329 CHECK_PROCESS (process); | |
1330 if (!XPROCESS (process)->separate_stderr) | |
1331 invalid_operation ("stdout and stderr not separate", process); | |
1332 return XPROCESS (process)->stderr_filter; | |
1144 } | 1333 } |
1145 | 1334 |
1146 DEFUN ("process-send-region", Fprocess_send_region, 3, 4, 0, /* | 1335 DEFUN ("process-send-region", Fprocess_send_region, 3, 4, 0, /* |
1147 Send current contents of the region between START and END as input to PROCESS. | 1336 Send current contents of the region between START and END as input to PROCESS. |
1148 PROCESS may be a process or the name of a process, or a buffer or the | 1337 PROCESS may be a process or the name of a process, or a buffer or the |
1149 name of a buffer, in which case the buffer's process is used. If it | 1338 name of a buffer, in which case the buffer's process is used. If it |
1150 is nil, the current buffer's process is used. | 1339 is nil, the current buffer's process is used. |
1151 BUFFER specifies the buffer to look in; if nil, the current buffer is used. | 1340 BUFFER specifies the buffer to look in; if nil, the current buffer is used. |
1152 If STRING is more than 100 or so characters long, it may be sent in | 1341 If the region is more than 100 or so characters long, it may be sent in |
1153 several chunks. This may happen even for shorter strings. Output | 1342 several chunks. This may happen even for shorter regions. Output |
1154 from processes can arrive in between chunks. | 1343 from processes can arrive in between chunks. |
1155 */ | 1344 */ |
1156 (process, start, end, buffer)) | 1345 (process, start, end, buffer)) |
1157 { | 1346 { |
1158 /* This function can GC */ | 1347 /* This function can GC */ |
1282 /************************************************************************/ | 1471 /************************************************************************/ |
1283 | 1472 |
1284 static Lisp_Object | 1473 static Lisp_Object |
1285 exec_sentinel_unwind (Lisp_Object datum) | 1474 exec_sentinel_unwind (Lisp_Object datum) |
1286 { | 1475 { |
1287 Lisp_Cons *d = XCONS (datum); | 1476 XPROCESS (XCAR (datum))->sentinel = XCDR (datum); |
1288 XPROCESS (d->car)->sentinel = d->cdr; | 1477 free_cons (datum); |
1289 free_cons (d); | |
1290 return Qnil; | 1478 return Qnil; |
1291 } | 1479 } |
1292 | 1480 |
1293 static void | 1481 static void |
1294 exec_sentinel (Lisp_Object process, Lisp_Object reason) | 1482 exec_sentinel (Lisp_Object process, Lisp_Object reason) |
1302 return; | 1490 return; |
1303 | 1491 |
1304 /* Some weird FSFmacs crap here with | 1492 /* Some weird FSFmacs crap here with |
1305 Vdeactivate_mark and current_buffer->keymap */ | 1493 Vdeactivate_mark and current_buffer->keymap */ |
1306 | 1494 |
1495 /* Some FSF junk with running_asynch_code, to preserve the match | |
1496 data. Not necessary because we don't call process filters | |
1497 asynchronously (i.e. from within QUIT). */ | |
1498 | |
1307 /* Zilch the sentinel while it's running, to avoid recursive invocations; | 1499 /* Zilch the sentinel while it's running, to avoid recursive invocations; |
1308 assure that it gets restored no matter how the sentinel exits. */ | 1500 assure that it gets restored no matter how the sentinel exits. |
1501 | |
1502 (#### Why is this necessary? Probably another relic of asynchronous | |
1503 calling of process filters/sentinels.) */ | |
1309 p->sentinel = Qnil; | 1504 p->sentinel = Qnil; |
1310 record_unwind_protect (exec_sentinel_unwind, noseeum_cons (process, sentinel)); | 1505 record_unwind_protect (exec_sentinel_unwind, |
1311 /* We used to bind inhibit-quit to t here, but call2_trapping_errors() | 1506 noseeum_cons (process, sentinel)); |
1312 does that for us. */ | 1507 /* Don't catch errors here; we're not in any critical code. */ |
1313 running_asynch_code = 1; | 1508 call2 (sentinel, process, reason); |
1314 call2_trapping_errors ("Error in process sentinel", sentinel, process, reason); | |
1315 running_asynch_code = 0; | |
1316 restore_match_data (); | |
1317 unbind_to (speccount); | 1509 unbind_to (speccount); |
1318 } | 1510 } |
1319 | 1511 |
1320 DEFUN ("set-process-sentinel", Fset_process_sentinel, 2, 2, 0, /* | 1512 DEFUN ("set-process-sentinel", Fset_process_sentinel, 2, 2, 0, /* |
1321 Give PROCESS the sentinel SENTINEL; nil for none. | 1513 Give PROCESS the sentinel SENTINEL; nil for none. |
1399 return Fcopy_sequence (Fsymbol_name (symbol)); | 1591 return Fcopy_sequence (Fsymbol_name (symbol)); |
1400 } | 1592 } |
1401 | 1593 |
1402 /* Tell status_notify() to check for terminated processes. We do this | 1594 /* Tell status_notify() to check for terminated processes. We do this |
1403 because on some systems we sometimes miss SIGCHLD calls. (Not sure | 1595 because on some systems we sometimes miss SIGCHLD calls. (Not sure |
1404 why.) */ | 1596 why.) This is also used under Mswin. */ |
1405 | 1597 |
1406 void | 1598 void |
1407 kick_status_notify (void) | 1599 kick_status_notify (void) |
1408 { | 1600 { |
1409 process_tick++; | 1601 process_tick++; |
1463 { | 1655 { |
1464 p->update_tick = this_process_tick; | 1656 p->update_tick = this_process_tick; |
1465 | 1657 |
1466 /* If process is still active, read any output that remains. */ | 1658 /* If process is still active, read any output that remains. */ |
1467 while (!EQ (p->filter, Qt) | 1659 while (!EQ (p->filter, Qt) |
1468 && read_process_output (process) > 0) | 1660 && read_process_output (process, 0) > 0) |
1661 ; | |
1662 while (p->separate_stderr && !EQ (p->stderr_filter, Qt) | |
1663 && read_process_output (process, 1) > 0) | |
1469 ; | 1664 ; |
1470 | 1665 |
1471 /* Get the text to use for the message. */ | 1666 /* Get the text to use for the message. */ |
1472 msg = status_message (p); | 1667 msg = status_message (p); |
1473 | 1668 |
1492 /* Avoid error if buffer is deleted | 1687 /* Avoid error if buffer is deleted |
1493 (probably that's why the process is dead, too) */ | 1688 (probably that's why the process is dead, too) */ |
1494 BUFFER_LIVE_P (XBUFFER (p->buffer))) | 1689 BUFFER_LIVE_P (XBUFFER (p->buffer))) |
1495 { | 1690 { |
1496 struct gcpro ngcpro1; | 1691 struct gcpro ngcpro1; |
1497 struct buffer *buf = XBUFFER (p->buffer); | 1692 int spec = process_setup_for_insertion (process, 0); |
1498 int spec = process_setup_for_insertion (process); | |
1499 | 1693 |
1500 NGCPRO1 (process); | 1694 NGCPRO1 (process); |
1501 buffer_insert_c_string (current_buffer, "\nProcess "); | 1695 buffer_insert_c_string (current_buffer, "\nProcess "); |
1502 Finsert (1, &p->name); | 1696 Finsert (1, &p->name); |
1503 buffer_insert_c_string (current_buffer, " "); | 1697 buffer_insert_c_string (current_buffer, " "); |
1887 | 2081 |
1888 if (!MAYBE_INT_PROCMETH (process_send_eof, (process))) | 2082 if (!MAYBE_INT_PROCMETH (process_send_eof, (process))) |
1889 { | 2083 { |
1890 if (!NILP (DATA_OUTSTREAM (XPROCESS (process)))) | 2084 if (!NILP (DATA_OUTSTREAM (XPROCESS (process)))) |
1891 { | 2085 { |
2086 USID humpty, dumpty; | |
1892 Lstream_close (XLSTREAM (DATA_OUTSTREAM (XPROCESS (process)))); | 2087 Lstream_close (XLSTREAM (DATA_OUTSTREAM (XPROCESS (process)))); |
1893 event_stream_delete_stream_pair (Qnil, XPROCESS (process)->pipe_outstream); | 2088 event_stream_delete_io_streams (Qnil, |
2089 XPROCESS (process)->pipe_outstream, | |
2090 Qnil, &humpty, &dumpty); | |
1894 XPROCESS (process)->pipe_outstream = Qnil; | 2091 XPROCESS (process)->pipe_outstream = Qnil; |
1895 XPROCESS (process)->coding_outstream = Qnil; | 2092 XPROCESS (process)->coding_outstream = Qnil; |
1896 } | 2093 } |
1897 } | 2094 } |
1898 | 2095 |
1906 | 2103 |
1907 void | 2104 void |
1908 deactivate_process (Lisp_Object process) | 2105 deactivate_process (Lisp_Object process) |
1909 { | 2106 { |
1910 Lisp_Process *p = XPROCESS (process); | 2107 Lisp_Process *p = XPROCESS (process); |
1911 USID usid; | 2108 USID in_usid, err_usid; |
1912 | 2109 |
1913 /* It's possible that we got as far in the process-creation | 2110 /* It's possible that we got as far in the process-creation |
1914 process as creating the descriptors but didn't get so | 2111 process as creating the descriptors but didn't get so |
1915 far as selecting the process for input. In this | 2112 far as selecting the process for input. In this |
1916 case, p->pid is nil: p->pid is set at the same time that | 2113 case, p->pid is nil: p->pid is set at the same time that |
1917 the process is selected for input. */ | 2114 the process is selected for input. */ |
1918 /* #### The comment does not look correct. event_stream_unselect_process | 2115 /* #### The comment does not look correct. event_stream_unselect_process |
1919 is guarded by process->selected, so this is not a problem. - kkm*/ | 2116 is guarded by process->*_selected, so this is not a problem. - kkm*/ |
1920 /* Must call this before setting the streams to nil */ | 2117 /* Must call this before setting the streams to nil */ |
1921 event_stream_unselect_process (p); | 2118 event_stream_unselect_process (p, 1, 1); |
1922 | 2119 |
1923 if (!NILP (DATA_OUTSTREAM (p))) | 2120 if (!NILP (DATA_OUTSTREAM (p))) |
1924 Lstream_close (XLSTREAM (DATA_OUTSTREAM (p))); | 2121 Lstream_close (XLSTREAM (DATA_OUTSTREAM (p))); |
1925 if (!NILP (DATA_INSTREAM (p))) | 2122 if (!NILP (DATA_INSTREAM (p))) |
1926 Lstream_close (XLSTREAM (DATA_INSTREAM (p))); | 2123 Lstream_close (XLSTREAM (DATA_INSTREAM (p))); |
2124 if (!NILP (DATA_ERRSTREAM (p))) | |
2125 Lstream_close (XLSTREAM (DATA_ERRSTREAM (p))); | |
1927 | 2126 |
1928 /* Provide minimal implementation for deactivate_process | 2127 /* Provide minimal implementation for deactivate_process |
1929 if there's no process-specific one */ | 2128 if there's no process-specific one */ |
1930 if (HAS_PROCMETH_P (deactivate_process)) | 2129 if (HAS_PROCMETH_P (deactivate_process)) |
1931 usid = PROCMETH (deactivate_process, (p)); | 2130 PROCMETH (deactivate_process, (p, &in_usid, &err_usid)); |
1932 else | 2131 else |
1933 usid = event_stream_delete_stream_pair (p->pipe_instream, | 2132 event_stream_delete_io_streams (p->pipe_instream, |
1934 p->pipe_outstream); | 2133 p->pipe_outstream, |
1935 | 2134 p->pipe_errstream, |
1936 if (usid != USID_DONTHASH) | 2135 &in_usid, &err_usid); |
1937 remhash ((const void*)usid, usid_to_process); | 2136 |
2137 if (in_usid != USID_DONTHASH) | |
2138 remhash ((const void*)in_usid, usid_to_process); | |
2139 if (err_usid != USID_DONTHASH) | |
2140 remhash ((const void*)err_usid, usid_to_process); | |
1938 | 2141 |
1939 p->pipe_instream = Qnil; | 2142 p->pipe_instream = Qnil; |
1940 p->pipe_outstream = Qnil; | 2143 p->pipe_outstream = Qnil; |
2144 p->pipe_errstream = Qnil; | |
1941 p->coding_instream = Qnil; | 2145 p->coding_instream = Qnil; |
1942 p->coding_outstream = Qnil; | 2146 p->coding_outstream = Qnil; |
2147 p->coding_errstream = Qnil; | |
1943 } | 2148 } |
1944 | 2149 |
1945 static void | 2150 static void |
1946 remove_process (Lisp_Object process) | 2151 remove_process (Lisp_Object process) |
1947 { | 2152 { |
2303 DEFSUBR (Fprocess_id); | 2508 DEFSUBR (Fprocess_id); |
2304 DEFSUBR (Fprocess_name); | 2509 DEFSUBR (Fprocess_name); |
2305 DEFSUBR (Fprocess_tty_name); | 2510 DEFSUBR (Fprocess_tty_name); |
2306 DEFSUBR (Fprocess_command); | 2511 DEFSUBR (Fprocess_command); |
2307 DEFSUBR (Fset_process_buffer); | 2512 DEFSUBR (Fset_process_buffer); |
2513 DEFSUBR (Fset_process_stderr_buffer); | |
2308 DEFSUBR (Fprocess_buffer); | 2514 DEFSUBR (Fprocess_buffer); |
2309 DEFSUBR (Fprocess_mark); | 2515 DEFSUBR (Fprocess_mark); |
2516 DEFSUBR (Fprocess_stderr_buffer); | |
2517 DEFSUBR (Fprocess_stderr_mark); | |
2310 DEFSUBR (Fset_process_filter); | 2518 DEFSUBR (Fset_process_filter); |
2311 DEFSUBR (Fprocess_filter); | 2519 DEFSUBR (Fprocess_filter); |
2520 DEFSUBR (Fset_process_stderr_filter); | |
2521 DEFSUBR (Fprocess_stderr_filter); | |
2312 DEFSUBR (Fset_process_window_size); | 2522 DEFSUBR (Fset_process_window_size); |
2313 DEFSUBR (Fset_process_sentinel); | 2523 DEFSUBR (Fset_process_sentinel); |
2314 DEFSUBR (Fprocess_sentinel); | 2524 DEFSUBR (Fprocess_sentinel); |
2315 DEFSUBR (Fprocess_kill_without_query); | 2525 DEFSUBR (Fprocess_kill_without_query); |
2316 DEFSUBR (Fprocess_kill_without_query_p); | 2526 DEFSUBR (Fprocess_kill_without_query_p); |
2418 the cdr part is used for writing (encoding) data to a process. | 2628 the cdr part is used for writing (encoding) data to a process. |
2419 */ ); | 2629 */ ); |
2420 /* This below will get its default set correctly in code-init.el. */ | 2630 /* This below will get its default set correctly in code-init.el. */ |
2421 Vdefault_process_coding_system = Fcons (Qundecided, Qnil); | 2631 Vdefault_process_coding_system = Fcons (Qundecided, Qnil); |
2422 | 2632 |
2633 DEFVAR_LISP ("default-network-coding-system", | |
2634 &Vdefault_network_coding_system /* | |
2635 Cons of coding systems used for network I/O by default. | |
2636 The car part is used for reading (decoding) data from a process, and | |
2637 the cdr part is used for writing (encoding) data to a process. | |
2638 */ ); | |
2639 Vdefault_network_coding_system = Fcons (Qundecided, Qnil); | |
2640 | |
2423 #ifdef PROCESS_IO_BLOCKING | 2641 #ifdef PROCESS_IO_BLOCKING |
2424 DEFVAR_LISP ("network-stream-blocking-port-list", &network_stream_blocking_port_list /* | 2642 DEFVAR_LISP ("network-stream-blocking-port-list", &network_stream_blocking_port_list /* |
2425 List of port numbers or port names to set a blocking I/O mode with connection. | 2643 List of port numbers or port names to set a blocking I/O mode with connection. |
2426 Nil value means to set a default(non-blocking) I/O mode. | 2644 Nil value means to set a default(non-blocking) I/O mode. |
2427 The value takes effect when `open-network-stream-internal' is called. | 2645 The value takes effect when `open-network-stream-internal' is called. |