/* 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 <signal.h>
-#include "config.h"
+#include <config.h>
/* This file is split into two parts by the following preprocessor
conditional. The 'then' clause contains all of the support for
#include <sys/types.h> /* some typedefs are used in sys/file.h */
#include <sys/file.h>
#include <sys/stat.h>
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
#ifdef HAVE_SOCKETS /* TCP connection support, if kernel can do it */
#include <sys/socket.h>
#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 "commands.h"
#include "frame.h"
+Lisp_Object Qprocessp;
Lisp_Object Qrun, Qstop, Qsignal, Qopen, Qclosed;
/* Qexit is declared and initialized in eval.c. */
#include "syssignal.h"
-/* Define the structure that the wait system call stores.
- On many systems, there is a structure defined for this.
- But on vanilla-ish USG systems there is not. */
+#include "syswait.h"
-#ifndef VMS
-#ifndef WAITTYPE
-#if (!defined (BSD) && !defined (UNIPLUS) && !defined (STRIDE) && !(defined (HPUX) && !defined (NOMULTIPLEJOBS)) && !defined (HAVE_WAIT_HEADER)) || defined (LINUX)
-#define WAITTYPE int
-#define WIFSTOPPED(w) ((w&0377) == 0177)
-#define WIFSIGNALED(w) ((w&0377) != 0177 && (w&~0377) == 0)
-#define WIFEXITED(w) ((w&0377) == 0)
-#define WRETCODE(w) (w >> 8)
-#define WSTOPSIG(w) (w >> 8)
-#define WTERMSIG(w) (w & 0377)
-#ifndef WCOREDUMP
-#define WCOREDUMP(w) ((w&0200) != 0)
-#endif
-#else
-#ifdef BSD4_1
-#include <wait.h>
-#else
-#include <sys/wait.h>
-#endif /* not BSD 4.1 */
-
-#define WAITTYPE union wait
-#define WRETCODE(w) w.w_retcode
-#define WCOREDUMP(w) w.w_coredump
-
-#ifdef HPUX
-/* HPUX version 7 has broken definitions of these. */
-#undef WTERMSIG
-#undef WSTOPSIG
-#undef WIFSTOPPED
-#undef WIFSIGNALED
-#undef WIFEXITED
-#endif
-
-#ifndef WTERMSIG
-#define WTERMSIG(w) w.w_termsig
-#endif
-#ifndef WSTOPSIG
-#define WSTOPSIG(w) w.w_stopsig
-#endif
-#ifndef WIFSTOPPED
-#define WIFSTOPPED(w) (WTERMSIG (w) == 0177)
-#endif
-#ifndef WIFSIGNALED
-#define WIFSIGNALED(w) (WTERMSIG (w) != 0177 && (WSTOPSIG (w)) == 0)
-#endif
-#ifndef WIFEXITED
-#define WIFEXITED(w) (WTERMSIG (w) == 0)
-#endif
-#endif /* BSD or UNIPLUS or STRIDE */
-#endif /* no WAITTYPE */
-#else /* VMS */
-#define WAITTYPE int
-#define WIFSTOPPED(w) 0
-#define WIFSIGNALED(w) 0
-#define WIFEXITED(w) ((w) != -1)
-#define WRETCODE(w) (w)
-#define WSTOPSIG(w) (w)
-#define WCOREDUMP(w) 0
-#define WTERMSIG(w) (w)
-#include <ssdef.h>
-#include <iodef.h>
-#include <clidef.h>
-#include "vmsproc.h"
-#endif /* VMS */
-
-extern errno;
-extern sys_nerr;
+extern int errno;
+extern char *strerror ();
+#ifdef VMS
extern char *sys_errlist[];
+#endif
+#ifndef SYS_SIGLIST_DECLARED
#ifndef VMS
#ifndef BSD4_1
#ifndef LINUX
extern char *sys_siglist[];
-#endif
-#else
+#endif /* not LINUX */
+#else /* BSD4_1 */
char *sys_siglist[] =
{
"bum signal!!",
};
#endif
#endif /* VMS */
+#endif /* ! SYS_SIGLIST_DECLARED */
/* t means use pty, nil means use a pipe,
maybe other values to come. */
-Lisp_Object Vprocess_connection_type;
+static Lisp_Object Vprocess_connection_type;
#ifdef SKTPAIR
#ifndef HAVE_SOCKETS
#endif /* SKTPAIR */
/* Number of events of change of status of a process. */
-int process_tick;
+static int process_tick;
/* Number of events for which the user or sentinel has been notified. */
-int update_tick;
+static int update_tick;
#ifdef FD_SET
/* We could get this from param.h, but better not to depend on finding that.
/* Mask of bits indicating the descriptors that we wait for input on */
-SELECT_TYPE input_wait_mask;
+static SELECT_TYPE input_wait_mask;
-int delete_exited_processes;
+/* Descriptor to use for keyboard input. */
+static int keyboard_descriptor;
+
+/* Nonzero means delete a process right away if it exits. */
+static int delete_exited_processes;
/* Indexed by descriptor, gives the process (if any) for that descriptor */
Lisp_Object chan_process[MAXDESC];
/* Alist of elements (NAME . PROCESS) */
Lisp_Object Vprocess_alist;
-Lisp_Object Qprocessp;
-
-Lisp_Object get_process ();
-
/* Buffered-ahead input char from process, indexed by channel.
-1 means empty (no char is buffered).
Used on sys V where the only way to tell if there is any
output from the process is to read at least one char.
Always -1 on systems that support FIONREAD. */
-int proc_buffered_char[MAXDESC];
+static int proc_buffered_char[MAXDESC];
+
+static Lisp_Object get_process ();
+
+/* Maximum number of bytes to send to a pty without an eof. */
+static int pty_max_bytes;
\f
/* Compute the Lisp form of the process status, p->status, from
the numeric status that was returned by `wait'. */
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;
{
- register Lisp_Object proc;
- if (NILP (name))
- proc = Fget_buffer_process (Fcurrent_buffer ());
+ register Lisp_Object proc, obj;
+ if (STRINGP (name))
+ {
+ obj = Fget_process (name);
+ if (NILP (obj))
+ obj = Fget_buffer (name);
+ if (NILP (obj))
+ error ("Process %s does not exist", XSTRING (name)->data);
+ }
+ else if (NILP (name))
+ obj = Fcurrent_buffer ();
else
+ obj = name;
+
+ /* Now obj should be either a buffer object or a process object.
+ */
+ if (BUFFERP (obj))
{
- proc = Fget_process (name);
+ proc = Fget_buffer_process (obj);
if (NILP (proc))
- proc = Fget_buffer_process (Fget_buffer (name));
+ error ("Buffer %s has no process", XSTRING (XBUFFER (obj)->name)->data);
}
-
- if (!NILP (proc))
- return proc;
-
- if (NILP (name))
- error ("Current buffer has no process");
else
- error ("Process %s does not exist", XSTRING (name)->data);
- /* NOTREACHED */
+ {
+ CHECK_PROCESS (obj, 0);
+ proc = obj;
+ }
+ return proc;
}
DEFUN ("delete-process", Fdelete_process, Sdelete_process, 1, 1, 0,
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. */
nil -- if arg is a process name and no such process exists.\n\
PROCESS may be a process, a buffer, the name of a process or buffer, or\n\
nil, indicating the current buffer's process.")
-/* command -- for a command channel opened to Emacs by another process.\n\
- external -- for an i/o channel opened to Emacs by another process.\n\ */
(proc)
register Lisp_Object proc;
{
DEFUN ("set-process-filter", Fset_process_filter, Sset_process_filter,
2, 2, 0,
"Give PROCESS the filter function FILTER; nil means no filter.\n\
+t means stop accepting output from the process.\n\
When a process has a filter, each time it does output\n\
the entire string of output is passed to the filter.\n\
The filter gets two arguments: the process and the string of output.\n\
register Lisp_Object proc, filter;
{
CHECK_PROCESS (proc, 0);
+ if (EQ (filter, Qt))
+ FD_CLR (XINT (XPROCESS (proc)->infd), &input_wait_mask);
+ else if (EQ (XPROCESS (proc)->filter, Qt))
+ FD_SET (XINT (XPROCESS (proc)->infd), &input_wait_mask);
XPROCESS (proc)->filter = filter;
return filter;
}
DEFUN ("process-kill-without-query", Fprocess_kill_without_query,
Sprocess_kill_without_query, 1, 2, 0,
"Say no query needed if PROCESS is running when Emacs is exited.\n\
-Optional second argument if non-nill says to require a query.\n\
+Optional second argument if non-nil says to require a query.\n\
Value is t if a query was formerly required.")
(proc, value)
register Lisp_Object proc, value;
return Fnull (tem);
}
+
+#if 0 /* Turned off because we don't currently record this info
+ in the process. Perhaps add it. */
+DEFUN ("process-connection", Fprocess_connection, Sprocess_connection, 1, 1, 0,
+ "Return the connection type of `PROCESS'.\n\
+The value is `nil' for a pipe,\n\
+`t' or `pty' for a pty, or `stream' for a socket connection.")
+ (process)
+ Lisp_Object process;
+{
+ return XPROCESS (process)->type;
+}
+#endif
\f
Lisp_Object
list_processes_1 ()
#else /* not VMS */
new_argv = (unsigned char **) alloca ((nargs - 1) * sizeof (char *));
- for (i = 3; i < nargs; i++)
- {
- tem = args[i];
- CHECK_STRING (tem, i);
- new_argv[i - 2] = XSTRING (tem)->data;
- }
- new_argv[i - 2] = 0;
- new_argv[0] = XSTRING (program)->data;
-
/* If program file name is not absolute, search our path for it */
- if (new_argv[0][0] != '/')
+ if (XSTRING (program)->data[0] != '/')
{
+ struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
+
tem = Qnil;
+ GCPRO4 (name, program, buffer, current_dir);
openp (Vexec_path, program, EXEC_SUFFIXES, &tem, 1);
+ UNGCPRO;
if (NILP (tem))
report_file_error ("Searching for program", Fcons (program, Qnil));
new_argv[0] = XSTRING (tem)->data;
}
+ else
+ new_argv[0] = XSTRING (program)->data;
+
+ for (i = 3; i < nargs; i++)
+ {
+ tem = args[i];
+ CHECK_STRING (tem, i);
+ new_argv[i - 2] = XSTRING (tem)->data;
+ }
+ new_argv[i - 2] = 0;
#endif /* not VMS */
proc = make_process (name);
/* 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 && xforkin >= 0)
+ {
+ /* 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 (XINT (read_kbd) >= 0)
QUIT;
+ /* Exit now if the cell we're waiting for became non-nil. */
+ if (wait_for_cell && ! NILP (*wait_for_cell))
+ break;
+
/* Compute time from now till when time limit is up */
/* Exit if already run out */
if (time_limit == -1)
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 ();
}
/* Wait till there is something to do */
Available = input_wait_mask;
- if (! XINT (read_kbd) && wait_for_cell == 0)
- FD_CLR (0, &Available);
+ /* We used to have && wait_for_cell == 0
+ but that led to lossage handling selection_request events:
+ within one, we would start to handle another. */
+ if (! XINT (read_kbd))
+ FD_CLR (keyboard_descriptor, &Available);
/* If frame size has changed or the window is newly mapped,
redisplay now, before we start to wait. There is a race
condition here; if a SIGIO arrives between now and the select
and indicates that a frame is trashed, the select may block
displaying a trashed screen. */
- if (frame_garbaged)
+ if (frame_garbaged && do_display)
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 (0, &Available) && interrupt_input)
+ else if (nfds > 0 && FD_ISSET (keyboard_descriptor, &Available)
+ && interrupt_input)
/* System sometimes fails to deliver SIGIO.
David J. Mackenzie says that Emacs doesn't compile under
/* If there is any, return immediately
to give it higher priority than subprocesses */
- if (XINT (read_kbd) && detect_input_pending ())
+ /* We used to do his if wait_for_cell,
+ but that caused infinite recursion in selection request events. */
+ if ((XINT (read_kbd))
+ && detect_input_pending ())
{
swallow_events ();
if (detect_input_pending ())
In that case, there really is no input and no SIGIO,
but select says there is input. */
- if (XINT (read_kbd) && interrupt_input && (FD_ISSET (fileno (stdin), &Available)))
+ if (XINT (read_kbd) && interrupt_input
+ && (FD_ISSET (keyboard_descriptor, &Available)))
kill (0, SIGIO);
#endif
/* If checking input just got us a size-change event from X,
obey it now if we should. */
- if (XINT (read_kbd))
+ 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);
{
int this = len;
SIGTYPE (*old_sigpipe)();
+ int flush_pty = 0;
+
+ if (pty_max_bytes == 0)
+ {
+#if defined (HAVE_FPATHCONF) && defined (_PC_MAX_CANON)
+ pty_max_bytes = fpathconf (XFASTINT (XPROCESS (proc)->outfd),
+ _PC_MAX_CANON);
+#else
+ pty_max_bytes = 250;
+#endif
+ }
+
+ /* Don't send more than pty_max_bytes bytes at a time. */
+ /* Subtract 1 to leave room for the EOF. */
+ if (this >= pty_max_bytes && XPROCESS (proc)->pty_flag != 0)
+ this = pty_max_bytes - 1;
- /* Don't send more than 500 bytes at a time. */
- 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);
+
+ /* If we sent just part of the string, put in an EOF
+ to force it through, before we send the rest. */
+ if (this < len)
+ Fprocess_send_eof (proc);
+
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
status_notify ()
{
register Lisp_Object proc, buffer;
- Lisp_Object tail = Qnil;
- Lisp_Object msg = Qnil;
+ Lisp_Object tail, msg;
struct gcpro gcpro1, gcpro2;
+ tail = Qnil;
+ msg = Qnil;
/* We need to gcpro tail; if read_process_output calls a filter
which deletes a process and removes the cons to which tail points
from Vprocess_alist, and then causes a GC, tail is an unprotected
XSETINT (p->update_tick, XINT (p->tick));
/* If process is still active, read any output that remains. */
- if (XFASTINT (p->infd))
- while (read_process_output (proc, XFASTINT (p->infd)) > 0);
+ if (XINT (p->infd) >= 0)
+ while (! EQ (p->filter, Qt)
+ && read_process_output (proc, XINT (p->infd)) > 0);
buffer = p->buffer;
when a process becomes runnable. */
else if (!EQ (symbol, Qrun) && !NILP (buffer))
{
- Lisp_Object ro = XBUFFER (buffer)->read_only;
- Lisp_Object tem;
+ Lisp_Object ro, tem;
struct buffer *old = current_buffer;
int opoint;
+ ro = XBUFFER (buffer)->read_only;
+
/* Avoid error if buffer is deleted
(probably that's why the process is dead, too) */
if (NILP (XBUFFER (buffer)->name))
#endif
FD_ZERO (&input_wait_mask);
- FD_SET (0, &input_wait_mask);
+
+ keyboard_descriptor = 0;
+ FD_SET (keyboard_descriptor, &input_wait_mask);
+
Vprocess_alist = Qnil;
for (i = 0; i < MAXDESC; i++)
{
proc_buffered_char[i] = -1;
}
}
-#if 0
-DEFUN ("process-connection", Fprocess_connection, Sprocess_connection, 0, 1, 0,
- "Return the connection type of `PROCESS'. This can be nil (pipe),\n\
-t or pty (pty) or stream (socket connection).")
- (process)
- Lisp_Object process;
+
+/* From now on, assume keyboard input comes from descriptor DESC. */
+
+void
+change_keyboard_wait_descriptor (desc)
+ int desc;
{
- return XPROCESS (process)->type;
+ FD_CLR (keyboard_descriptor, &input_wait_mask);
+ keyboard_descriptor = desc;
+ FD_SET (keyboard_descriptor, &input_wait_mask);
}
-#endif
+
syms_of_process ()
{
#ifdef HAVE_SOCKETS
`subprocesses' isn't defined.
do_display != 0 means redisplay should be done to show subprocess
- output that arrives. This version of the function ignores it.
+ output that arrives.
Return true iff we received input from any process. */
/* 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 ();
/* If a frame has been newly mapped and needs updating,
reprocess its display stuff. */
- if (frame_garbaged)
+ if (frame_garbaged && do_display)
redisplay_preserve_echo_area ();
if (XINT (read_kbd) && detect_input_pending ())
DEFUN ("get-buffer-process", Fget_buffer_process, Sget_buffer_process, 1, 1, 0,
- "Return the (or, a) process associated with BUFFER.\n\
-This copy of Emacs has not been built to support subprocesses, so this\n\
-function always returns nil.")
+ /* Don't confuse make-docfile by having two doc strings for this function.
+ make-docfile does not pay attention to #if, for good reason! */
+ 0)
(name)
register Lisp_Object name;
{