comparison src/process.c @ 83353:532e0a9335a9

Merged in changes from CVS trunk. Plus added lisp/term tweaks. Patches applied: * lorentey@elte.hu--2004/emacs--cvs-trunk--0--base-0 tag of miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-474 * lorentey@elte.hu--2004/emacs--cvs-trunk--0--patch-1 Add CVS metadata files. * lorentey@elte.hu--2004/emacs--cvs-trunk--0--patch-2 Update from CVS. git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-393
author Karoly Lorentey <lorentey@elte.hu>
date Sun, 04 Sep 2005 03:48:17 +0000
parents 6c13700d1c13 d26871fb1b7b
children 2a679c81f552
comparison
equal deleted inserted replaced
83352:b258b3492423 83353:532e0a9335a9
1 /* Asynchronous subprocess control for GNU Emacs. 1 /* Asynchronous subprocess control for GNU Emacs.
2 Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995, 1996, 1998, 1999, 2 Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995,
3 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. 3 1996, 1998, 1999, 2001, 2002, 2003, 2004,
4 2005 Free Software Foundation, Inc.
4 5
5 This file is part of GNU Emacs. 6 This file is part of GNU Emacs.
6 7
7 GNU Emacs is free software; you can redistribute it and/or modify 8 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by 9 it under the terms of the GNU General Public License as published by
291 #endif 292 #endif
292 293
293 294
294 #include "sysselect.h" 295 #include "sysselect.h"
295 296
296 extern int keyboard_bit_set P_ ((SELECT_TYPE *)); 297 static int keyboard_bit_set P_ ((SELECT_TYPE *));
298 static void deactivate_process P_ ((Lisp_Object));
299 static void status_notify P_ ((struct Lisp_Process *));
300 static int read_process_output P_ ((Lisp_Object, int));
297 301
298 /* If we support a window system, turn on the code to poll periodically 302 /* If we support a window system, turn on the code to poll periodically
299 to detect C-g. It isn't actually used when doing interrupt input. */ 303 to detect C-g. It isn't actually used when doing interrupt input. */
300 #ifdef HAVE_WINDOW_SYSTEM 304 #ifdef HAVE_WINDOW_SYSTEM
301 #define POLL_FOR_INPUT 305 #define POLL_FOR_INPUT
388 #endif 392 #endif
389 393
390 /* Compute the Lisp form of the process status, p->status, from 394 /* Compute the Lisp form of the process status, p->status, from
391 the numeric status that was returned by `wait'. */ 395 the numeric status that was returned by `wait'. */
392 396
393 Lisp_Object status_convert (); 397 static Lisp_Object status_convert ();
394 398
395 void 399 static void
396 update_status (p) 400 update_status (p)
397 struct Lisp_Process *p; 401 struct Lisp_Process *p;
398 { 402 {
399 union { int i; WAITTYPE wt; } u; 403 union { int i; WAITTYPE wt; } u;
400 u.i = XFASTINT (p->raw_status_low) + (XFASTINT (p->raw_status_high) << 16); 404 u.i = XFASTINT (p->raw_status_low) + (XFASTINT (p->raw_status_high) << 16);
404 } 408 }
405 409
406 /* Convert a process status word in Unix format to 410 /* Convert a process status word in Unix format to
407 the list that we use internally. */ 411 the list that we use internally. */
408 412
409 Lisp_Object 413 static Lisp_Object
410 status_convert (w) 414 status_convert (w)
411 WAITTYPE w; 415 WAITTYPE w;
412 { 416 {
413 if (WIFSTOPPED (w)) 417 if (WIFSTOPPED (w))
414 return Fcons (Qstop, Fcons (make_number (WSTOPSIG (w)), Qnil)); 418 return Fcons (Qstop, Fcons (make_number (WSTOPSIG (w)), Qnil));
423 } 427 }
424 428
425 /* Given a status-list, extract the three pieces of information 429 /* Given a status-list, extract the three pieces of information
426 and store them individually through the three pointers. */ 430 and store them individually through the three pointers. */
427 431
428 void 432 static void
429 decode_status (l, symbol, code, coredump) 433 decode_status (l, symbol, code, coredump)
430 Lisp_Object l; 434 Lisp_Object l;
431 Lisp_Object *symbol; 435 Lisp_Object *symbol;
432 int *code; 436 int *code;
433 int *coredump; 437 int *coredump;
502 /* Open an available pty, returning a file descriptor. 506 /* Open an available pty, returning a file descriptor.
503 Return -1 on failure. 507 Return -1 on failure.
504 The file name of the terminal corresponding to the pty 508 The file name of the terminal corresponding to the pty
505 is left in the variable pty_name. */ 509 is left in the variable pty_name. */
506 510
507 int 511 static int
508 allocate_pty () 512 allocate_pty ()
509 { 513 {
510 register int c, i; 514 register int c, i;
511 int fd; 515 int fd;
512 516
587 } 591 }
588 return -1; 592 return -1;
589 } 593 }
590 #endif /* HAVE_PTYS */ 594 #endif /* HAVE_PTYS */
591 595
592 Lisp_Object 596 static Lisp_Object
593 make_process (name) 597 make_process (name)
594 Lisp_Object name; 598 Lisp_Object name;
595 { 599 {
596 register Lisp_Object val, tem, name1; 600 register Lisp_Object val, tem, name1;
597 register struct Lisp_Process *p; 601 register struct Lisp_Process *p;
631 XSETPROCESS (val, p); 635 XSETPROCESS (val, p);
632 Vprocess_alist = Fcons (Fcons (name, val), Vprocess_alist); 636 Vprocess_alist = Fcons (Fcons (name, val), Vprocess_alist);
633 return val; 637 return val;
634 } 638 }
635 639
636 void 640 static void
637 remove_process (proc) 641 remove_process (proc)
638 register Lisp_Object proc; 642 register Lisp_Object proc;
639 { 643 {
640 register Lisp_Object pair; 644 register Lisp_Object pair;
641 645
765 PROCESS may be a process, a buffer, the name of a process or buffer, or 769 PROCESS may be a process, a buffer, the name of a process or buffer, or
766 nil, indicating the current buffer's process. */) 770 nil, indicating the current buffer's process. */)
767 (process) 771 (process)
768 register Lisp_Object process; 772 register Lisp_Object process;
769 { 773 {
774 register struct Lisp_Process *p;
775
770 process = get_process (process); 776 process = get_process (process);
771 XPROCESS (process)->raw_status_low = Qnil; 777 p = XPROCESS (process);
772 XPROCESS (process)->raw_status_high = Qnil; 778
773 if (NETCONN_P (process)) 779 p->raw_status_low = Qnil;
774 { 780 p->raw_status_high = Qnil;
775 XPROCESS (process)->status = Fcons (Qexit, Fcons (make_number (0), Qnil)); 781 if (NETCONN1_P (p))
776 XSETINT (XPROCESS (process)->tick, ++process_tick); 782 {
777 status_notify (); 783 p->status = Fcons (Qexit, Fcons (make_number (0), Qnil));
778 } 784 XSETINT (p->tick, ++process_tick);
779 else if (XINT (XPROCESS (process)->infd) >= 0) 785 status_notify (p);
786 }
787 else if (XINT (p->infd) >= 0)
780 { 788 {
781 Fkill_process (process, Qnil); 789 Fkill_process (process, Qnil);
782 /* Do this now, since remove_process will make sigchld_handler do nothing. */ 790 /* Do this now, since remove_process will make sigchld_handler do nothing. */
783 XPROCESS (process)->status 791 p->status
784 = Fcons (Qsignal, Fcons (make_number (SIGKILL), Qnil)); 792 = Fcons (Qsignal, Fcons (make_number (SIGKILL), Qnil));
785 XSETINT (XPROCESS (process)->tick, ++process_tick); 793 XSETINT (p->tick, ++process_tick);
786 status_notify (); 794 status_notify (p);
787 } 795 }
788 remove_process (process); 796 remove_process (process);
789 return Qnil; 797 return Qnil;
790 } 798 }
791 799
1235 1243
1236 return Qnil; 1244 return Qnil;
1237 } 1245 }
1238 #endif 1246 #endif
1239 1247
1240 Lisp_Object 1248 static Lisp_Object
1241 list_processes_1 (query_only) 1249 list_processes_1 (query_only)
1242 Lisp_Object query_only; 1250 Lisp_Object query_only;
1243 { 1251 {
1244 register Lisp_Object tail, tem; 1252 register Lisp_Object tail, tem;
1245 Lisp_Object proc, minspace, tem1; 1253 Lisp_Object proc, minspace, tem1;
1705 remove_process (proc); 1713 remove_process (proc);
1706 1714
1707 return Qnil; 1715 return Qnil;
1708 } 1716 }
1709 1717
1710 void 1718 static void
1711 create_process_1 (timer) 1719 create_process_1 (timer)
1712 struct atimer *timer; 1720 struct atimer *timer;
1713 { 1721 {
1714 /* Nothing to do. */ 1722 /* Nothing to do. */
1715 } 1723 }
2528 } 2536 }
2529 2537
2530 2538
2531 /* A version of request_sigio suitable for a record_unwind_protect. */ 2539 /* A version of request_sigio suitable for a record_unwind_protect. */
2532 2540
2533 Lisp_Object 2541 static Lisp_Object
2534 unwind_request_sigio (dummy) 2542 unwind_request_sigio (dummy)
2535 Lisp_Object dummy; 2543 Lisp_Object dummy;
2536 { 2544 {
2537 if (interrupt_input) 2545 if (interrupt_input)
2538 request_sigio (); 2546 request_sigio ();
4219 <= 0)) 4227 <= 0))
4220 { 4228 {
4221 /* It's okay for us to do this and then continue with 4229 /* It's okay for us to do this and then continue with
4222 the loop, since timeout has already been zeroed out. */ 4230 the loop, since timeout has already been zeroed out. */
4223 clear_waiting_for_input (); 4231 clear_waiting_for_input ();
4224 status_notify (); 4232 status_notify (NULL);
4225 } 4233 }
4226 } 4234 }
4227 4235
4228 /* Don't wait for output from a non-running process. Just 4236 /* Don't wait for output from a non-running process. Just
4229 read whatever data has already been received. */ 4237 read whatever data has already been received. */
4737 you must call it repeatedly until it returns zero. 4745 you must call it repeatedly until it returns zero.
4738 4746
4739 The characters read are decoded according to PROC's coding-system 4747 The characters read are decoded according to PROC's coding-system
4740 for decoding. */ 4748 for decoding. */
4741 4749
4742 int 4750 static int
4743 read_process_output (proc, channel) 4751 read_process_output (proc, channel)
4744 Lisp_Object proc; 4752 Lisp_Object proc;
4745 register int channel; 4753 register int channel;
4746 { 4754 {
4747 register int nbytes; 4755 register int nbytes;
5128 If OBJECT is not nil, the data is encoded by PROC's coding-system 5136 If OBJECT is not nil, the data is encoded by PROC's coding-system
5129 for encoding before it is sent. 5137 for encoding before it is sent.
5130 5138
5131 This function can evaluate Lisp code and can garbage collect. */ 5139 This function can evaluate Lisp code and can garbage collect. */
5132 5140
5133 void 5141 static void
5134 send_process (proc, buf, len, object) 5142 send_process (proc, buf, len, object)
5135 volatile Lisp_Object proc; 5143 volatile Lisp_Object proc;
5136 unsigned char *volatile buf; 5144 unsigned char *volatile buf;
5137 volatile int len; 5145 volatile int len;
5138 volatile Lisp_Object object; 5146 volatile Lisp_Object object;
5722 p->raw_status_low = Qnil; 5730 p->raw_status_low = Qnil;
5723 p->raw_status_high = Qnil; 5731 p->raw_status_high = Qnil;
5724 p->status = Qrun; 5732 p->status = Qrun;
5725 XSETINT (p->tick, ++process_tick); 5733 XSETINT (p->tick, ++process_tick);
5726 if (!nomsg) 5734 if (!nomsg)
5727 status_notify (); 5735 status_notify (NULL);
5728 break; 5736 break;
5729 #endif /* ! defined (SIGCONT) */ 5737 #endif /* ! defined (SIGCONT) */
5730 case SIGINT: 5738 case SIGINT:
5731 #ifdef VMS 5739 #ifdef VMS
5732 send_process (proc, "\003", 1, Qnil); /* ^C */ 5740 send_process (proc, "\003", 1, Qnil); /* ^C */
6390 /* Report all recent events of a change in process status 6398 /* Report all recent events of a change in process status
6391 (either run the sentinel or output a message). 6399 (either run the sentinel or output a message).
6392 This is usually done while Emacs is waiting for keyboard input 6400 This is usually done while Emacs is waiting for keyboard input
6393 but can be done at other times. */ 6401 but can be done at other times. */
6394 6402
6395 void 6403 static void
6396 status_notify () 6404 status_notify (deleting_process)
6405 struct Lisp_Process *deleting_process;
6397 { 6406 {
6398 register Lisp_Object proc, buffer; 6407 register Lisp_Object proc, buffer;
6399 Lisp_Object tail, msg; 6408 Lisp_Object tail, msg;
6400 struct gcpro gcpro1, gcpro2; 6409 struct gcpro gcpro1, gcpro2;
6401 6410
6427 while (! EQ (p->filter, Qt) 6436 while (! EQ (p->filter, Qt)
6428 && ! EQ (p->status, Qconnect) 6437 && ! EQ (p->status, Qconnect)
6429 && ! EQ (p->status, Qlisten) 6438 && ! EQ (p->status, Qlisten)
6430 && ! EQ (p->command, Qt) /* Network process not stopped. */ 6439 && ! EQ (p->command, Qt) /* Network process not stopped. */
6431 && XINT (p->infd) >= 0 6440 && XINT (p->infd) >= 0
6441 && p != deleting_process
6432 && read_process_output (proc, XINT (p->infd)) > 0); 6442 && read_process_output (proc, XINT (p->infd)) > 0);
6433 6443
6434 buffer = p->buffer; 6444 buffer = p->buffer;
6435 6445
6436 /* Get the text to use for the message. */ 6446 /* Get the text to use for the message. */
6622 } 6632 }
6623 6633
6624 /* Return nonzero if *MASK has a bit set 6634 /* Return nonzero if *MASK has a bit set
6625 that corresponds to one of the keyboard input descriptors. */ 6635 that corresponds to one of the keyboard input descriptors. */
6626 6636
6627 int 6637 static int
6628 keyboard_bit_set (mask) 6638 keyboard_bit_set (mask)
6629 SELECT_TYPE *mask; 6639 SELECT_TYPE *mask;
6630 { 6640 {
6631 int fd; 6641 int fd;
6632 6642