/* 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.
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
{
for (i = 0; i < nargs; i++)
{
- if (! RANGED_INTEGERP (0, p->u.contents[i], 65535))
+ if (! RANGED_INTEGERP (0, p->contents[i], 65535))
return Qnil;
if (nargs <= 5 /* IPv4 */
&& i < 4 /* host, not port */
- && XINT (p->u.contents[i]) > 255)
+ && XINT (p->contents[i]) > 255)
return Qnil;
- args[i+1] = p->u.contents[i];
+ args[i+1] = p->contents[i];
}
return Fformat (nargs+1, 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);
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);
/* Convert an internal struct sockaddr to a lisp object (vector or string).
The address family of sa is not included in the result. */
+#ifndef WINDOWSNT
+static
+#endif
Lisp_Object
conv_sockaddr_to_lisp (struct sockaddr *sa, int len)
{
len = sizeof (sin->sin_addr) + 1;
address = Fmake_vector (make_number (len), Qnil);
p = XVECTOR (address);
- p->u.contents[--len] = make_number (ntohs (sin->sin_port));
+ p->contents[--len] = make_number (ntohs (sin->sin_port));
cp = (unsigned char *) &sin->sin_addr;
break;
}
len = sizeof (sin6->sin6_addr)/2 + 1;
address = Fmake_vector (make_number (len), Qnil);
p = XVECTOR (address);
- p->u.contents[--len] = make_number (ntohs (sin6->sin6_port));
+ p->contents[--len] = make_number (ntohs (sin6->sin6_port));
for (i = 0; i < len; i++)
- p->u.contents[i] = make_number (ntohs (ip6[i]));
+ p->contents[i] = make_number (ntohs (ip6[i]));
return address;
}
#endif
i = 0;
while (i < len)
- p->u.contents[i++] = make_number (*cp++);
+ p->contents[i++] = make_number (*cp++);
return address;
}
{
struct sockaddr_in *sin = (struct sockaddr_in *) sa;
len = sizeof (sin->sin_addr) + 1;
- hostport = XINT (p->u.contents[--len]);
+ hostport = XINT (p->contents[--len]);
sin->sin_port = htons (hostport);
cp = (unsigned char *)&sin->sin_addr;
sa->sa_family = family;
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) sa;
uint16_t *ip6 = (uint16_t *)&sin6->sin6_addr;
len = sizeof (sin6->sin6_addr) + 1;
- hostport = XINT (p->u.contents[--len]);
+ hostport = XINT (p->contents[--len]);
sin6->sin6_port = htons (hostport);
for (i = 0; i < len; i++)
- if (INTEGERP (p->u.contents[i]))
+ if (INTEGERP (p->contents[i]))
{
- int j = XFASTINT (p->u.contents[i]) & 0xffff;
+ int j = XFASTINT (p->contents[i]) & 0xffff;
ip6[i] = ntohs (j);
}
sa->sa_family = family;
}
for (i = 0; i < len; i++)
- if (INTEGERP (p->u.contents[i]))
- *cp++ = XFASTINT (p->u.contents[i]) & 0xff;
+ if (INTEGERP (p->contents[i]))
+ *cp++ = XFASTINT (p->contents[i]) & 0xff;
}
#ifdef DATAGRAM_SOCKETS
}
\f
-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
-}
-
-#if defined (HAVE_NET_IF_H)
+#ifdef HAVE_NET_IF_H
#ifdef SIOCGIFCONF
-Lisp_Object
+static Lisp_Object
network_interface_list (void)
{
struct ifconf ifconf;
{ 0, 0 }
};
-Lisp_Object
+static Lisp_Object
network_interface_info (Lisp_Object ifname)
{
struct ifreq rq;
any = 1;
for (n = 0; n < 6; n++)
- p->u.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)
memcpy (linkaddr, LLADDR (sdl), sdl->sdl_alen);
for (n = 0; n < 6; n++)
- p->u.contents[n] = make_number (linkaddr[n]);
+ p->contents[n] = make_number (linkaddr[n]);
elt = Fcons (make_number (it->ifa_addr->sa_family), hwaddr);
break;
#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
{
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))
{
/* 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))
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
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. */
#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
(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)
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);
}
else
{
- int old_outfd = XPROCESS (proc)->outfd;
+ struct Lisp_Process *p = XPROCESS (proc);
+ int old_outfd = p->outfd;
int new_outfd;
#ifdef HAVE_SHUTDOWN
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;
}
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
}
} /* 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;
}