]> code.delx.au - gnu-emacs/blobdiff - src/process.c
Merge from emacs--devo--0
[gnu-emacs] / src / process.c
index 2281f1ce3f63e12ab2ec83e1d83b84b41f54b1f5..663170e685e84550a13af42d87be4f5d00a73e34 100644 (file)
@@ -149,7 +149,8 @@ Boston, MA 02110-1301, USA.  */
 #include "atimer.h"
 
 Lisp_Object Qprocessp;
-Lisp_Object Qrun, Qstop, Qsignal;
+Lisp_Object Qrun, Qstop;
+extern Lisp_Object Qsignal;
 Lisp_Object Qopen, Qclosed, Qconnect, Qfailed, Qlisten;
 Lisp_Object Qlocal, Qipv4, Qdatagram;
 #ifdef AF_INET6
@@ -318,6 +319,12 @@ static int read_process_output P_ ((Lisp_Object, int));
 #define POLL_FOR_INPUT
 #endif
 
+static Lisp_Object get_process ();
+static void exec_sentinel ();
+
+extern EMACS_TIME timer_check ();
+extern int timers_run;
+\f
 /* Mask of bits indicating the descriptors that we wait for input on.  */
 
 static SELECT_TYPE input_wait_mask;
@@ -386,15 +393,13 @@ struct sockaddr_and_len {
 #define DATAGRAM_CONN_P(proc)  (0)
 #endif
 
-static Lisp_Object get_process ();
-static void exec_sentinel ();
-
-extern EMACS_TIME timer_check ();
-extern int timers_run;
-
 /* Maximum number of bytes to send to a pty without an eof.  */
 static int pty_max_bytes;
 
+/* Nonzero means don't run process sentinels.  This is used
+   when exiting.  */
+int inhibit_sentinels;
+
 #ifdef HAVE_PTYS
 #ifdef HAVE_PTY_H
 #include <pty.h>
@@ -1309,6 +1314,7 @@ list_processes_1 (query_only)
   register struct Lisp_Process *p;
   char tembuf[300];
   int w_proc, w_buffer, w_tty;
+  int exited = 0;
   Lisp_Object i_status, i_buffer, i_tty, i_command;
 
   w_proc = 4;    /* Proc   */
@@ -1435,8 +1441,8 @@ list_processes_1 (query_only)
            }
        }
 
-      if (EQ (symbol, Qsignal) || EQ (symbol, Qexit))
-       remove_process (proc);
+      if (EQ (symbol, Qsignal) || EQ (symbol, Qexit) || EQ (symbol, Qclosed))
+       exited++;
 
       Findent_to (i_buffer, minspace);
       if (NILP (p->buffer))
@@ -1500,6 +1506,8 @@ list_processes_1 (query_only)
          insert_string ("\n");
        }
     }
+  if (exited)
+    status_notify (NULL);
   return Qnil;
 }
 
@@ -4157,6 +4165,14 @@ server_accept_connection (server, channel)
    when not inside wait_reading_process_output.  */
 static int waiting_for_user_input_p;
 
+static Lisp_Object
+wait_reading_process_output_unwind (data)
+     Lisp_Object data;
+{
+  waiting_for_user_input_p = XINT (data);
+  return Qnil;
+}
+
 /* This is here so breakpoints can be put on it.  */
 static void
 wait_reading_process_output_1 ()
@@ -4239,9 +4255,7 @@ wait_reading_process_output (time_limit, microsecs, read_kbd, do_display,
   EMACS_TIME timeout, end_time;
   int wait_channel = -1;
   int got_some_input = 0;
-  /* Either nil or a cons cell, the car of which is of interest and
-     may be changed outside of this routine.  */
-  int saved_waiting_for_user_input_p = waiting_for_user_input_p;
+  int count = SPECPDL_INDEX ();
 
   FD_ZERO (&Available);
 #ifdef NON_BLOCKING_CONNECT
@@ -4252,6 +4266,8 @@ wait_reading_process_output (time_limit, microsecs, read_kbd, do_display,
   if (wait_proc != NULL)
     wait_channel = XINT (wait_proc->infd);
 
+  record_unwind_protect (wait_reading_process_output_unwind,
+                        make_number (waiting_for_user_input_p));
   waiting_for_user_input_p = read_kbd;
 
   /* Since we may need to wait several times,
@@ -4878,7 +4894,7 @@ wait_reading_process_output (time_limit, microsecs, read_kbd, do_display,
        }                       /* end for each file descriptor */
     }                          /* end while exit conditions not met */
 
-  waiting_for_user_input_p = saved_waiting_for_user_input_p;
+  unbind_to (count, Qnil);
 
   /* If calling from keyboard input, do not quit
      since we want to return C-g as an input character.
@@ -5158,7 +5174,7 @@ read_process_output (proc, channel)
 #endif
        /* But do it only if the caller is actually going to read events.
           Otherwise there's no need to make him wake up, and it could
-          cause trouble (for example it would make Fsit_for return).  */
+          cause trouble (for example it would make sit_for return).  */
        if (waiting_for_user_input_p == -1)
          record_asynch_buffer_change ();
 
@@ -6067,7 +6083,7 @@ If PROCESS is a network process, resume handling of incoming traffic.  */)
 DEFUN ("signal-process", Fsignal_process, Ssignal_process,
        2, 2, "sProcess (name or number): \nnSignal code: ",
        doc: /* Send PROCESS the signal with code SIGCODE.
-PROCESS may also be an integer specifying the process id of the
+PROCESS may also be a number specifying the process id of the
 process to signal; in this case, the process need not be a child of
 this Emacs.
 SIGCODE may be an integer, or a symbol whose name is a signal name.  */)
@@ -6084,7 +6100,7 @@ SIGCODE may be an integer, or a symbol whose name is a signal name.  */)
 
   if (FLOATP (process))
     {
-      pid = (pid_t) XFLOAT (process);
+      pid = (pid_t) XFLOAT_DATA (process);
       goto got_it;
     }
 
@@ -6112,8 +6128,8 @@ SIGCODE may be an integer, or a symbol whose name is a signal name.  */)
 
  got_it:
 
-#define handle_signal(NAME, VALUE)             \
-  else if (!strcmp (name, NAME))               \
+#define parse_signal(NAME, VALUE)              \
+  else if (!xstricmp (name, NAME))             \
     XSETINT (sigcode, VALUE)
 
   if (INTEGERP (sigcode))
@@ -6125,106 +6141,106 @@ SIGCODE may be an integer, or a symbol whose name is a signal name.  */)
       CHECK_SYMBOL (sigcode);
       name = SDATA (SYMBOL_NAME (sigcode));
 
-      if (!strncmp(name, "SIG", 3))
+      if (!strncmp(name, "SIG", 3) || !strncmp(name, "sig", 3))
        name += 3;
 
       if (0)
        ;
+#ifdef SIGUSR1
+      parse_signal ("usr1", SIGUSR1);
+#endif
+#ifdef SIGUSR2
+      parse_signal ("usr2", SIGUSR2);
+#endif
+#ifdef SIGTERM
+      parse_signal ("term", SIGTERM);
+#endif
 #ifdef SIGHUP
-      handle_signal ("HUP", SIGHUP);
+      parse_signal ("hup", SIGHUP);
 #endif
 #ifdef SIGINT
-      handle_signal ("INT", SIGINT);
+      parse_signal ("int", SIGINT);
 #endif
 #ifdef SIGQUIT
-      handle_signal ("QUIT", SIGQUIT);
+      parse_signal ("quit", SIGQUIT);
 #endif
 #ifdef SIGILL
-      handle_signal ("ILL", SIGILL);
+      parse_signal ("ill", SIGILL);
 #endif
 #ifdef SIGABRT
-      handle_signal ("ABRT", SIGABRT);
+      parse_signal ("abrt", SIGABRT);
 #endif
 #ifdef SIGEMT
-      handle_signal ("EMT", SIGEMT);
+      parse_signal ("emt", SIGEMT);
 #endif
 #ifdef SIGKILL
-      handle_signal ("KILL", SIGKILL);
+      parse_signal ("kill", SIGKILL);
 #endif
 #ifdef SIGFPE
-      handle_signal ("FPE", SIGFPE);
+      parse_signal ("fpe", SIGFPE);
 #endif
 #ifdef SIGBUS
-      handle_signal ("BUS", SIGBUS);
+      parse_signal ("bus", SIGBUS);
 #endif
 #ifdef SIGSEGV
-      handle_signal ("SEGV", SIGSEGV);
+      parse_signal ("segv", SIGSEGV);
 #endif
 #ifdef SIGSYS
-      handle_signal ("SYS", SIGSYS);
+      parse_signal ("sys", SIGSYS);
 #endif
 #ifdef SIGPIPE
-      handle_signal ("PIPE", SIGPIPE);
+      parse_signal ("pipe", SIGPIPE);
 #endif
 #ifdef SIGALRM
-      handle_signal ("ALRM", SIGALRM);
-#endif
-#ifdef SIGTERM
-      handle_signal ("TERM", SIGTERM);
+      parse_signal ("alrm", SIGALRM);
 #endif
 #ifdef SIGURG
-      handle_signal ("URG", SIGURG);
+      parse_signal ("urg", SIGURG);
 #endif
 #ifdef SIGSTOP
-      handle_signal ("STOP", SIGSTOP);
+      parse_signal ("stop", SIGSTOP);
 #endif
 #ifdef SIGTSTP
-      handle_signal ("TSTP", SIGTSTP);
+      parse_signal ("tstp", SIGTSTP);
 #endif
 #ifdef SIGCONT
-      handle_signal ("CONT", SIGCONT);
+      parse_signal ("cont", SIGCONT);
 #endif
 #ifdef SIGCHLD
-      handle_signal ("CHLD", SIGCHLD);
+      parse_signal ("chld", SIGCHLD);
 #endif
 #ifdef SIGTTIN
-      handle_signal ("TTIN", SIGTTIN);
+      parse_signal ("ttin", SIGTTIN);
 #endif
 #ifdef SIGTTOU
-      handle_signal ("TTOU", SIGTTOU);
+      parse_signal ("ttou", SIGTTOU);
 #endif
 #ifdef SIGIO
-      handle_signal ("IO", SIGIO);
+      parse_signal ("io", SIGIO);
 #endif
 #ifdef SIGXCPU
-      handle_signal ("XCPU", SIGXCPU);
+      parse_signal ("xcpu", SIGXCPU);
 #endif
 #ifdef SIGXFSZ
-      handle_signal ("XFSZ", SIGXFSZ);
+      parse_signal ("xfsz", SIGXFSZ);
 #endif
 #ifdef SIGVTALRM
-      handle_signal ("VTALRM", SIGVTALRM);
+      parse_signal ("vtalrm", SIGVTALRM);
 #endif
 #ifdef SIGPROF
-      handle_signal ("PROF", SIGPROF);
+      parse_signal ("prof", SIGPROF);
 #endif
 #ifdef SIGWINCH
-      handle_signal ("WINCH", SIGWINCH);
+      parse_signal ("winch", SIGWINCH);
 #endif
 #ifdef SIGINFO
-      handle_signal ("INFO", SIGINFO);
-#endif
-#ifdef SIGUSR1
-      handle_signal ("USR1", SIGUSR1);
-#endif
-#ifdef SIGUSR2
-      handle_signal ("USR2", SIGUSR2);
+      parse_signal ("info", SIGINFO);
 #endif
       else
        error ("Undefined signal name %s", name);
     }
 
-#undef handle_signal
+#undef parse_signal
 
   return make_number (kill (pid, XINT (sigcode)));
 }
@@ -6539,6 +6555,9 @@ exec_sentinel (proc, reason)
   int outer_running_asynch_code = running_asynch_code;
   int waiting = waiting_for_user_input_p;
 
+  if (inhibit_sentinels)
+    return;
+
   /* No need to gcpro these, because all we do with them later
      is test them for EQness, and none of them should be a string.  */
   odeactivate = Vdeactivate_mark;
@@ -6595,7 +6614,7 @@ exec_sentinel (proc, reason)
 #endif
     /* But do it only if the caller is actually going to read events.
        Otherwise there's no need to make him wake up, and it could
-       cause trouble (for example it would make Fsit_for return).  */
+       cause trouble (for example it would make sit_for return).  */
     if (waiting_for_user_input_p == -1)
       record_asynch_buffer_change ();
 
@@ -6868,6 +6887,8 @@ init_process ()
 {
   register int i;
 
+  inhibit_sentinels = 0;
+
 #ifdef SIGCHLD
 #ifndef CANNOT_DUMP
   if (! noninteractive || initialized)
@@ -6965,8 +6986,6 @@ syms_of_process ()
   staticpro (&Qrun);
   Qstop = intern ("stop");
   staticpro (&Qstop);
-  Qsignal = intern ("signal");
-  staticpro (&Qsignal);
 
   /* Qexit is already staticpro'd by syms_of_eval; don't staticpro it
      here again.
@@ -7040,7 +7059,7 @@ syms_of_process ()
 
   DEFVAR_BOOL ("delete-exited-processes", &delete_exited_processes,
               doc: /* *Non-nil means delete processes immediately when they exit.
-nil means don't delete them until `list-processes' is run.  */);
+A value of nil means don't delete them until `list-processes' is run.  */);
 
   delete_exited_processes = 1;