/* Asynchronous subprocess control for GNU Emacs.
- Copyright (C) 1985, 1986, 1987, 1988, 1993 Free Software Foundation, Inc.
+ Copyright (C) 1985, 86, 87, 88, 93, 94 Free Software Foundation, Inc.
This file is part of GNU Emacs.
#include <arpa/inet.h>
#endif /* HAVE_SOCKETS */
+/* TERM is a poor-man's SLIP, used on Linux. */
+#ifdef TERM
+#include <client.h>
+#endif
+
+/* DGUX inet_addr returns a 'struct in_addr'. */
+#ifdef DGUX
+#define IN_ADDR struct in_addr
+#define NUMERIC_ADDR_ERROR (numeric_addr.s_addr == -1)
+#else
+#define IN_ADDR unsigned long
+#define NUMERIC_ADDR_ERROR (numeric_addr == -1)
+#endif
+
#if defined(BSD) || defined(STRIDE)
#include <sys/ioctl.h>
#if !defined (O_NDELAY) && defined (HAVE_PTYS) && !defined(USG5)
#endif /* HAVE_PTYS and no O_NDELAY */
#endif /* BSD or STRIDE */
+#ifdef BROKEN_O_NONBLOCK
+#undef O_NONBLOCK
+#endif /* BROKEN_O_NONBLOCK */
+
#ifdef NEED_BSDTTY
#include <bsdtty.h>
#endif
#include "syswait.h"
-extern errno;
-extern sys_nerr;
+extern int errno;
+extern char *strerror ();
+#ifdef VMS
extern char *sys_errlist[];
+#endif
#ifndef VMS
#ifndef BSD4_1
#ifndef LINUX
extern char *sys_siglist[];
-#endif
-#else
+#endif /* not LINUX */
+#else /* BSD4_1 */
char *sys_siglist[] =
{
"bum signal!!",
if (EQ (symbol, Qsignal) || EQ (symbol, Qstop))
{
+ char *signame = 0;
+ if (code < NSIG)
+ {
#ifndef VMS
- string = build_string (code < NSIG ? sys_siglist[code] : "unknown");
+ signame = sys_siglist[code];
#else
- string = build_string (code < NSIG ? sys_errlist[code] : "unknown");
+ signame = sys_errlist[code];
#endif
+ }
+ if (signame == 0)
+ signame = "unknown";
+ string = build_string (signame);
string2 = build_string (coredump ? " (core dumped)\n" : "\n");
XSTRING (string)->data[0] = DOWNCASE (XSTRING (string)->data[0]);
return concat2 (string, string2);
XSETTYPE (val, Lisp_Process);
p = XPROCESS (val);
- XFASTINT (p->infd) = 0;
- XFASTINT (p->outfd) = 0;
+ XSET (p->infd, Lisp_Int, -1);
+ XSET (p->outfd, Lisp_Int, -1);
XFASTINT (p->pid) = 0;
XFASTINT (p->tick) = 0;
XFASTINT (p->update_tick) = 0;
Buffers denote the first process in the buffer, and nil denotes the
current buffer. */
-Lisp_Object
+static Lisp_Object
get_process (name)
register Lisp_Object name;
{
XPROCESS (proc)->status = Fcons (Qexit, Fcons (make_number (0), Qnil));
XSETINT (XPROCESS (proc)->tick, ++process_tick);
}
- else if (XFASTINT (XPROCESS (proc)->infd))
+ else if (XINT (XPROCESS (proc)->infd) >= 0)
{
Fkill_process (proc, Qnil);
/* Do this now, since remove_process will make sigchld_handler do nothing. */
{
register struct Lisp_Process *p;
register Lisp_Object status;
- proc = Fget_process (proc);
+ proc = get_process (proc);
if (NILP (proc))
return proc;
p = XPROCESS (proc);
{
CHECK_PROCESS (proc, 0);
if (EQ (filter, Qt))
- FD_CLR (XPROCESS (proc)->infd, &input_wait_mask);
+ FD_CLR (XINT (XPROCESS (proc)->infd), &input_wait_mask);
else if (EQ (XPROCESS (proc)->filter, Qt))
- FD_SET (XPROCESS (proc)->infd, &input_wait_mask);
+ FD_SET (XINT (XPROCESS (proc)->infd), &input_wait_mask);
XPROCESS (proc)->filter = filter;
return filter;
}
/* Record this as an active process, with its channels.
As a result, child_setup will close Emacs's side of the pipes. */
chan_process[inchannel] = process;
- XFASTINT (XPROCESS (process)->infd) = inchannel;
- XFASTINT (XPROCESS (process)->outfd) = outchannel;
+ XSET (XPROCESS (process)->infd, Lisp_Int, inchannel);
+ XSET (XPROCESS (process)->outfd, Lisp_Int, outchannel);
/* Record the tty descriptor used in the subprocess. */
if (forkin < 0)
XPROCESS (process)->subtty = Qnil;
ioctl (xforkin, TIOCSCTTY, 0);
#endif
#else /* not HAVE_SETSID */
-#if defined (USG) && !defined (IRIX)
- /* It's very important to call setpgrp() here and no time
+#ifdef USG
+ /* It's very important to call setpgrp here and no time
afterwards. Otherwise, we lose our controlling tty which
is set when we open the pty. */
setpgrp ();
#endif /* USG */
#endif /* not HAVE_SETSID */
+#ifdef NTTYDISC
+ if (pty_flag)
+ {
+ /* Use new line discipline. */
+ int ldisc = NTTYDISC;
+ if (ioctl (xforkin, TIOCSETD, &ldisc) < 0)
+ write (1, "create_process/TIOCSETD failed\n", 31);
+ }
+#endif
#ifdef TIOCNOTTY
/* In 4.3BSD, the TIOCSPGRP bug has been fixed, and now you
can do TIOCSPGRP only to the process's controlling tty. */
This makes the pty the controlling terminal of the subprocess. */
if (pty_flag)
{
+#ifdef SET_CHILD_PTY_PGRP
+ int pgrp = getpid ();
+#endif
+
/* I wonder if close (open (pty_name, ...)) would work? */
if (xforkin >= 0)
close (xforkin);
xforkout = xforkin = open (pty_name, O_RDWR, 0);
+#ifdef SET_CHILD_PTY_PGRP
+ ioctl (xforkin, TIOCSPGRP, &pgrp);
+ ioctl (xforkout, TIOCSPGRP, &pgrp);
+#endif
+
if (xforkin < 0)
abort ();
}
stop_polling ();
signal (SIGALRM, create_process_1);
alarm (1);
-#ifdef SYSV4_PTYS
- /* OK to close only if it's not a pty. Otherwise we need to leave
- it open for ioctl to get pgrp when signals are sent, or to send
- the interrupt characters through if that's how we're signalling
- subprocesses. Alternately if you are concerned about running out
- of file descriptors, you could just save the tty name and open
- just to do the ioctl. */
- if (NILP (XFASTINT (XPROCESS (process)->pty_flag)))
-#endif
- {
- XPROCESS (process)->subtty = Qnil;
- if (forkin >= 0)
- close (forkin);
- }
+ XPROCESS (process)->subtty = Qnil;
+ if (forkin >= 0)
+ close (forkin);
alarm (0);
start_polling ();
if (forkin != forkout && forkout >= 0)
struct servent *svc_info;
struct hostent *host_info_ptr, host_info;
char *(addr_list[2]);
- unsigned long numeric_addr;
+ IN_ADDR numeric_addr;
int s, outch, inch;
char errstring[80];
int port;
port = svc_info->s_port;
}
+#ifndef TERM
host_info_ptr = gethostbyname (XSTRING (host)->data);
if (host_info_ptr == 0)
/* Attempt to interpret host as numeric inet address */
{
- numeric_addr = inet_addr (XSTRING (host)->data);
- if (numeric_addr == -1)
+ numeric_addr = inet_addr ((char *) XSTRING (host)->data);
+ if (NUMERIC_ADDR_ERROR)
error ("Unknown host \"%s\"", XSTRING (host)->data);
host_info_ptr = &host_info;
if (s < 0)
report_file_error ("error creating socket", Fcons (name, Qnil));
+ /* Kernel bugs (on Ultrix at least) cause lossage (not just EINTR)
+ when connect is interrupted. So let's not let it get interrupted.
+ Note we do not turn off polling, because polling is only used
+ when not interrupt_input, and thus not normally used on the systems
+ which have this bug. On systems which use polling, there's no way
+ to quit if polling is turned off. */
+ if (interrupt_input)
+ unrequest_sigio ();
+
loop:
if (connect (s, (struct sockaddr *) &address, sizeof address) == -1)
{
if (errno == EINTR)
goto loop;
close (s);
+
+ if (interrupt_input)
+ request_sigio ();
+
errno = xerrno;
report_file_error ("connection failed",
Fcons (host, Fcons (name, Qnil)));
}
+ if (interrupt_input)
+ request_sigio ();
+
+#else /* TERM */
+ s = connect_server (0);
+ if (s < 0)
+ report_file_error ("error creating socket", Fcons (name, Qnil));
+ send_command (s, C_PORT, 0, "%s:%d", XSTRING (host)->data, ntohs (port));
+ send_command (s, C_DUMB, 1, 0);
+#endif /* TERM */
+
inch = s;
outch = dup (s);
if (outch < 0)
XPROCESS (proc)->filter = Qnil;
XPROCESS (proc)->command = Qnil;
XPROCESS (proc)->pid = Qnil;
- XFASTINT (XPROCESS (proc)->infd) = s;
- XFASTINT (XPROCESS (proc)->outfd) = outch;
+ XSET (XPROCESS (proc)->infd, Lisp_Int, s);
+ XSET (XPROCESS (proc)->outfd, Lisp_Int, outch);
XPROCESS (proc)->status = Qrun;
FD_SET (inch, &input_wait_mask);
register int inchannel, outchannel;
register struct Lisp_Process *p = XPROCESS (proc);
- inchannel = XFASTINT (p->infd);
- outchannel = XFASTINT (p->outfd);
+ inchannel = XINT (p->infd);
+ outchannel = XINT (p->outfd);
- if (inchannel)
+ if (inchannel >= 0)
{
/* Beware SIGCHLD hereabouts. */
flush_pending_output (inchannel);
}
#else
close (inchannel);
- if (outchannel && outchannel != inchannel)
+ if (outchannel >= 0 && outchannel != inchannel)
close (outchannel);
#endif
- XFASTINT (p->infd) = 0;
- XFASTINT (p->outfd) = 0;
+ XSET (p->infd, Lisp_Int, -1);
+ XSET (p->outfd, Lisp_Int, -1);
chan_process[inchannel] = Qnil;
FD_CLR (inchannel, &input_wait_mask);
}
process = chan_process[i];
if (!NILP (process))
{
- int in = XFASTINT (XPROCESS (process)->infd);
- int out = XFASTINT (XPROCESS (process)->outfd);
- if (in)
+ int in = XINT (XPROCESS (process)->infd);
+ int out = XINT (XPROCESS (process)->outfd);
+ if (in >= 0)
close (in);
- if (out && in != out)
+ if (out >= 0 && in != out)
close (out);
}
}
Lisp_Object proc;
EMACS_TIME timeout, end_time, garbage;
SELECT_TYPE Atemp;
- int wait_channel = 0;
+ int wait_channel = -1;
struct Lisp_Process *wait_proc = 0;
int got_some_input = 0;
Lisp_Object *wait_for_cell = 0;
if (XTYPE (read_kbd) == Lisp_Process)
{
wait_proc = XPROCESS (read_kbd);
- wait_channel = XFASTINT (wait_proc->infd);
+ wait_channel = XINT (wait_proc->infd);
XFASTINT (read_kbd) = 0;
}
EMACS_ADD_TIME (end_time, end_time, timeout);
}
+ /* It would not be safe to call this below,
+ where we call redisplay_preserve_echo_area. */
+ prepare_menu_bars ();
+
while (1)
{
/* If calling from keyboard input, do not quit
if (select (MAXDESC, &Atemp, 0, 0, &timeout) <= 0)
{
/* It's okay for us to do this and then continue with
- the loop, since timeout has already been zeroed out. */
+ the loop, since timeout has already been zeroed out. */
clear_waiting_for_input ();
status_notify ();
}
redisplay_preserve_echo_area ();
if (XINT (read_kbd) && detect_input_pending ())
- nfds = 0;
+ {
+ nfds = 0;
+ FD_ZERO (&Available);
+ }
else
nfds = select (MAXDESC, &Available, 0, 0, &timeout);
the ptc file descriptor is automatically closed,
yielding EBADF here or at select() call above.
So, SIGHUP is ignored (see def of PTY_TTY_NAME_SPRINTF
- in m-ibmrt-aix.h), and here we just ignore the select error.
+ in m/ibmrt-aix.h), and here we just ignore the select error.
Cleanup occurs c/o status_notify after SIGCLD. */
FD_ZERO (&Available); /* Cannot depend on values returned */
#else
#endif
}
else
- error("select error: %s", sys_errlist[xerrno]);
+ error("select error: %s", strerror (xerrno));
}
#if defined(sun) && !defined(USG5_4)
else if (nfds > 0 && FD_ISSET (keyboard_descriptor, &Available)
if (XINT (read_kbd) || wait_for_cell)
do_pending_window_change ();
- /* Check for data from a process or a command channel */
- for (channel = FIRST_PROC_DESC; channel < MAXDESC; channel++)
+ /* Check for data from a process. */
+ /* Really FIRST_PROC_DESC should be 0 on Unix,
+ but this is safer in the short run. */
+ for (channel = keyboard_descriptor == 0 ? FIRST_PROC_DESC : 0;
+ channel < MAXDESC; channel++)
{
if (FD_ISSET (channel, &Available))
{
waiting. */
if (wait_channel == channel)
{
- wait_channel = 0;
+ wait_channel = -1;
time_limit = -1;
got_some_input = 1;
}
#ifdef VMS
start_vms_process_read (vs);
#endif
- unbind_to (count);
+ unbind_to (count, Qnil);
return nchars;
}
at the current end-of-output marker,
thus preserving logical ordering of input and output. */
if (XMARKER (p->mark)->buffer)
- SET_PT (marker_position (p->mark));
+ SET_PT (clip_to_bounds (BEGV, marker_position (p->mark), ZV));
else
SET_PT (ZV);
if (this > 500)
this = 500;
old_sigpipe = (SIGTYPE (*) ()) signal (SIGPIPE, send_process_trap);
- rv = write (XFASTINT (XPROCESS (proc)->outfd), buf, this);
+ rv = write (XINT (XPROCESS (proc)->outfd), buf, this);
signal (SIGPIPE, old_sigpipe);
if (rv < 0)
{
if (!EQ (p->childp, Qt))
error ("Process %s is not a subprocess",
XSTRING (p->name)->data);
- if (!XFASTINT (p->infd))
+ if (XINT (p->infd) < 0)
error ("Process %s is not active",
XSTRING (p->name)->data);
switch (signo)
{
case SIGINT:
- tcgetattr (XFASTINT (p->infd), &t);
+ tcgetattr (XINT (p->infd), &t);
send_process (proc, &t.c_cc[VINTR], 1);
return;
case SIGQUIT:
- tcgetattr (XFASTINT (p->infd), &t);
+ tcgetattr (XINT (p->infd), &t);
send_process (proc, &t.c_cc[VQUIT], 1);
return;
case SIGTSTP:
- tcgetattr (XFASTINT (p->infd), &t);
-#ifdef VSWTCH
+ tcgetattr (XINT (p->infd), &t);
+#if defined (VSWTCH) && !defined (IRIX5)
send_process (proc, &t.c_cc[VSWTCH], 1);
#else
send_process (proc, &t.c_cc[VSUSP], 1);
switch (signo)
{
case SIGINT:
- ioctl (XFASTINT (p->infd), TIOCGETC, &c);
+ ioctl (XINT (p->infd), TIOCGETC, &c);
send_process (proc, &c.t_intrc, 1);
return;
case SIGQUIT:
- ioctl (XFASTINT (p->infd), TIOCGETC, &c);
+ ioctl (XINT (p->infd), TIOCGETC, &c);
send_process (proc, &c.t_quitc, 1);
return;
#ifdef SIGTSTP
case SIGTSTP:
- ioctl (XFASTINT (p->infd), TIOCGLTC, &lc);
+ ioctl (XINT (p->infd), TIOCGLTC, &lc);
send_process (proc, &lc.t_suspc, 1);
return;
#endif /* ! defined (SIGTSTP) */
switch (signo)
{
case SIGINT:
- ioctl (XFASTINT (p->infd), TCGETA, &t);
+ ioctl (XINT (p->infd), TCGETA, &t);
send_process (proc, &t.c_cc[VINTR], 1);
return;
case SIGQUIT:
- ioctl (XFASTINT (p->infd), TCGETA, &t);
+ ioctl (XINT (p->infd), TCGETA, &t);
send_process (proc, &t.c_cc[VQUIT], 1);
return;
#ifdef SIGTSTP
case SIGTSTP:
- ioctl (XFASTINT (p->infd), TCGETA, &t);
+ ioctl (XINT (p->infd), TCGETA, &t);
send_process (proc, &t.c_cc[VSWTCH], 1);
return;
#endif /* ! defined (SIGTSTP) */
if (!NILP (p->subtty))
err = ioctl (XFASTINT (p->subtty), TIOCGPGRP, &gid);
else
- err = ioctl (XFASTINT (p->infd), TIOCGPGRP, &gid);
+ err = ioctl (XINT (p->infd), TIOCGPGRP, &gid);
#ifdef pfa
if (err == -1)
sys$forcex (&(XFASTINT (p->pid)), 0, 1);
whoosh:
#endif
- flush_pending_output (XFASTINT (p->infd));
+ flush_pending_output (XINT (p->infd));
break;
}
/* gid may be a pid, or minus a pgrp's number */
#ifdef TIOCSIGSEND
if (!NILP (current_group))
- ioctl (XFASTINT (p->infd), TIOCSIGSEND, signo);
+ ioctl (XINT (p->infd), TIOCSIGSEND, signo);
else
{
gid = - XFASTINT (p->pid);
#ifdef DID_REMOTE
{
char buf[1];
- write (XFASTINT (XPROCESS (proc)->outfd), buf, 0);
+ write (XINT (XPROCESS (proc)->outfd), buf, 0);
}
#else /* did not do TOICREMOTE */
#ifdef VMS
send_process (proc, "\004", 1);
else
{
- close (XPROCESS (proc)->outfd);
- XFASTINT (XPROCESS (proc)->outfd) = open (NULL_DEVICE, O_WRONLY);
+ close (XINT (XPROCESS (proc)->outfd));
+ XSET (XPROCESS (proc)->outfd, Lisp_Int, open (NULL_DEVICE, O_WRONLY));
}
#endif /* VMS */
#endif /* did not do TOICREMOTE */
{
if (NETCONN_P (proc))
deactivate_process (proc);
- else if (XFASTINT (XPROCESS (proc)->infd))
+ else if (XINT (XPROCESS (proc)->infd) >= 0)
process_send_signal (proc, SIGHUP, Qnil, 1);
}
}
/* If process has terminated, stop waiting for its output. */
if (WIFSIGNALED (w) || WIFEXITED (w))
- if (XFASTINT (p->infd))
- FD_CLR (XFASTINT (p->infd), &input_wait_mask);
+ if (XINT (p->infd) >= 0)
+ FD_CLR (XINT (p->infd), &input_wait_mask);
/* Tell wait_reading_process_input that it needs to wake up and
look around. */
if (WIFEXITED (w))
synch_process_retcode = WRETCODE (w);
else if (WIFSIGNALED (w))
+ {
+ int code = WTERMSIG (w);
+ char *signame = 0;
+
+ if (code < NSIG)
+ {
#ifndef VMS
- synch_process_death = (char *) sys_siglist[WTERMSIG (w)];
+ signame = sys_siglist[code];
#else
- synch_process_death = sys_errlist[WTERMSIG (w)];
+ signame = sys_errlist[code];
#endif
+ }
+ if (signame == 0)
+ signame = "unknown";
+
+ synch_process_death = signame;
+ }
/* Tell wait_reading_process_input that it needs to wake up and
look around. */
/* Inhibit quit so that random quits don't screw up a running filter. */
specbind (Qinhibit_quit, Qt);
call2 (sentinel, proc, reason);
- unbind_to (count);
+ unbind_to (count, Qnil);
}
/* Report all recent events of a change in process status
XSETINT (p->update_tick, XINT (p->tick));
/* If process is still active, read any output that remains. */
- if (XFASTINT (p->infd))
+ if (XINT (p->infd) >= 0)
while (! EQ (p->filter, Qt)
- && read_process_output (proc, XFASTINT (p->infd)) > 0);
+ && read_process_output (proc, XINT (p->infd)) > 0);
buffer = p->buffer;
/* It's infinite. */
timeout_p = 0;
+ /* This must come before stop_polling. */
+ prepare_menu_bars ();
+
/* Turn off periodic alarms (in case they are in use)
because the select emulator uses alarms. */
stop_polling ();