configure: new option --enable-gcc-warnings
[bpt/emacs.git] / src / process.c
index dc37ec5..f14de47 100644 (file)
@@ -1,6 +1,6 @@
 /* Asynchronous subprocess control for GNU Emacs.
 
-Copyright (C) 1985-1988, 1993-1996, 1998-1999, 2001-2011
+Copyright (C) 1985-1988, 1993-1996, 1998-1999, 2001-2012
   Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
@@ -120,6 +120,13 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include "nsterm.h"
 #endif
 
+/* Work around GCC 4.7.0 bug with strict overflow checking; see
+   <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52904>.
+   These lines can be removed once the GCC bug is fixed.  */
+#if (__GNUC__ == 4 && 3 <= __GNUC_MINOR__) || 4 < __GNUC__
+# pragma GCC diagnostic ignored "-Wstrict-overflow"
+#endif
+
 Lisp_Object Qeuid, Qegid, Qcomm, Qstate, Qppid, Qpgrp, Qsess, Qttname, Qtpgid;
 Lisp_Object Qminflt, Qmajflt, Qcminflt, Qcmajflt, Qutime, Qstime, Qcstime;
 Lisp_Object Qcutime, Qpri, Qnice, Qthcount, Qstart, Qvsize, Qrss, Qargs;
@@ -1414,7 +1421,7 @@ usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS)  */)
          val = XCDR (Vdefault_process_coding_system);
       }
     XPROCESS (proc)->encode_coding_system = val;
-    /* Note: At this momemnt, the above coding system may leave
+    /* Note: At this moment, the above coding system may leave
        text-conversion or eol-conversion unspecified.  They will be
        decided after we read output from the process and decode it by
        some coding system, or just before we actually send a text to
@@ -1521,8 +1528,9 @@ start_process_unwind (Lisp_Object proc)
   if (!PROCESSP (proc))
     abort ();
 
-  /* Was PROC started successfully?  */
-  if (XPROCESS (proc)->pid == -1)
+  /* Was PROC started successfully?
+     -2 is used for a pty with no process, eg for gdb.  */
+  if (XPROCESS (proc)->pid <= 0 && XPROCESS (proc)->pid != -2)
     remove_process (proc);
 
   return Qnil;
@@ -3120,7 +3128,7 @@ usage: (make-network-process &rest ARGS)  */)
     {
       struct hostent *host_info_ptr;
 
-      /* gethostbyname may fail with TRY_AGAIN, but we don't honour that,
+      /* gethostbyname may fail with TRY_AGAIN, but we don't honor that,
         as it may `hang' Emacs for a very long time.  */
       immediate_quit = 1;
       QUIT;
@@ -3474,7 +3482,7 @@ usage: (make-network-process &rest ARGS)  */)
 
   {
     /* Setup coding systems for communicating with the network stream.  */
-    struct gcpro inner_gcpro1;
+    struct gcpro gcpro1;
     /* Qt denotes we have not yet called Ffind_operation_coding_system.  */
     Lisp_Object coding_systems = Qt;
     Lisp_Object fargs[5], val;
@@ -3491,7 +3499,7 @@ usage: (make-network-process &rest ARGS)  */)
             || (NILP (buffer) && NILP (BVAR (&buffer_defaults, enable_multibyte_characters))))
       /* We dare not decode end-of-line format by setting VAL to
         Qraw_text, because the existing Emacs Lisp libraries
-        assume that they receive bare code including a sequene of
+        assume that they receive bare code including a sequence of
         CR LF.  */
       val = Qnil;
     else
@@ -3502,9 +3510,9 @@ usage: (make-network-process &rest ARGS)  */)
          {
            fargs[0] = Qopen_network_stream, fargs[1] = name,
              fargs[2] = buffer, fargs[3] = host, fargs[4] = service;
-           GCPRO1_VAR (proc, inner_gcpro);
+           GCPRO1 (proc);
            coding_systems = Ffind_operation_coding_system (5, fargs);
-           UNGCPRO_VAR (inner_gcpro);
+           UNGCPRO;
          }
        if (CONSP (coding_systems))
          val = XCAR (coding_systems);
@@ -3535,9 +3543,9 @@ usage: (make-network-process &rest ARGS)  */)
              {
                fargs[0] = Qopen_network_stream, fargs[1] = name,
                  fargs[2] = buffer, fargs[3] = host, fargs[4] = service;
-               GCPRO1_VAR (proc, inner_gcpro);
+               GCPRO1 (proc);
                coding_systems = Ffind_operation_coding_system (5, fargs);
-               UNGCPRO_VAR (inner_gcpro);
+               UNGCPRO;
              }
          }
        if (CONSP (coding_systems))
@@ -3717,7 +3725,7 @@ DEFUN ("network-interface-info", Fnetwork_interface_info, Snetwork_interface_inf
        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 addres, and
+NETMASK is the layer 3 network mask, HWADDR is the layer 2 address, and
 FLAGS is the current flags of the interface.  */)
   (Lisp_Object ifname)
 {
@@ -4620,15 +4628,46 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
              some data in the TCP buffers so that select works, but
              with custom pull/push functions we need to check if some
              data is available in the buffers manually.  */
-          if (nfds == 0 &&
-              wait_proc && wait_proc->gnutls_p /* Check for valid process.  */
-              /* Do we have pending data?  */
-              && emacs_gnutls_record_check_pending (wait_proc->gnutls_state) > 0)
-          {
-              nfds = 1;
-              /* Set to Available.  */
-              FD_SET (wait_proc->infd, &Available);
-          }
+          if (nfds == 0)
+           {
+             if (! wait_proc)
+               {
+                 /* We're not waiting on a specific process, so loop
+                    through all the channels and check for data.
+                    This is a workaround needed for some versions of
+                    the gnutls library -- 2.12.14 has been confirmed
+                    to need it.  See
+                    http://comments.gmane.org/gmane.emacs.devel/145074 */
+                 for (channel = 0; channel < MAXDESC; ++channel)
+                   if (! NILP (chan_process[channel]))
+                     {
+                       struct Lisp_Process *p =
+                         XPROCESS (chan_process[channel]);
+                       if (p && p->gnutls_p && p->infd
+                           && ((emacs_gnutls_record_check_pending
+                                (p->gnutls_state))
+                               > 0))
+                         {
+                           nfds++;
+                           FD_SET (p->infd, &Available);
+                         }
+                     }
+               }
+             else
+               {
+                 /* Check this specific channel. */
+                 if (wait_proc->gnutls_p /* Check for valid process.  */
+                     /* Do we have pending data?  */
+                     && ((emacs_gnutls_record_check_pending
+                          (wait_proc->gnutls_state))
+                         > 0))
+                   {
+                     nfds = 1;
+                     /* Set to Available.  */
+                     FD_SET (wait_proc->infd, &Available);
+                   }
+               }
+           }
 #endif
        }
 
@@ -4856,20 +4895,20 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
                 It can't hurt.  */
              else if (nread == -1 && errno == EIO)
                {
-                 /* Clear the descriptor now, so we only raise the
-                    signal once.  Don't do this if `process' is only
-                    a pty.  */
-                 if (XPROCESS (proc)->pid != -2)
-                   {
-                     FD_CLR (channel, &input_wait_mask);
-                     FD_CLR (channel, &non_keyboard_wait_mask);
-
-                     kill (getpid (), SIGCHLD);
-                   }
+                  /* Don't do anything if only a pty, with no associated
+                    process (bug#10933).  */
+                  if (XPROCESS (proc)->pid != -2) {
+                    /* Clear the descriptor now, so we only raise the signal
+                      once.  */
+                    FD_CLR (channel, &input_wait_mask);
+                    FD_CLR (channel, &non_keyboard_wait_mask);
+                    
+                    kill (getpid (), SIGCHLD);
+                  }
                }
 #endif /* HAVE_PTYS */
-             /* If we can detect process termination, don't consider the process
-                gone just because its pipe is closed.  */
+             /* If we can detect process termination, don't consider the
+                process gone just because its pipe is closed.  */
 #ifdef SIGCHLD
              else if (nread == 0 && !NETCONN_P (proc) && !SERIALCONN_P (proc))
                ;
@@ -5033,9 +5072,8 @@ read_process_output (Lisp_Object proc, register int channel)
          proc_buffered_char[channel] = -1;
        }
 #ifdef HAVE_GNUTLS
-      if (XPROCESS (proc)->gnutls_p)
-       nbytes = emacs_gnutls_read (XPROCESS (proc),
-                                   chars + carryover + buffered,
+      if (p->gnutls_p)
+       nbytes = emacs_gnutls_read (p, chars + carryover + buffered,
                                    readmax - buffered);
       else
 #endif
@@ -5382,8 +5420,8 @@ send_process (volatile Lisp_Object proc, const char *volatile buf,
             sending a multibyte text, thus we must encode it by the
             original coding system specified for the current process.
 
-            Another reason we comming here is that the coding system
-            was just complemented and new one was returned by
+            Another reason we come here is that the coding system
+            was just complemented and new one was returned by
             complement_process_encoding_system.  */
          setup_coding_system (p->encode_coding_system, coding);
          Vlast_coding_system_used = p->encode_coding_system;
@@ -5392,6 +5430,7 @@ send_process (volatile Lisp_Object proc, const char *volatile buf,
     }
   else
     {
+      coding->src_multibyte = 0;
       /* For sending a unibyte text, character code conversion should
         not take place but EOL conversion should.  So, setup raw-text
         or one of the subsidiary if we have not yet done it.  */
@@ -5499,9 +5538,8 @@ send_process (volatile Lisp_Object proc, const char *volatile buf,
 #endif
                {
 #ifdef HAVE_GNUTLS
-                 if (XPROCESS (proc)->gnutls_p)
-                   written = emacs_gnutls_write (XPROCESS (proc),
-                                                  buf, this);
+                 if (p->gnutls_p)
+                   written = emacs_gnutls_write (p, buf, this);
                  else
 #endif
                    written = emacs_write (outfd, buf, this);