]> code.delx.au - gnu-emacs/blobdiff - src/process.c
* Makefile.in (doxemacs, dotemacs): Explicitly pass along the CC
[gnu-emacs] / src / process.c
index 2265c2c34db8cbfdae2fea99d49631da41b357d6..35a30540c02f36dc2faddf8442b4c35c5968534a 100644 (file)
@@ -48,18 +48,10 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
 #if defined(BSD) || defined(STRIDE)
 #include <sys/ioctl.h>
-#if !defined (O_NDELAY) && defined (HAVE_PTYS)
+#if !defined (O_NDELAY) && defined (HAVE_PTYS) && !defined(USG5)
 #include <fcntl.h>
 #endif /* HAVE_PTYS and no O_NDELAY */
 #endif /* BSD or STRIDE */
-#ifdef USG
-#ifdef HAVE_TERMIOS
-#include <termios.h>
-#else
-#include <termio.h>
-#endif
-#include <fcntl.h>
-#endif /* USG */
 
 #ifdef NEED_BSDTTY
 #include <bsdtty.h>
@@ -70,7 +62,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #endif /* not IRIS */
 
 #include "systime.h"
-#include "systerm.h"
+#include "systty.h"
 
 #include "lisp.h"
 #include "window.h"
@@ -119,15 +111,16 @@ static Lisp_Object stream_process;
 #ifndef VMS
 #ifndef WAITTYPE
 #if !defined (BSD) && !defined (UNIPLUS) && !defined (STRIDE) && !(defined (HPUX) && !defined (NOMULTIPLEJOBS)) && !defined (HAVE_WAIT_HEADER)
-mis;tak-+;;:
 #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 WCOREDUMP(w) ((w&0200) != 0)
 #define WTERMSIG(w) (w & 0377)
+#ifndef WCOREDUMP
+#define WCOREDUMP(w) ((w&0200) != 0)
+#endif
 #else 
 #ifdef BSD4_1
 #include <wait.h>
@@ -283,6 +276,8 @@ int proc_buffered_char[MAXDESC];
 /* Compute the Lisp form of the process status, p->status, from
    the numeric status that was returned by `wait'.  */
 
+Lisp_Object status_convert ();
+
 update_status (p)
      struct Lisp_Process *p;
 {
@@ -335,7 +330,7 @@ decode_status (l, symbol, code, coredump)
       *symbol = XCONS (l)->car;
       tem = XCONS (l)->cdr;
       *code = XFASTINT (XCONS (tem)->car);
-      tem = XFASTINT (XCONS (tem)->cdr);
+      tem = XCONS (tem)->cdr;
       *coredump = !NILP (tem);
     }
 }
@@ -373,7 +368,6 @@ status_message (status)
 }
 \f
 #ifdef HAVE_PTYS
-static int pty_process;
 
 /* Open an available pty, returning a file descriptor.
    Return -1 on failure.
@@ -405,18 +399,13 @@ allocate_pty ()
       {
 #ifdef PTY_NAME_SPRINTF
        PTY_NAME_SPRINTF
-#else
-#ifdef HPUX
-       sprintf (pty_name, "/dev/ptym/pty%c%x", c, i);
-#else
-#ifdef RTU
-       sprintf (pty_name, "/dev/pty%x", i);
 #else
        sprintf (pty_name, "/dev/pty%c%x", c, i);
-#endif /* not RTU */
-#endif /* not HPUX */
 #endif /* no PTY_NAME_SPRINTF */
 
+#ifdef PTY_OPEN
+       PTY_OPEN;
+#else /* no PTY_OPEN */
 #ifdef IRIS
        /* Unusual IRIS code */
        *ptyv = open ("/dev/ptc", O_RDWR | O_NDELAY, 0);
@@ -424,7 +413,7 @@ allocate_pty ()
          return -1;
        if (fstat (fd, &stb) < 0)
          return -1;
-#else
+#else /* not IRIS */
        if (stat (pty_name, &stb) < 0)
          {
            failed_count++;
@@ -438,7 +427,8 @@ allocate_pty ()
 #else
        fd = open (pty_name, O_RDWR | O_NDELAY, 0);
 #endif
-#endif /* IRIS */
+#endif /* not IRIS */
+#endif /* no PTY_OPEN */
 
        if (fd >= 0)
          {
@@ -446,21 +436,8 @@ allocate_pty ()
               this avoids a nasty yet stupid bug in rlogins */
 #ifdef PTY_TTY_NAME_SPRINTF
            PTY_TTY_NAME_SPRINTF
-#else
-           /* TODO: In version 19, make these special cases use the macro above.  */
-#ifdef HPUX
-            sprintf (pty_name, "/dev/pty/tty%c%x", c, i);
-#else
-#ifdef RTU
-            sprintf (pty_name, "/dev/ttyp%x", i);
-#else
-#ifdef IRIS
-           sprintf (pty_name, "/dev/ttyq%d", minor (stb.st_rdev));
 #else
             sprintf (pty_name, "/dev/tty%c%x", c, i);
-#endif /* not IRIS */
-#endif /* not RTU */
-#endif /* not HPUX */
 #endif /* no PTY_TTY_NAME_SPRINTF */
 #ifndef UNIPLUS
            if (access (pty_name, 6) != 0)
@@ -579,7 +556,10 @@ BUFFER may be a buffer or the name of one.")
   return Qnil;
 }
 
-/* This is how commands for the user decode process arguments */
+/* This is how commands for the user decode process arguments.  It
+   accepts a process, a process name, a buffer, a buffer name, or nil.
+   Buffers denote the first process in the buffer, and nil denotes the
+   current buffer.  */
 
 Lisp_Object
 get_process (name)
@@ -607,7 +587,8 @@ get_process (name)
 
 DEFUN ("delete-process", Fdelete_process, Sdelete_process, 1, 1, 0,
   "Delete PROCESS: kill it and forget about it immediately.\n\
-PROCESS may be a process or the name of one, or a buffer name.")
+PROCESS may be a process, a buffer, the name of a process or buffer, or\n\
+nil, indicating the current buffer's process.")
   (proc)
      register Lisp_Object proc;
 {
@@ -640,7 +621,9 @@ exit -- for a process that has exited.\n\
 signal -- for a process that has got a fatal signal.\n\
 open -- for a network stream connection that is open.\n\
 closed -- for a network stream connection that is closed.\n\
-nil -- if arg is a process name and no such process exists.")
+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)
@@ -648,7 +631,7 @@ nil -- if arg is a process name and no such process exists.")
 {
   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);
@@ -1218,6 +1201,11 @@ create_process (process, new_argv)
        /* First, disconnect its current controlling terminal.  */
 #ifdef HAVE_SETSID
        setsid ();
+#ifdef TIOCSCTTY
+       /* Make the pty's terminal the controlling terminal.  */
+       if (pty_flag && (ioctl (xforkin, TIOCSCTTY, 0) < 0))
+         abort ();
+#endif
 #else /* not HAVE_SETSID */
 #ifdef USG
        /* It's very important to call setpgrp() here and no time
@@ -1279,7 +1267,9 @@ create_process (process, new_argv)
 #if defined (BSD) || defined (UNIPLUS) || defined (HPUX)
        sigsetmask (SIGEMPTYMASK);
 #else /* ordinary USG */
+#if 0
        signal (SIGCHLD, sigchld);
+#endif
 #endif /* ordinary USG */
 #endif /* not BSD4_1 */
 #endif /* SIGCHLD */
@@ -1571,6 +1561,8 @@ Return non-nil iff we received any output before the timeout expired.")
          }
       }
     }
+  else
+    useconds = 0;
 
   if (! NILP (timeout))
     {
@@ -1723,11 +1715,11 @@ wait_reading_process_input (time_limit, microsecs, read_kbd, do_display)
       if (! XINT (read_kbd))
        FD_CLR (0, &Available);
 
-      /* If screen size has changed or the window is newly mapped,
+      /* 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 screen is trashed, we lose.  */
-      if (screen_garbaged)
+        and indicates that a frame is trashed, we lose.  */
+      if (frame_garbaged)
        redisplay_preserve_echo_area ();
 
       if (XINT (read_kbd) && detect_input_pending ())
@@ -1749,6 +1741,12 @@ wait_reading_process_input (time_limit, microsecs, read_kbd, do_display)
        {
          if (xerrno == EINTR)
            FD_ZERO (&Available);
+#ifdef __ultrix__
+         /* Ultrix select seems to return ENOMEM when it is interrupted.
+            Treat it just like EINTR.  Bleah.  -JimB  */
+         else if (xerrno == ENOMEM)
+           FD_ZERO (&Available);
+#endif
 #ifdef ALLIANT
          /* This happens for no known reason on ALLIANT.
             I am guessing that this is the right response. -- RMS.  */
@@ -1807,7 +1805,7 @@ wait_reading_process_input (time_limit, microsecs, read_kbd, do_display)
          Available &= ~(ChannelMask (comm_server));
          create_commchan ();
        }
-#endif vipc
+#endif /* vipc */
 
       if (! wait_proc)
        got_some_input |= nfds > 0;
@@ -2164,7 +2162,8 @@ send_process (proc, buf, len)
 DEFUN ("process-send-region", Fprocess_send_region, Sprocess_send_region,
   3, 3, 0,
   "Send current contents of region as input to PROCESS.\n\
-PROCESS may be a process name or an actual process.\n\
+PROCESS may be a process, a buffer, the name of a process or buffer, or\n\
+nil, indicating the current buffer's process.\n\
 Called from program, takes three arguments, PROCESS, START and END.\n\
 If the region is more than 500 characters long,\n\
 it is sent in several bunches.  This may happen even for shorter regions.\n\
@@ -2190,7 +2189,8 @@ Output from processes can arrive in between bunches.")
 DEFUN ("process-send-string", Fprocess_send_string, Sprocess_send_string,
   2, 2, 0,
   "Send PROCESS the contents of STRING as input.\n\
-PROCESS may be a process name or an actual process.\n\
+PROCESS may be a process, a buffer, the name of a process or buffer, or\n\
+nil, indicating the current buffer's process.\n\
 If STRING is more than 500 characters long,\n\
 it is sent in several bunches.  This may happen even for shorter strings.\n\
 Output from processes can arrive in between bunches.")
@@ -2211,6 +2211,7 @@ Output from processes can arrive in between bunches.")
    If NOMSG is zero, insert signal-announcements into process's buffers
    right away.  */
 
+static void
 process_send_signal (process, signo, current_group, nomsg)
      Lisp_Object process;
      int signo;
@@ -2235,7 +2236,6 @@ process_send_signal (process, signo, current_group, nomsg)
   if (NILP (p->pty_flag))
     current_group = Qnil;
 
-#ifdef TIOCGPGRP               /* Not sure about this! (fnf) */
   /* If we are using pgrps, get a pgrp number and make it negative.  */
   if (!NILP (current_group))
     {
@@ -2250,45 +2250,49 @@ process_send_signal (process, signo, current_group, nomsg)
        case SIGINT:
          ioctl (XFASTINT (p->infd), TIOCGETC, &c);
          send_process (proc, &c.t_intrc, 1);
-         return Qnil;
+         return;
        case SIGQUIT:
          ioctl (XFASTINT (p->infd), TIOCGETC, &c);
          send_process (proc, &c.t_quitc, 1);
-         return Qnil;
+         return;
+#ifdef SIGTSTP
        case SIGTSTP:
          ioctl (XFASTINT (p->infd), TIOCGLTC, &lc);
          send_process (proc, &lc.t_suspc, 1);
-         return Qnil;
+         return;
+#endif /* SIGTSTP */
        }
-#endif /* have TIOCGLTC and have TIOCGETC */
+#endif /* ! defined (TIOCGLTC) && defined (TIOCGETC) */
       /* It is possible that the following code would work
         on other kinds of USG systems, not just on the IRIS.
         This should be tried in Emacs 19.  */
-#if defined (IRIS) && defined (HAVE_SETSID) /* Check for Irix, not older
-                                              systems.  */
+#if defined (USG)
       struct termio t;
       switch (signo)
        {
        case SIGINT:
          ioctl (XFASTINT (p->infd), TCGETA, &t);
          send_process (proc, &t.c_cc[VINTR], 1);
-         return Qnil;
+         return;
        case SIGQUIT:
          ioctl (XFASTINT (p->infd), TCGETA, &t);
          send_process (proc, &t.c_cc[VQUIT], 1);
-         return Qnil;
+         return;
+#ifdef SIGTSTP
        case SIGTSTP:
          ioctl (XFASTINT (p->infd), TCGETA, &t);
          send_process (proc, &t.c_cc[VSWTCH], 1);
-         return Qnil;
+         return;
+#endif
        }
-#endif /* IRIS and HAVE_SETSID */
+#endif /* ! defined (USG) */
 
+#ifdef TIOCGPGRP 
       /* Get the pgrp using the tty itself, if we have that.
         Otherwise, use the pty to get the pgrp.
         On pfa systems, saka@pfu.fujitsu.co.JP writes:
         "TICGPGRP symbol defined in sys/ioctl.h at E50.
-         But, TIOCGPGRP donot work on E50 ;-P work fine on E60"
+         But, TIOCGPGRP does not work on E50 ;-P works fine on E60"
         His patch indicates that if TIOCGPGRP returns an error, then
         we should just assume that p->pid is also the process group id.  */
       {
@@ -2302,20 +2306,20 @@ process_send_signal (process, signo, current_group, nomsg)
 #ifdef pfa
        if (err == -1)
          gid = - XFASTINT (p->pid);
-#endif
+#endif /* ! defined (pfa) */
       }
       if (gid == -1)
        no_pgrp = 1;
       else
        gid = - gid;
+#else /* ! defined (TIOCGPGRP ) */
+      /* Can't select pgrps on this system, so we know that
+        the child itself heads the pgrp.  */
+      gid = - XFASTINT (p->pid);
+#endif /* ! defined (TIOCGPGRP ) */
     }
   else
     gid = - XFASTINT (p->pid);
-#else /* not using pgrps */
-  /* Can't select pgrps on this system, so we know that
-     the child itself heads the pgrp.  */
-  gid = - XFASTINT (p->pid);
-#endif /* not using pgrps */
 
   switch (signo)
     {
@@ -2328,7 +2332,7 @@ process_send_signal (process, signo, current_group, nomsg)
       if (!nomsg)
        status_notify ();
       break;
-#endif
+#endif /* ! defined (SIGCONT) */
     case SIGINT:
 #ifdef VMS
       send_process (proc, "\003", 1);  /* ^C */
@@ -2366,13 +2370,14 @@ process_send_signal (process, signo, current_group, nomsg)
       gid = - XFASTINT (p->pid);
       kill (gid, signo);
     }
-#else /* no TIOCSIGSEND */
+#else /* ! defined (TIOCSIGSEND) */
   EMACS_KILLPG (-gid, signo);
-#endif
+#endif /* ! defined (TIOCSIGSEND) */
 }
 
 DEFUN ("interrupt-process", Finterrupt_process, Sinterrupt_process, 0, 2, 0,
   "Interrupt process PROCESS.  May be process or name of one.\n\
+PROCESS may be a process, a buffer, or the name of a process or buffer.\n\
 Nil or no arg means current buffer's process.\n\
 Second arg CURRENT-GROUP non-nil means send signal to\n\
 the current process-group of the process's controlling terminal\n\
@@ -2449,7 +2454,8 @@ Both PID and CODE are integers.")
 DEFUN ("process-send-eof", Fprocess_send_eof, Sprocess_send_eof, 0, 1, 0,
   "Make PROCESS see end-of-file in its input.\n\
 Eof comes after any text already sent to it.\n\
-nil or no arg means current buffer's process.")
+PROCESS may be a process, a buffer, the name of a process or buffer, or\n\
+nil, indicating the current buffer's process.")
   (process)
      Lisp_Object process;
 {
@@ -2610,8 +2616,8 @@ sigchld_handler (signo)
          
          /* If process has terminated, stop waiting for its output.  */
          if (WIFSIGNALED (w) || WIFEXITED (w))
-           if (p->infd)
-             FD_CLR (p->infd, &input_wait_mask);
+           if (XFASTINT (p->infd))
+             FD_CLR (XFASTINT (p->infd), &input_wait_mask);
        }
 
        /* There was no asynchronous process found for that id.  Check
@@ -2810,9 +2816,6 @@ t or pty (pty) or stream (socket connection).")
 #endif
 syms_of_process ()
 {
-#ifdef HAVE_PTYS
-  pty_process = intern ("pty");
-#endif
 #ifdef HAVE_SOCKETS
   stream_process = intern ("stream");
 #endif
@@ -2898,7 +2901,7 @@ effect when `start-process' is called.");
 #include "systime.h"
 #include "termopts.h"
 
-extern int screen_garbaged;
+extern int frame_garbaged;
 
 
 /* As described above, except assuming that there are no subprocesses:
@@ -2981,9 +2984,9 @@ wait_reading_process_input (time_limit, microsecs, read_kbd, do_display)
       if (XINT (read_kbd) < 0)
        set_waiting_for_input (&timeout);
 
-      /* If a screen has been newly mapped and needs updating,
+      /* If a frame has been newly mapped and needs updating,
         reprocess its display stuff.  */
-      if (screen_garbaged)
+      if (frame_garbaged)
        redisplay_preserve_echo_area ();
 
       if (XINT (read_kbd) && detect_input_pending ())