X-Git-Url: https://git.hcoop.net/bpt/emacs.git/blobdiff_plain/39eb0cb563f5287270f3946804456dc766386638..9a84bfd6813ca38b8402e4368dcc76e857716cd9:/src/process.c diff --git a/src/process.c b/src/process.c index 20f84990d6..85470b66c3 100644 --- a/src/process.c +++ b/src/process.c @@ -1,6 +1,6 @@ /* Asynchronous subprocess control for GNU Emacs. -Copyright (C) 1985-1988, 1993-1996, 1998-1999, 2001-2013 Free Software +Copyright (C) 1985-1988, 1993-1996, 1998-1999, 2001-2014 Free Software Foundation, Inc. This file is part of GNU Emacs. @@ -21,8 +21,6 @@ along with GNU Emacs. If not, see . */ #include -#define PROCESS_INLINE EXTERN_INLINE - #include #include #include /* Some typedefs are used in sys/file.h. */ @@ -814,13 +812,14 @@ get_process (register Lisp_Object name) else obj = name; - /* Now obj should be either a buffer object or a process object. - */ + /* Now obj should be either a buffer object or a process object. */ if (BUFFERP (obj)) { + if (NILP (BVAR (XBUFFER (obj), name))) + error ("Attempt to get process for a dead buffer"); proc = Fget_buffer_process (obj); if (NILP (proc)) - error ("Buffer %s has no process", SDATA (BVAR (XBUFFER (obj), name))); + error ("Buffer %s has no process", SDATA (BVAR (XBUFFER (obj), name))); } else { @@ -1531,7 +1530,8 @@ usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS) */) tem = Qnil; GCPRO4 (name, program, buffer, current_dir); - openp (Vexec_path, program, Vexec_suffixes, &tem, make_number (X_OK)); + openp (Vexec_path, program, Vexec_suffixes, &tem, + make_number (X_OK), false); UNGCPRO; if (NILP (tem)) report_file_error ("Searching for program", program); @@ -1841,6 +1841,9 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir) signal (SIGINT, SIG_DFL); signal (SIGQUIT, SIG_DFL); +#ifdef SIGPROF + signal (SIGPROF, SIG_DFL); +#endif /* Emacs ignores SIGPIPE, but the child should not. */ signal (SIGPIPE, SIG_DFL); @@ -1960,7 +1963,10 @@ create_pty (Lisp_Object process) /* Convert an internal struct sockaddr to a lisp object (vector or string). The address family of sa is not included in the result. */ -static Lisp_Object +#ifndef WINDOWSNT +static +#endif +Lisp_Object conv_sockaddr_to_lisp (struct sockaddr *sa, int len) { Lisp_Object address; @@ -3506,15 +3512,11 @@ usage: (make-network-process &rest ARGS) */) } -#if defined (HAVE_NET_IF_H) +#ifdef HAVE_NET_IF_H #ifdef SIOCGIFCONF -DEFUN ("network-interface-list", Fnetwork_interface_list, Snetwork_interface_list, 0, 0, 0, - doc: /* Return an alist of all network interfaces and their network address. -Each element is a cons, the car of which is a string containing the -interface name, and the cdr is the network address in internal -format; see the description of ADDRESS in `make-network-process'. */) - (void) +static Lisp_Object +network_interface_list (void) { struct ifconf ifconf; struct ifreq *ifreq; @@ -3656,13 +3658,8 @@ static const struct ifflag_def ifflag_table[] = { { 0, 0 } }; -DEFUN ("network-interface-info", Fnetwork_interface_info, Snetwork_interface_info, 1, 1, 0, - doc: /* Return information about network interface named IFNAME. -The return value is a list (ADDR BCAST NETMASK HWADDR FLAGS), -where ADDR is the layer 3 address, BCAST is the layer 3 broadcast address, -NETMASK is the layer 3 network mask, HWADDR is the layer 2 address, and -FLAGS is the current flags of the interface. */) - (Lisp_Object ifname) +static Lisp_Object +network_interface_info (Lisp_Object ifname) { struct ifreq rq; Lisp_Object res = Qnil; @@ -3731,7 +3728,9 @@ FLAGS is the current flags of the interface. */) any = 1; for (n = 0; n < 6; n++) - p->contents[n] = make_number (((unsigned char *)&rq.ifr_hwaddr.sa_data[0])[n]); + p->contents[n] = make_number (((unsigned char *) + &rq.ifr_hwaddr.sa_data[0]) + [n]); elt = Fcons (make_number (rq.ifr_hwaddr.sa_family), hwaddr); } #elif defined (HAVE_GETIFADDRS) && defined (LLADDR) @@ -3804,9 +3803,48 @@ FLAGS is the current flags of the interface. */) return unbind_to (count, any ? res : Qnil); } -#endif +#endif /* !SIOCGIFADDR && !SIOCGIFHWADDR && !SIOCGIFFLAGS */ #endif /* defined (HAVE_NET_IF_H) */ +DEFUN ("network-interface-list", Fnetwork_interface_list, + Snetwork_interface_list, 0, 0, 0, + doc: /* Return an alist of all network interfaces and their network address. +Each element is a cons, the car of which is a string containing the +interface name, and the cdr is the network address in internal +format; see the description of ADDRESS in `make-network-process'. + +If the information is not available, return nil. */) + (void) +{ +#if (defined HAVE_NET_IF_H && defined SIOCGIFCONF) || defined WINDOWSNT + return network_interface_list (); +#else + return Qnil; +#endif +} + +DEFUN ("network-interface-info", Fnetwork_interface_info, + Snetwork_interface_info, 1, 1, 0, + doc: /* Return information about network interface named IFNAME. +The return value is a list (ADDR BCAST NETMASK HWADDR FLAGS), +where ADDR is the layer 3 address, BCAST is the layer 3 broadcast address, +NETMASK is the layer 3 network mask, HWADDR is the layer 2 address, and +FLAGS is the current flags of the interface. + +Data that is unavailable is returned as nil. */) + (Lisp_Object ifname) +{ +#if ((defined HAVE_NET_IF_H \ + && (defined SIOCGIFADDR || defined SIOCGIFHWADDR \ + || defined SIOCGIFFLAGS)) \ + || defined WINDOWSNT) + return network_interface_info (ifname); +#else + return Qnil; +#endif +} + + /* Turn off input and output for process PROC. */ static void @@ -4576,7 +4614,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, { struct Lisp_Process *p = XPROCESS (chan_process[channel]); - if (p && p->gnutls_p && p->infd + if (p && p->gnutls_p && p->gnutls_state && p->infd && ((emacs_gnutls_record_check_pending (p->gnutls_state)) > 0)) @@ -4590,6 +4628,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, { /* Check this specific channel. */ if (wait_proc->gnutls_p /* Check for valid process. */ + && wait_proc->gnutls_state /* Do we have pending data? */ && ((emacs_gnutls_record_check_pending (wait_proc->gnutls_state)) @@ -4849,7 +4888,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, #else { struct sockaddr pname; - int pnamelen = sizeof (pname); + socklen_t pnamelen = sizeof (pname); /* If connection failed, getpeername will fail. */ xerrno = 0; @@ -4971,7 +5010,7 @@ read_process_output (Lisp_Object proc, register int channel) proc_buffered_char[channel] = -1; } #ifdef HAVE_GNUTLS - if (p->gnutls_p) + if (p->gnutls_p && p->gnutls_state) nbytes = emacs_gnutls_read (p, chars + carryover + buffered, readmax - buffered); else @@ -5212,7 +5251,7 @@ DEFUN ("internal-default-process-filter", Finternal_default_process_filter, else set_marker_both (p->mark, p->buffer, PT, PT_BYTE); - update_mode_lines++; + update_mode_lines = 23; /* Make sure opoint and the old restrictions float ahead of any new text just as point would. */ @@ -5465,7 +5504,7 @@ send_process (Lisp_Object proc, const char *buf, ptrdiff_t len, #endif { #ifdef HAVE_GNUTLS - if (p->gnutls_p) + if (p->gnutls_p && p->gnutls_state) written = emacs_gnutls_write (p, cur_buf, cur_len); else #endif @@ -5997,13 +6036,16 @@ process has been transmitted to the serial port. */) (Lisp_Object process) { Lisp_Object proc; - struct coding_system *coding; + struct coding_system *coding = NULL; + int outfd; if (DATAGRAM_CONN_P (process)) return process; proc = get_process (process); - coding = proc_encode_coding_system[XPROCESS (proc)->outfd]; + outfd = XPROCESS (proc)->outfd; + if (outfd >= 0) + coding = proc_encode_coding_system[outfd]; /* Make sure the process is really alive. */ if (XPROCESS (proc)->raw_status_new) @@ -6011,7 +6053,7 @@ process has been transmitted to the serial port. */) if (! EQ (XPROCESS (proc)->status, Qrun)) error ("Process %s not running", SDATA (XPROCESS (proc)->name)); - if (CODING_REQUIRE_FLUSHING (coding)) + if (coding && CODING_REQUIRE_FLUSHING (coding)) { coding->mode |= CODING_MODE_LAST_BLOCK; send_process (proc, "", 0, Qnil); @@ -6029,7 +6071,8 @@ process has been transmitted to the serial port. */) } else { - int old_outfd = XPROCESS (proc)->outfd; + struct Lisp_Process *p = XPROCESS (proc); + int old_outfd = p->outfd; int new_outfd; #ifdef HAVE_SHUTDOWN @@ -6037,24 +6080,30 @@ process has been transmitted to the serial port. */) for communication with the subprocess, call shutdown to cause EOF. (In some old system, shutdown to socketpair doesn't work. Then we just can't win.) */ - if (EQ (XPROCESS (proc)->type, Qnetwork) - || XPROCESS (proc)->infd == old_outfd) + if (EQ (p->type, Qnetwork) + || p->infd == old_outfd) shutdown (old_outfd, 1); #endif - close_process_fd (&XPROCESS (proc)->open_fd[WRITE_TO_SUBPROCESS]); + close_process_fd (&p->open_fd[WRITE_TO_SUBPROCESS]); new_outfd = emacs_open (NULL_DEVICE, O_WRONLY, 0); if (new_outfd < 0) report_file_error ("Opening null device", Qnil); - XPROCESS (proc)->open_fd[WRITE_TO_SUBPROCESS] = new_outfd; - XPROCESS (proc)->outfd = new_outfd; + p->open_fd[WRITE_TO_SUBPROCESS] = new_outfd; + p->outfd = new_outfd; if (!proc_encode_coding_system[new_outfd]) proc_encode_coding_system[new_outfd] = xmalloc (sizeof (struct coding_system)); - *proc_encode_coding_system[new_outfd] - = *proc_encode_coding_system[old_outfd]; - memset (proc_encode_coding_system[old_outfd], 0, - sizeof (struct coding_system)); + if (old_outfd >= 0) + { + *proc_encode_coding_system[new_outfd] + = *proc_encode_coding_system[old_outfd]; + memset (proc_encode_coding_system[old_outfd], 0, + sizeof (struct coding_system)); + } + else + setup_coding_system (p->encode_coding_system, + proc_encode_coding_system[new_outfd]); } return process; } @@ -6186,7 +6235,7 @@ handle_child_signal (int sig) lib_child_handler (sig); #ifdef NS_IMPL_GNUSTEP - /* NSTask in GNUStep sets its child handler each time it is called. + /* NSTask in GNUstep sets its child handler each time it is called. So we must re-set ours. */ catch_child_signal(); #endif @@ -6356,7 +6405,7 @@ status_notify (struct Lisp_Process *deleting_process) } } /* end for */ - update_mode_lines++; /* In case buffers use %s in mode-line-format. */ + update_mode_lines = 24; /* In case buffers use %s in mode-line-format. */ UNGCPRO; } @@ -7295,14 +7344,8 @@ The variable takes effect when `start-process' is called. */); defsubr (&Sset_network_process_option); defsubr (&Smake_network_process); defsubr (&Sformat_network_address); -#if defined (HAVE_NET_IF_H) -#ifdef SIOCGIFCONF defsubr (&Snetwork_interface_list); -#endif -#if defined (SIOCGIFADDR) || defined (SIOCGIFHWADDR) || defined (SIOCGIFFLAGS) defsubr (&Snetwork_interface_info); -#endif -#endif /* defined (HAVE_NET_IF_H) */ #ifdef DATAGRAM_SOCKETS defsubr (&Sprocess_datagram_address); defsubr (&Sset_process_datagram_address);