aboutsummaryrefslogtreecommitdiffstats
path: root/src/process.c
diff options
context:
space:
mode:
authorStefan Monnier2010-08-11 07:42:48 +0200
committerStefan Monnier2010-08-11 07:42:48 +0200
commitc566235d981eba73c88bbff00b6a1d88360b6e9f (patch)
treef8d653add3570fe750a83d1123ed35022e0bf4ef /src/process.c
parent0bfdb86f425a88fe43ebc88851c6f9a6418e1862 (diff)
parent490b89acab3e759426ede25c31c94268df55e925 (diff)
downloademacs-c566235d981eba73c88bbff00b6a1d88360b6e9f.tar.gz
emacs-c566235d981eba73c88bbff00b6a1d88360b6e9f.zip
Merge from trunk
Diffstat (limited to 'src/process.c')
-rw-r--r--src/process.c129
1 files changed, 39 insertions, 90 deletions
diff --git a/src/process.c b/src/process.c
index 219098905cf..4a658623077 100644
--- a/src/process.c
+++ b/src/process.c
@@ -43,7 +43,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
43/* Only MS-DOS does not define `subprocesses'. */ 43/* Only MS-DOS does not define `subprocesses'. */
44#ifdef subprocesses 44#ifdef subprocesses
45 45
46#ifdef HAVE_SOCKETS /* TCP connection support, if kernel can do it */
47#include <sys/socket.h> 46#include <sys/socket.h>
48#include <netdb.h> 47#include <netdb.h>
49#include <netinet/in.h> 48#include <netinet/in.h>
@@ -59,30 +58,21 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
59#include <sys/un.h> 58#include <sys/un.h>
60#endif 59#endif
61#endif 60#endif
62#endif /* HAVE_SOCKETS */
63 61
64#if defined(HAVE_SYS_IOCTL_H) 62#if defined(HAVE_SYS_IOCTL_H)
65#include <sys/ioctl.h> 63#include <sys/ioctl.h>
66#if !defined (O_NDELAY) && defined (HAVE_PTYS) && !defined(USG5) 64#if !defined (O_NDELAY) && defined (HAVE_PTYS) && !defined(USG5)
67#include <fcntl.h> 65#include <fcntl.h>
68#endif /* HAVE_PTYS and no O_NDELAY */ 66#endif /* HAVE_PTYS and no O_NDELAY */
67#if defined(HAVE_NET_IF_H)
68#include <net/if.h>
69#endif /* HAVE_NET_IF_H */
69#endif /* HAVE_SYS_IOCTL_H */ 70#endif /* HAVE_SYS_IOCTL_H */
70 71
71#ifdef NEED_BSDTTY 72#ifdef NEED_BSDTTY
72#include <bsdtty.h> 73#include <bsdtty.h>
73#endif 74#endif
74 75
75/* Can we use SIOCGIFCONF and/or SIOCGIFADDR */
76#ifdef HAVE_SOCKETS
77#if defined(HAVE_SYS_IOCTL_H) && defined(HAVE_NET_IF_H)
78/* sys/ioctl.h may have been included already */
79#ifndef SIOCGIFADDR
80#include <sys/ioctl.h>
81#endif
82#include <net/if.h>
83#endif
84#endif
85
86#ifdef HAVE_SYS_WAIT 76#ifdef HAVE_SYS_WAIT
87#include <sys/wait.h> 77#include <sys/wait.h>
88#endif 78#endif
@@ -93,6 +83,10 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
93#include <resolv.h> 83#include <resolv.h>
94#endif 84#endif
95 85
86#ifdef HAVE_UTIL_H
87#include <util.h>
88#endif
89
96#endif /* subprocesses */ 90#endif /* subprocesses */
97 91
98#include "lisp.h" 92#include "lisp.h"
@@ -120,6 +114,27 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
120#if defined (USE_GTK) || defined (HAVE_GCONF) 114#if defined (USE_GTK) || defined (HAVE_GCONF)
121#include "xgselect.h" 115#include "xgselect.h"
122#endif /* defined (USE_GTK) || defined (HAVE_GCONF) */ 116#endif /* defined (USE_GTK) || defined (HAVE_GCONF) */
117#ifdef HAVE_NS
118#include "nsterm.h"
119#endif
120extern int timers_run;
121
122Lisp_Object Qeuid, Qegid, Qcomm, Qstate, Qppid, Qpgrp, Qsess, Qttname, Qtpgid;
123Lisp_Object Qminflt, Qmajflt, Qcminflt, Qcmajflt, Qutime, Qstime, Qcstime;
124Lisp_Object Qcutime, Qpri, Qnice, Qthcount, Qstart, Qvsize, Qrss, Qargs;
125Lisp_Object Quser, Qgroup, Qetime, Qpcpu, Qpmem, Qtime, Qctime;
126Lisp_Object QCname, QCtype;
127
128/* Non-zero if keyboard input is on hold, zero otherwise. */
129
130static int kbd_is_on_hold;
131
132/* Nonzero means delete a process right away if it exits. */
133static int delete_exited_processes;
134
135/* Nonzero means don't run process sentinels. This is used
136 when exiting. */
137int inhibit_sentinels;
123 138
124#ifdef subprocesses 139#ifdef subprocesses
125 140
@@ -150,17 +165,10 @@ extern Lisp_Object QCfamily;
150/* QCfilter is defined in keyboard.c. */ 165/* QCfilter is defined in keyboard.c. */
151extern Lisp_Object QCfilter; 166extern Lisp_Object QCfilter;
152 167
153#ifdef HAVE_SOCKETS
154#define NETCONN_P(p) (EQ (XPROCESS (p)->type, Qnetwork)) 168#define NETCONN_P(p) (EQ (XPROCESS (p)->type, Qnetwork))
155#define NETCONN1_P(p) (EQ ((p)->type, Qnetwork)) 169#define NETCONN1_P(p) (EQ ((p)->type, Qnetwork))
156#define SERIALCONN_P(p) (EQ (XPROCESS (p)->type, Qserial)) 170#define SERIALCONN_P(p) (EQ (XPROCESS (p)->type, Qserial))
157#define SERIALCONN1_P(p) (EQ ((p)->type, Qserial)) 171#define SERIALCONN1_P(p) (EQ ((p)->type, Qserial))
158#else
159#define NETCONN_P(p) 0
160#define NETCONN1_P(p) 0
161#define SERIALCONN_P(p) 0
162#define SERIALCONN1_P(p) 0
163#endif /* HAVE_SOCKETS */
164 172
165/* Define first descriptor number available for subprocesses. */ 173/* Define first descriptor number available for subprocesses. */
166#define FIRST_PROC_DESC 3 174#define FIRST_PROC_DESC 3
@@ -172,7 +180,7 @@ extern Lisp_Object QCfilter;
172#define SIGCHLD SIGCLD 180#define SIGCHLD SIGCLD
173#endif /* SIGCLD */ 181#endif /* SIGCLD */
174 182
175extern char *get_operating_system_release (void); 183extern const char *get_operating_system_release (void);
176 184
177/* Serial processes require termios or Windows. */ 185/* Serial processes require termios or Windows. */
178#if defined (HAVE_TERMIOS) || defined (WINDOWSNT) 186#if defined (HAVE_TERMIOS) || defined (WINDOWSNT)
@@ -206,7 +214,6 @@ int update_tick;
206#undef NON_BLOCKING_CONNECT 214#undef NON_BLOCKING_CONNECT
207#else 215#else
208#ifndef NON_BLOCKING_CONNECT 216#ifndef NON_BLOCKING_CONNECT
209#ifdef HAVE_SOCKETS
210#ifdef HAVE_SELECT 217#ifdef HAVE_SELECT
211#if defined (HAVE_GETPEERNAME) || defined (GNU_LINUX) 218#if defined (HAVE_GETPEERNAME) || defined (GNU_LINUX)
212#if defined (O_NONBLOCK) || defined (O_NDELAY) 219#if defined (O_NONBLOCK) || defined (O_NDELAY)
@@ -216,7 +223,6 @@ int update_tick;
216#endif /* O_NONBLOCK || O_NDELAY */ 223#endif /* O_NONBLOCK || O_NDELAY */
217#endif /* HAVE_GETPEERNAME || GNU_LINUX */ 224#endif /* HAVE_GETPEERNAME || GNU_LINUX */
218#endif /* HAVE_SELECT */ 225#endif /* HAVE_SELECT */
219#endif /* HAVE_SOCKETS */
220#endif /* NON_BLOCKING_CONNECT */ 226#endif /* NON_BLOCKING_CONNECT */
221#endif /* BROKEN_NON_BLOCKING_CONNECT */ 227#endif /* BROKEN_NON_BLOCKING_CONNECT */
222 228
@@ -229,13 +235,11 @@ int update_tick;
229#undef DATAGRAM_SOCKETS 235#undef DATAGRAM_SOCKETS
230#else 236#else
231#ifndef DATAGRAM_SOCKETS 237#ifndef DATAGRAM_SOCKETS
232#ifdef HAVE_SOCKETS
233#if defined (HAVE_SELECT) || defined (FIONREAD) 238#if defined (HAVE_SELECT) || defined (FIONREAD)
234#if defined (HAVE_SENDTO) && defined (HAVE_RECVFROM) && defined (EMSGSIZE) 239#if defined (HAVE_SENDTO) && defined (HAVE_RECVFROM) && defined (EMSGSIZE)
235#define DATAGRAM_SOCKETS 240#define DATAGRAM_SOCKETS
236#endif /* HAVE_SENDTO && HAVE_RECVFROM && EMSGSIZE */ 241#endif /* HAVE_SENDTO && HAVE_RECVFROM && EMSGSIZE */
237#endif /* HAVE_SELECT || FIONREAD */ 242#endif /* HAVE_SELECT || FIONREAD */
238#endif /* HAVE_SOCKETS */
239#endif /* DATAGRAM_SOCKETS */ 243#endif /* DATAGRAM_SOCKETS */
240#endif /* BROKEN_DATAGRAM_SOCKETS */ 244#endif /* BROKEN_DATAGRAM_SOCKETS */
241 245
@@ -287,29 +291,6 @@ static void create_pty (Lisp_Object);
287static Lisp_Object get_process (register Lisp_Object name); 291static Lisp_Object get_process (register Lisp_Object name);
288static void exec_sentinel (Lisp_Object proc, Lisp_Object reason); 292static void exec_sentinel (Lisp_Object proc, Lisp_Object reason);
289 293
290#endif /* subprocesses */
291
292extern int timers_run;
293
294Lisp_Object Qeuid, Qegid, Qcomm, Qstate, Qppid, Qpgrp, Qsess, Qttname, Qtpgid;
295Lisp_Object Qminflt, Qmajflt, Qcminflt, Qcmajflt, Qutime, Qstime, Qcstime;
296Lisp_Object Qcutime, Qpri, Qnice, Qthcount, Qstart, Qvsize, Qrss, Qargs;
297Lisp_Object Quser, Qgroup, Qetime, Qpcpu, Qpmem, Qtime, Qctime;
298Lisp_Object QCname, QCtype;
299
300/* Non-zero if keyboard input is on hold, zero otherwise. */
301
302static int kbd_is_on_hold;
303
304/* Nonzero means delete a process right away if it exits. */
305static int delete_exited_processes;
306
307/* Nonzero means don't run process sentinels. This is used
308 when exiting. */
309int inhibit_sentinels;
310
311#ifdef subprocesses
312
313/* Mask of bits indicating the descriptors that we wait for input on. */ 294/* Mask of bits indicating the descriptors that we wait for input on. */
314 295
315static SELECT_TYPE input_wait_mask; 296static SELECT_TYPE input_wait_mask;
@@ -1148,7 +1129,6 @@ nil, indicating the current buffer's process. */)
1148 return XPROCESS (proc)->type; 1129 return XPROCESS (proc)->type;
1149} 1130}
1150 1131
1151#ifdef HAVE_SOCKETS
1152DEFUN ("format-network-address", Fformat_network_address, Sformat_network_address, 1132DEFUN ("format-network-address", Fformat_network_address, Sformat_network_address,
1153 1, 2, 0, 1133 1, 2, 0,
1154 doc: /* Convert network ADDRESS from internal format to a string. 1134 doc: /* Convert network ADDRESS from internal format to a string.
@@ -1222,7 +1202,6 @@ Returns nil if format of ADDRESS is invalid. */)
1222 1202
1223 return Qnil; 1203 return Qnil;
1224} 1204}
1225#endif
1226 1205
1227static Lisp_Object 1206static Lisp_Object
1228list_processes_1 (Lisp_Object query_only) 1207list_processes_1 (Lisp_Object query_only)
@@ -1727,25 +1706,6 @@ create_process_1 (struct atimer *timer)
1727} 1706}
1728 1707
1729 1708
1730#if 0 /* This doesn't work; see the note before sigchld_handler. */
1731#ifdef USG
1732#ifdef SIGCHLD
1733/* Mimic blocking of signals on system V, which doesn't really have it. */
1734
1735/* Nonzero means we got a SIGCHLD when it was supposed to be blocked. */
1736int sigchld_deferred;
1737
1738SIGTYPE
1739create_process_sigchld ()
1740{
1741 signal (SIGCHLD, create_process_sigchld);
1742
1743 sigchld_deferred = 1;
1744}
1745#endif
1746#endif
1747#endif
1748
1749void 1709void
1750create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir) 1710create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
1751{ 1711{
@@ -2215,8 +2175,6 @@ create_pty (Lisp_Object process)
2215} 2175}
2216 2176
2217 2177
2218#ifdef HAVE_SOCKETS
2219
2220/* Convert an internal struct sockaddr to a lisp object (vector or string). 2178/* Convert an internal struct sockaddr to a lisp object (vector or string).
2221 The address family of sa is not included in the result. */ 2179 The address family of sa is not included in the result. */
2222 2180
@@ -2447,7 +2405,7 @@ Returns nil upon error setting address, ADDRESS otherwise. */)
2447static const struct socket_options { 2405static const struct socket_options {
2448 /* The name of this option. Should be lowercase version of option 2406 /* The name of this option. Should be lowercase version of option
2449 name without SO_ prefix. */ 2407 name without SO_ prefix. */
2450 char *name; 2408 const char *name;
2451 /* Option level SOL_... */ 2409 /* Option level SOL_... */
2452 int optlevel; 2410 int optlevel;
2453 /* Option number SO_... */ 2411 /* Option number SO_... */
@@ -3075,7 +3033,8 @@ usage: (make-network-process &rest ARGS) */)
3075#ifdef HAVE_GETADDRINFO 3033#ifdef HAVE_GETADDRINFO
3076 struct addrinfo ai, *res, *lres; 3034 struct addrinfo ai, *res, *lres;
3077 struct addrinfo hints; 3035 struct addrinfo hints;
3078 char *portstring, portbuf[128]; 3036 const char *portstring;
3037 char portbuf[128];
3079#else /* HAVE_GETADDRINFO */ 3038#else /* HAVE_GETADDRINFO */
3080 struct _emacs_addrinfo 3039 struct _emacs_addrinfo
3081 { 3040 {
@@ -3770,10 +3729,9 @@ usage: (make-network-process &rest ARGS) */)
3770 UNGCPRO; 3729 UNGCPRO;
3771 return proc; 3730 return proc;
3772} 3731}
3773#endif /* HAVE_SOCKETS */
3774 3732
3775 3733
3776#if defined(HAVE_SOCKETS) && defined(HAVE_NET_IF_H) && defined(HAVE_SYS_IOCTL_H) 3734#if defined(HAVE_NET_IF_H) && defined(HAVE_SYS_IOCTL_H)
3777 3735
3778#ifdef SIOCGIFCONF 3736#ifdef SIOCGIFCONF
3779DEFUN ("network-interface-list", Fnetwork_interface_list, Snetwork_interface_list, 0, 0, 0, 3737DEFUN ("network-interface-list", Fnetwork_interface_list, Snetwork_interface_list, 0, 0, 0,
@@ -4016,7 +3974,7 @@ FLAGS is the current flags of the interface. */)
4016 return any ? res : Qnil; 3974 return any ? res : Qnil;
4017} 3975}
4018#endif 3976#endif
4019#endif /* HAVE_SOCKETS */ 3977#endif /* defined(HAVE_NET_IF_H) && defined(HAVE_SYS_IOCTL_H) */
4020 3978
4021/* Turn off input and output for process PROC. */ 3979/* Turn off input and output for process PROC. */
4022 3980
@@ -5458,7 +5416,7 @@ send_process_trap (int ignore)
5458 This function can evaluate Lisp code and can garbage collect. */ 5416 This function can evaluate Lisp code and can garbage collect. */
5459 5417
5460static void 5418static void
5461send_process (volatile Lisp_Object proc, unsigned char *volatile buf, 5419send_process (volatile Lisp_Object proc, const unsigned char *volatile buf,
5462 volatile int len, volatile Lisp_Object object) 5420 volatile int len, volatile Lisp_Object object)
5463{ 5421{
5464 /* Use volatile to protect variables from being clobbered by longjmp. */ 5422 /* Use volatile to protect variables from being clobbered by longjmp. */
@@ -6064,7 +6022,6 @@ If PROCESS is a network or serial process, inhibit handling of incoming
6064traffic. */) 6022traffic. */)
6065 (Lisp_Object process, Lisp_Object current_group) 6023 (Lisp_Object process, Lisp_Object current_group)
6066{ 6024{
6067#ifdef HAVE_SOCKETS
6068 if (PROCESSP (process) && (NETCONN_P (process) || SERIALCONN_P (process))) 6025 if (PROCESSP (process) && (NETCONN_P (process) || SERIALCONN_P (process)))
6069 { 6026 {
6070 struct Lisp_Process *p; 6027 struct Lisp_Process *p;
@@ -6079,7 +6036,6 @@ traffic. */)
6079 p->command = Qt; 6036 p->command = Qt;
6080 return process; 6037 return process;
6081 } 6038 }
6082#endif
6083#ifndef SIGTSTP 6039#ifndef SIGTSTP
6084 error ("No SIGTSTP support"); 6040 error ("No SIGTSTP support");
6085#else 6041#else
@@ -6095,7 +6051,6 @@ If PROCESS is a network or serial process, resume handling of incoming
6095traffic. */) 6051traffic. */)
6096 (Lisp_Object process, Lisp_Object current_group) 6052 (Lisp_Object process, Lisp_Object current_group)
6097{ 6053{
6098#ifdef HAVE_SOCKETS
6099 if (PROCESSP (process) && (NETCONN_P (process) || SERIALCONN_P (process))) 6054 if (PROCESSP (process) && (NETCONN_P (process) || SERIALCONN_P (process)))
6100 { 6055 {
6101 struct Lisp_Process *p; 6056 struct Lisp_Process *p;
@@ -6118,7 +6073,6 @@ traffic. */)
6118 p->command = Qnil; 6073 p->command = Qnil;
6119 return process; 6074 return process;
6120 } 6075 }
6121#endif
6122#ifdef SIGCONT 6076#ifdef SIGCONT
6123 process_send_signal (process, SIGCONT, current_group, 0); 6077 process_send_signal (process, SIGCONT, current_group, 0);
6124#else 6078#else
@@ -6402,8 +6356,7 @@ sigchld_handler (int signo)
6402{ 6356{
6403 int old_errno = errno; 6357 int old_errno = errno;
6404 Lisp_Object proc; 6358 Lisp_Object proc;
6405 register struct Lisp_Process *p; 6359 struct Lisp_Process *p;
6406 extern EMACS_TIME *input_available_clear_time;
6407 6360
6408 SIGNAL_THREAD_CHECK (signo); 6361 SIGNAL_THREAD_CHECK (signo);
6409 6362
@@ -7430,7 +7383,6 @@ init_process (void)
7430 memset (datagram_address, 0, sizeof datagram_address); 7383 memset (datagram_address, 0, sizeof datagram_address);
7431#endif 7384#endif
7432 7385
7433#ifdef HAVE_SOCKETS
7434 { 7386 {
7435 Lisp_Object subfeatures = Qnil; 7387 Lisp_Object subfeatures = Qnil;
7436 const struct socket_options *sopt; 7388 const struct socket_options *sopt;
@@ -7466,14 +7418,13 @@ init_process (void)
7466 7418
7467 Fprovide (intern_c_string ("make-network-process"), subfeatures); 7419 Fprovide (intern_c_string ("make-network-process"), subfeatures);
7468 } 7420 }
7469#endif /* HAVE_SOCKETS */
7470 7421
7471#if defined (DARWIN_OS) 7422#if defined (DARWIN_OS)
7472 /* PTYs are broken on Darwin < 6, but are sometimes useful for interactive 7423 /* PTYs are broken on Darwin < 6, but are sometimes useful for interactive
7473 processes. As such, we only change the default value. */ 7424 processes. As such, we only change the default value. */
7474 if (initialized) 7425 if (initialized)
7475 { 7426 {
7476 char *release = get_operating_system_release (); 7427 const char *release = get_operating_system_release ();
7477 if (!release || !release[0] || (release[0] < MIN_PTY_KERNEL_VERSION 7428 if (!release || !release[0] || (release[0] < MIN_PTY_KERNEL_VERSION
7478 && release[1] == '.')) { 7429 && release[1] == '.')) {
7479 Vprocess_connection_type = Qnil; 7430 Vprocess_connection_type = Qnil;
@@ -7725,19 +7676,17 @@ The variable takes effect when `start-process' is called. */);
7725 defsubr (&Sserial_process_configure); 7676 defsubr (&Sserial_process_configure);
7726 defsubr (&Smake_serial_process); 7677 defsubr (&Smake_serial_process);
7727#endif /* HAVE_SERIAL */ 7678#endif /* HAVE_SERIAL */
7728#ifdef HAVE_SOCKETS
7729 defsubr (&Sset_network_process_option); 7679 defsubr (&Sset_network_process_option);
7730 defsubr (&Smake_network_process); 7680 defsubr (&Smake_network_process);
7731 defsubr (&Sformat_network_address); 7681 defsubr (&Sformat_network_address);
7732#endif /* HAVE_SOCKETS */ 7682#if defined(HAVE_NET_IF_H) && defined(HAVE_SYS_IOCTL_H)
7733#if defined(HAVE_SOCKETS) && defined(HAVE_NET_IF_H) && defined(HAVE_SYS_IOCTL_H)
7734#ifdef SIOCGIFCONF 7683#ifdef SIOCGIFCONF
7735 defsubr (&Snetwork_interface_list); 7684 defsubr (&Snetwork_interface_list);
7736#endif 7685#endif
7737#if defined(SIOCGIFADDR) || defined(SIOCGIFHWADDR) || defined(SIOCGIFFLAGS) 7686#if defined(SIOCGIFADDR) || defined(SIOCGIFHWADDR) || defined(SIOCGIFFLAGS)
7738 defsubr (&Snetwork_interface_info); 7687 defsubr (&Snetwork_interface_info);
7739#endif 7688#endif
7740#endif /* HAVE_SOCKETS ... */ 7689#endif /* defined(HAVE_NET_IF_H) && defined(HAVE_SYS_IOCTL_H) */
7741#ifdef DATAGRAM_SOCKETS 7690#ifdef DATAGRAM_SOCKETS
7742 defsubr (&Sprocess_datagram_address); 7691 defsubr (&Sprocess_datagram_address);
7743 defsubr (&Sset_process_datagram_address); 7692 defsubr (&Sset_process_datagram_address);