comparison src/process-unix.c @ 380:8626e4521993 r21-2-5

Import from CVS: tag r21-2-5
author cvs
date Mon, 13 Aug 2007 11:07:10 +0200
parents d883f39b8495
children 4af0ddfb7c5b
comparison
equal deleted inserted replaced
379:76b7d63099ad 380:8626e4521993
1 /* Asynchronous subprocess implemenation for UNIX 1 /* Asynchronous subprocess implementation for UNIX
2 Copyright (C) 1985, 1986, 1987, 1988, 1992, 1993, 1994, 1995 2 Copyright (C) 1985, 1986, 1987, 1988, 1992, 1993, 1994, 1995
3 Free Software Foundation, Inc. 3 Free Software Foundation, Inc.
4 Copyright (C) 1995 Sun Microsystems, Inc. 4 Copyright (C) 1995 Sun Microsystems, Inc.
5 Copyright (C) 1995, 1996 Ben Wing. 5 Copyright (C) 1995, 1996 Ben Wing.
6 6
35 /* The entire file is within this conditional */ 35 /* The entire file is within this conditional */
36 36
37 #include "lisp.h" 37 #include "lisp.h"
38 38
39 #include "buffer.h" 39 #include "buffer.h"
40 #include "commands.h"
41 #include "events.h" 40 #include "events.h"
42 #include "frame.h" 41 #include "frame.h"
43 #include "hash.h" 42 #include "hash.h"
44 #include "insdel.h"
45 #include "lstream.h" 43 #include "lstream.h"
46 #include "opaque.h" 44 #include "opaque.h"
47 #include "process.h" 45 #include "process.h"
48 #include "procimpl.h" 46 #include "procimpl.h"
49 #include "sysdep.h" 47 #include "sysdep.h"
60 #include "systty.h" 58 #include "systty.h"
61 #include "syswait.h" 59 #include "syswait.h"
62 60
63 61
64 /* 62 /*
65 * Implemenation-specific data. Pointed to by Lisp_Process->process_data 63 * Implementation-specific data. Pointed to by Lisp_Process->process_data
66 */ 64 */
67 65
68 struct unix_process_data 66 struct unix_process_data
69 { 67 {
70 /* Non-0 if this is really a ToolTalk channel. */ 68 /* Non-0 if this is really a ToolTalk channel. */
234 #ifdef PTY_OPEN 232 #ifdef PTY_OPEN
235 PTY_OPEN; 233 PTY_OPEN;
236 #else /* no PTY_OPEN */ 234 #else /* no PTY_OPEN */
237 #ifdef IRIS 235 #ifdef IRIS
238 /* Unusual IRIS code */ 236 /* Unusual IRIS code */
239 *ptyv = open ("/dev/ptc", O_RDWR | O_NDELAY | OPEN_BINARY, 0); 237 *ptyv = open ("/dev/ptc", O_RDWR | O_NONBLOCK | OPEN_BINARY, 0);
240 if (fd < 0) 238 if (fd < 0)
241 return -1; 239 return -1;
242 if (fstat (fd, &stb) < 0) 240 if (fstat (fd, &stb) < 0)
243 return -1; 241 return -1;
244 #else /* not IRIS */ 242 #else /* not IRIS */
248 if (failed_count >= 3) 246 if (failed_count >= 3)
249 return -1; 247 return -1;
250 } 248 }
251 else 249 else
252 failed_count = 0; 250 failed_count = 0;
253 #ifdef O_NONBLOCK
254 fd = open (pty_name, O_RDWR | O_NONBLOCK | OPEN_BINARY, 0); 251 fd = open (pty_name, O_RDWR | O_NONBLOCK | OPEN_BINARY, 0);
255 #else
256 fd = open (pty_name, O_RDWR | O_NDELAY | OPEN_BINARY, 0);
257 #endif
258 #endif /* not IRIS */ 252 #endif /* not IRIS */
259 #endif /* no PTY_OPEN */ 253 #endif /* no PTY_OPEN */
260 254
261 if (fd >= 0) 255 if (fd >= 0)
262 { 256 {
670 664
671 static void 665 static void
672 unix_mark_process_data (struct Lisp_Process *proc, 666 unix_mark_process_data (struct Lisp_Process *proc,
673 void (*markobj) (Lisp_Object)) 667 void (*markobj) (Lisp_Object))
674 { 668 {
675 ((markobj) (UNIX_DATA(proc)->tty_name)); 669 markobj (UNIX_DATA(proc)->tty_name);
676 } 670 }
677 671
678 /* 672 /*
679 * Initialize XEmacs process implemenation once 673 * Initialize XEmacs process implementation once
680 */ 674 */
681 675
682 #ifdef SIGCHLD 676 #ifdef SIGCHLD
683 static void 677 static void
684 unix_init_process (void) 678 unix_init_process (void)
706 /* 700 /*
707 * Fork off a subprocess. P is a pointer to newly created subprocess 701 * Fork off a subprocess. P is a pointer to newly created subprocess
708 * object. If this function signals, the caller is responsible for 702 * object. If this function signals, the caller is responsible for
709 * deleting (and finalizing) the process object. 703 * deleting (and finalizing) the process object.
710 * 704 *
711 * The method must return PID of the new proces, a (positive??? ####) number 705 * The method must return PID of the new process, a (positive??? ####) number
712 * which fits into Lisp_Int. No return value indicates an error, the method 706 * which fits into Lisp_Int. No return value indicates an error, the method
713 * must signal an error instead. 707 * must signal an error instead.
714 */ 708 */
715 709
716 static int 710 static int
798 { 792 {
799 #if !defined(__CYGWIN32__) 793 #if !defined(__CYGWIN32__)
800 /* child_setup must clobber environ on systems with true vfork. 794 /* child_setup must clobber environ on systems with true vfork.
801 Protect it from permanent change. */ 795 Protect it from permanent change. */
802 char **save_environ = environ; 796 char **save_environ = environ;
803 #endif
804
805 #ifdef EMACS_BTL
806 /* when performance monitoring is on, turn it off before the vfork(),
807 as the child has no handler for the signal -- when back in the
808 parent process, turn it back on if it was really on when you "turned
809 it off" */
810 int logging_on = cadillac_stop_logging (); /* #### rename me */
811 #endif 797 #endif
812 798
813 pid = fork (); 799 pid = fork ();
814 if (pid == 0) 800 if (pid == 0)
815 { 801 {
923 /* On AIX, we've disabled SIGHUP above once we start a 909 /* On AIX, we've disabled SIGHUP above once we start a
924 child on a pty. Now reenable it in the child, so it 910 child on a pty. Now reenable it in the child, so it
925 will die when we want it to. 911 will die when we want it to.
926 JV: This needs to be done ALWAYS as we might have inherited 912 JV: This needs to be done ALWAYS as we might have inherited
927 a SIG_IGN handling from our parent (nohup) and we are in new 913 a SIG_IGN handling from our parent (nohup) and we are in new
928 process group. 914 process group.
929 */ 915 */
930 signal (SIGHUP, SIG_DFL); 916 signal (SIGHUP, SIG_DFL);
931 } 917 }
932 #endif /* HAVE_PTYS */ 918 #endif /* HAVE_PTYS */
933 919
940 child_setup_tty (xforkout); 926 child_setup_tty (xforkout);
941 } 927 }
942 928
943 child_setup (xforkin, xforkout, xforkout, new_argv, current_dir); 929 child_setup (xforkin, xforkout, xforkout, new_argv, current_dir);
944 } 930 }
945 #ifdef EMACS_BTL
946 else if (logging_on)
947 cadillac_start_logging (); /* #### rename me */
948 #endif
949 931
950 #if !defined(__CYGWIN32__) 932 #if !defined(__CYGWIN32__)
951 environ = save_environ; 933 environ = save_environ;
952 #endif 934 #endif
953 } 935 }
994 } 976 }
995 977
996 RETURN_NOT_REACHED (0); 978 RETURN_NOT_REACHED (0);
997 } 979 }
998 980
999 /* 981 /* Return nonzero if this process is a ToolTalk connection. */
1000 * Return nonzero if this process is a ToolTalk connection.
1001 */
1002 982
1003 static int 983 static int
1004 unix_tooltalk_connection_p (struct Lisp_Process *p) 984 unix_tooltalk_connection_p (struct Lisp_Process *p)
1005 { 985 {
1006 return UNIX_DATA(p)->connected_via_filedesc_p; 986 return UNIX_DATA(p)->connected_via_filedesc_p;
1007 } 987 }
1008 988
1009 /* 989 /* This is called to set process' virtual terminal size */
1010 * This is called to set process' virtual terminal size
1011 */
1012 990
1013 static int 991 static int
1014 unix_set_window_size (struct Lisp_Process* p, int cols, int rows) 992 unix_set_window_size (struct Lisp_Process* p, int cols, int rows)
1015 { 993 {
1016 return set_window_size (UNIX_DATA(p)->infd, cols, rows); 994 return set_window_size (UNIX_DATA(p)->infd, cols, rows);
1130 EMACS_UNBLOCK_SIGNAL (SIGCHLD); 1108 EMACS_UNBLOCK_SIGNAL (SIGCHLD);
1131 } 1109 }
1132 #endif /* SIGCHLD */ 1110 #endif /* SIGCHLD */
1133 1111
1134 /* 1112 /*
1135 * Stuff the entire contents of LSTREAM to the process ouptut pipe 1113 * Stuff the entire contents of LSTREAM to the process output pipe
1136 */ 1114 */
1137 1115
1138 static JMP_BUF send_process_frame; 1116 static JMP_BUF send_process_frame;
1139 1117
1140 static SIGTYPE 1118 static SIGTYPE
1178 chunklen); 1156 chunklen);
1179 signal (SIGPIPE, old_sigpipe); 1157 signal (SIGPIPE, old_sigpipe);
1180 if (writeret < 0) 1158 if (writeret < 0)
1181 /* This is a real error. Blocking errors are handled 1159 /* This is a real error. Blocking errors are handled
1182 specially inside of the filedesc stream. */ 1160 specially inside of the filedesc stream. */
1183 report_file_error ("writing to process", 1161 report_file_error ("writing to process", list1 (proc));
1184 list1 (vol_proc));
1185 while (Lstream_was_blocked_p (XLSTREAM (p->pipe_outstream))) 1162 while (Lstream_was_blocked_p (XLSTREAM (p->pipe_outstream)))
1186 { 1163 {
1187 /* Buffer is full. Wait, accepting input; 1164 /* Buffer is full. Wait, accepting input;
1188 that may allow the program 1165 that may allow the program
1189 to finish doing output and read more. */ 1166 to finish doing output and read more. */
1205 p->status_symbol = Qexit; 1182 p->status_symbol = Qexit;
1206 p->exit_code = 256; /* #### SIGPIPE ??? */ 1183 p->exit_code = 256; /* #### SIGPIPE ??? */
1207 p->core_dumped = 0; 1184 p->core_dumped = 0;
1208 p->tick++; 1185 p->tick++;
1209 process_tick++; 1186 process_tick++;
1210 deactivate_process (vol_proc); 1187 deactivate_process (*((Lisp_Object *) (&vol_proc)));
1211 error ("SIGPIPE raised on process %s; closed it", 1188 error ("SIGPIPE raised on process %s; closed it",
1212 XSTRING_DATA (p->name)); 1189 XSTRING_DATA (p->name));
1213 } 1190 }
1214 1191
1215 old_sigpipe = (SIGTYPE (*) (int)) signal (SIGPIPE, send_process_trap); 1192 old_sigpipe = (SIGTYPE (*) (int)) signal (SIGPIPE, send_process_trap);
1252 * event_stream_delete_stream_pair 1229 * event_stream_delete_stream_pair
1253 * 1230 *
1254 * In the lack of this method, only event_stream_delete_stream_pair 1231 * In the lack of this method, only event_stream_delete_stream_pair
1255 * is called on both I/O streams of the process. 1232 * is called on both I/O streams of the process.
1256 * 1233 *
1257 * The UNIX version quards this by ignoring possible SIGPIPE. 1234 * The UNIX version guards this by ignoring possible SIGPIPE.
1258 */ 1235 */
1259 1236
1260 static USID 1237 static USID
1261 unix_deactivate_process (struct Lisp_Process *p) 1238 unix_deactivate_process (struct Lisp_Process *p)
1262 { 1239 {
1423 } 1400 }
1424 1401
1425 /* 1402 /*
1426 * Canonicalize host name HOST, and return its canonical form 1403 * Canonicalize host name HOST, and return its canonical form
1427 * 1404 *
1428 * The default implemenation just takes HOST for a canonical name. 1405 * The default implementation just takes HOST for a canonical name.
1429 */ 1406 */
1430 1407
1431 #ifdef HAVE_SOCKETS 1408 #ifdef HAVE_SOCKETS
1432 static Lisp_Object 1409 static Lisp_Object
1433 unix_canonicalize_host_name (Lisp_Object host) 1410 unix_canonicalize_host_name (Lisp_Object host)
1573 This function is similar to open-network-stream-internal, but provides a 1550 This function is similar to open-network-stream-internal, but provides a
1574 mean to open an UDP multicast connection instead of a TCP one. Like in the 1551 mean to open an UDP multicast connection instead of a TCP one. Like in the
1575 TCP case, the multicast connection will be seen as a sub-process, 1552 TCP case, the multicast connection will be seen as a sub-process,
1576 1553
1577 Some notes: 1554 Some notes:
1578 - Normaly, we should use sendto and recvfrom with non connected 1555 - Normally, we should use sendto and recvfrom with non connected
1579 sockets. The current code doesn't allow us to do this. In the future, it 1556 sockets. The current code doesn't allow us to do this. In the future, it
1580 would be a good idea to extend the process data structure in order to deal 1557 would be a good idea to extend the process data structure in order to deal
1581 properly with the different types network connections. 1558 properly with the different types network connections.
1582 - For the same reason, when leaving a multicast group, it is better to make 1559 - For the same reason, when leaving a multicast group, it is better to make
1583 a setsockopt - IP_DROP_MEMBERSHIP before closing the descriptors. 1560 a setsockopt - IP_DROP_MEMBERSHIP before closing the descriptors.
1654 report_file_error ("error adding membership", list2(name, dest)); 1631 report_file_error ("error adding membership", list2(name, dest));
1655 } 1632 }
1656 1633
1657 /* Socket configuration for writing ----------------------- */ 1634 /* Socket configuration for writing ----------------------- */
1658 1635
1659 /* Normaly, there's no 'connect' in multicast, since we use preferentialy 1636 /* Normally, there's no 'connect' in multicast, since we prefer to use
1660 'sendto' and 'recvfrom'. However, in order to handle this connection in 1637 'sendto' and 'recvfrom'. However, in order to handle this connection in
1661 the process-like way it is done for TCP, we must be able to use 'write' 1638 the process-like way it is done for TCP, we must be able to use 'write'
1662 instead of 'sendto'. Consequently, we 'connect' this socket. */ 1639 instead of 'sendto'. Consequently, we 'connect' this socket. */
1663 1640
1664 /* See open-network-stream-internal for comments on this part of the code */ 1641 /* See open-network-stream-internal for comments on this part of the code */