aboutsummaryrefslogtreecommitdiffstats
path: root/src/process.c
diff options
context:
space:
mode:
authorTom Tromey2013-07-06 23:18:58 -0600
committerTom Tromey2013-07-06 23:18:58 -0600
commit6dacdad5fcb278e5a16b38bb81786aac9ca27be4 (patch)
treef5f331ea361ba0f99e0f9b638d183ad492a7da31 /src/process.c
parent0a6f2ff0c8ceb29703e76cddd46ea3f176dd873a (diff)
parent219afb88d9d484393418820d1c08dc93299110ec (diff)
downloademacs-6dacdad5fcb278e5a16b38bb81786aac9ca27be4.tar.gz
emacs-6dacdad5fcb278e5a16b38bb81786aac9ca27be4.zip
merge from trunk
this merges frmo trunk and fixes various build issues. this needed a few ugly tweaks. this hangs in "make check" now
Diffstat (limited to 'src/process.c')
-rw-r--r--src/process.c99
1 files changed, 66 insertions, 33 deletions
diff --git a/src/process.c b/src/process.c
index 17facf567b8..2e2610ffde4 100644
--- a/src/process.c
+++ b/src/process.c
@@ -78,7 +78,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
78#endif 78#endif
79 79
80#ifdef HAVE_RES_INIT 80#ifdef HAVE_RES_INIT
81#include <netinet/in.h>
82#include <arpa/nameser.h> 81#include <arpa/nameser.h>
83#include <resolv.h> 82#include <resolv.h>
84#endif 83#endif
@@ -124,8 +123,11 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
124#include TERM_HEADER 123#include TERM_HEADER
125#endif /* HAVE_WINDOW_SYSTEM */ 124#endif /* HAVE_WINDOW_SYSTEM */
126 125
127#if defined (USE_GTK) || defined (HAVE_GCONF) || defined (HAVE_GSETTINGS) 126#ifdef HAVE_GLIB
128#include "xgselect.h" 127#include "xgselect.h"
128#ifndef WINDOWSNT
129#include <glib.h>
130#endif
129#endif 131#endif
130 132
131#ifdef WINDOWSNT 133#ifdef WINDOWSNT
@@ -1784,12 +1786,10 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
1784#ifndef WINDOWSNT 1786#ifndef WINDOWSNT
1785 int wait_child_setup[2]; 1787 int wait_child_setup[2];
1786#endif 1788#endif
1787 sigset_t blocked; 1789 int forkin, forkout;
1788 /* Use volatile to protect variables from being clobbered by vfork. */ 1790 bool pty_flag = 0;
1789 volatile int forkin, forkout; 1791 Lisp_Object lisp_pty_name = Qnil;
1790 volatile bool pty_flag = 0; 1792 Lisp_Object encoded_current_dir;
1791 volatile Lisp_Object lisp_pty_name = Qnil;
1792 volatile Lisp_Object encoded_current_dir;
1793 1793
1794 inchannel = outchannel = -1; 1794 inchannel = outchannel = -1;
1795 1795
@@ -1877,15 +1877,34 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
1877 encoded_current_dir = ENCODE_FILE (current_dir); 1877 encoded_current_dir = ENCODE_FILE (current_dir);
1878 1878
1879 block_input (); 1879 block_input ();
1880 1880 block_child_signal ();
1881 /* Block SIGCHLD until we have a chance to store the new fork's
1882 pid in its process structure. */
1883 sigemptyset (&blocked);
1884 sigaddset (&blocked, SIGCHLD);
1885 pthread_sigmask (SIG_BLOCK, &blocked, 0);
1886 1881
1887#ifndef WINDOWSNT 1882#ifndef WINDOWSNT
1888 pid = vfork (); 1883 /* vfork, and prevent local vars from being clobbered by the vfork. */
1884 {
1885 Lisp_Object volatile encoded_current_dir_volatile = encoded_current_dir;
1886 Lisp_Object volatile lisp_pty_name_volatile = lisp_pty_name;
1887 Lisp_Object volatile process_volatile = process;
1888 bool volatile pty_flag_volatile = pty_flag;
1889 char **volatile new_argv_volatile = new_argv;
1890 int volatile forkin_volatile = forkin;
1891 int volatile forkout_volatile = forkout;
1892 int volatile wait_child_setup_0_volatile = wait_child_setup[0];
1893 int volatile wait_child_setup_1_volatile = wait_child_setup[1];
1894
1895 pid = vfork ();
1896
1897 encoded_current_dir = encoded_current_dir_volatile;
1898 lisp_pty_name = lisp_pty_name_volatile;
1899 process = process_volatile;
1900 pty_flag = pty_flag_volatile;
1901 new_argv = new_argv_volatile;
1902 forkin = forkin_volatile;
1903 forkout = forkout_volatile;
1904 wait_child_setup[0] = wait_child_setup_0_volatile;
1905 wait_child_setup[1] = wait_child_setup_1_volatile;
1906 }
1907
1889 if (pid == 0) 1908 if (pid == 0)
1890#endif /* not WINDOWSNT */ 1909#endif /* not WINDOWSNT */
1891 { 1910 {
@@ -1990,8 +2009,8 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
1990 /* Emacs ignores SIGPIPE, but the child should not. */ 2009 /* Emacs ignores SIGPIPE, but the child should not. */
1991 signal (SIGPIPE, SIG_DFL); 2010 signal (SIGPIPE, SIG_DFL);
1992 2011
1993 /* Stop blocking signals in the child. */ 2012 /* Stop blocking SIGCHLD in the child. */
1994 pthread_sigmask (SIG_SETMASK, &empty_mask, 0); 2013 unblock_child_signal ();
1995 2014
1996 if (pty_flag) 2015 if (pty_flag)
1997 child_setup_tty (xforkout); 2016 child_setup_tty (xforkout);
@@ -2011,8 +2030,8 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
2011 if (pid >= 0) 2030 if (pid >= 0)
2012 XPROCESS (process)->alive = 1; 2031 XPROCESS (process)->alive = 1;
2013 2032
2014 /* Stop blocking signals in the parent. */ 2033 /* Stop blocking in the parent. */
2015 pthread_sigmask (SIG_SETMASK, &empty_mask, 0); 2034 unblock_child_signal ();
2016 unblock_input (); 2035 unblock_input ();
2017 2036
2018 if (pid < 0) 2037 if (pid < 0)
@@ -2715,7 +2734,7 @@ usage: (make-serial-process &rest ARGS) */)
2715 struct gcpro gcpro1; 2734 struct gcpro gcpro1;
2716 Lisp_Object name, buffer; 2735 Lisp_Object name, buffer;
2717 Lisp_Object tem, val; 2736 Lisp_Object tem, val;
2718 ptrdiff_t specpdl_count = -1; 2737 ptrdiff_t specpdl_count;
2719 2738
2720 if (nargs == 0) 2739 if (nargs == 0)
2721 return Qnil; 2740 return Qnil;
@@ -4569,7 +4588,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
4569 && ! EQ (wait_proc->status, Qrun) 4588 && ! EQ (wait_proc->status, Qrun)
4570 && ! EQ (wait_proc->status, Qconnect)) 4589 && ! EQ (wait_proc->status, Qconnect))
4571 { 4590 {
4572 int nread, total_nread = 0; 4591 bool read_some_bytes = 0;
4573 4592
4574 clear_waiting_for_input (); 4593 clear_waiting_for_input ();
4575 XSETPROCESS (proc, wait_proc); 4594 XSETPROCESS (proc, wait_proc);
@@ -4577,16 +4596,13 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
4577 /* Read data from the process, until we exhaust it. */ 4596 /* Read data from the process, until we exhaust it. */
4578 while (wait_proc->infd >= 0) 4597 while (wait_proc->infd >= 0)
4579 { 4598 {
4580 nread = read_process_output (proc, wait_proc->infd); 4599 int nread = read_process_output (proc, wait_proc->infd);
4581 4600
4582 if (nread == 0) 4601 if (nread == 0)
4583 break; 4602 break;
4584 4603
4585 if (nread > 0) 4604 if (nread > 0)
4586 { 4605 got_some_input = read_some_bytes = 1;
4587 total_nread += nread;
4588 got_some_input = 1;
4589 }
4590 else if (nread == -1 && (errno == EIO || errno == EAGAIN)) 4606 else if (nread == -1 && (errno == EIO || errno == EAGAIN))
4591 break; 4607 break;
4592#ifdef EWOULDBLOCK 4608#ifdef EWOULDBLOCK
@@ -4594,7 +4610,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
4594 break; 4610 break;
4595#endif 4611#endif
4596 } 4612 }
4597 if (total_nread > 0 && do_display) 4613 if (read_some_bytes && do_display)
4598 redisplay_preserve_echo_area (10); 4614 redisplay_preserve_echo_area (10);
4599 4615
4600 break; 4616 break;
@@ -6257,9 +6273,10 @@ process has been transmitted to the serial port. */)
6257 6273
6258/* LIB_CHILD_HANDLER is a SIGCHLD handler that Emacs calls while doing 6274/* LIB_CHILD_HANDLER is a SIGCHLD handler that Emacs calls while doing
6259 its own SIGCHLD handling. On POSIXish systems, glib needs this to 6275 its own SIGCHLD handling. On POSIXish systems, glib needs this to
6260 keep track of its own children. The default handler does nothing. */ 6276 keep track of its own children. GNUstep is similar. */
6277
6261static void dummy_handler (int sig) {} 6278static void dummy_handler (int sig) {}
6262static signal_handler_t volatile lib_child_handler = dummy_handler; 6279static signal_handler_t volatile lib_child_handler;
6263 6280
6264/* Handle a SIGCHLD signal by looking for known child processes of 6281/* Handle a SIGCHLD signal by looking for known child processes of
6265 Emacs whose status have changed. For each one found, record its 6282 Emacs whose status have changed. For each one found, record its
@@ -6344,6 +6361,11 @@ handle_child_signal (int sig)
6344 } 6361 }
6345 6362
6346 lib_child_handler (sig); 6363 lib_child_handler (sig);
6364#ifdef NS_IMPL_GNUSTEP
6365 /* NSTask in GNUStep sets its child handler each time it is called.
6366 So we must re-set ours. */
6367 catch_child_signal();
6368#endif
6347} 6369}
6348 6370
6349static void 6371static void
@@ -7189,6 +7211,11 @@ integer or floating point values.
7189 return system_process_attributes (pid); 7211 return system_process_attributes (pid);
7190} 7212}
7191 7213
7214/* Arrange to catch SIGCHLD if this hasn't already been arranged.
7215 Invoke this after init_process_emacs, and after glib and/or GNUstep
7216 futz with the SIGCHLD handler, but before Emacs forks any children.
7217 This function's caller should block SIGCHLD. */
7218
7192#ifndef NS_IMPL_GNUSTEP 7219#ifndef NS_IMPL_GNUSTEP
7193static 7220static
7194#endif 7221#endif
@@ -7197,11 +7224,16 @@ catch_child_signal (void)
7197{ 7224{
7198 struct sigaction action, old_action; 7225 struct sigaction action, old_action;
7199 emacs_sigaction_init (&action, deliver_child_signal); 7226 emacs_sigaction_init (&action, deliver_child_signal);
7227 block_child_signal ();
7200 sigaction (SIGCHLD, &action, &old_action); 7228 sigaction (SIGCHLD, &action, &old_action);
7201 eassert (! (old_action.sa_flags & SA_SIGINFO)); 7229 eassert (! (old_action.sa_flags & SA_SIGINFO));
7202 if (old_action.sa_handler != SIG_DFL && old_action.sa_handler != SIG_IGN 7230
7203 && old_action.sa_handler != deliver_child_signal) 7231 if (old_action.sa_handler != deliver_child_signal)
7204 lib_child_handler = old_action.sa_handler; 7232 lib_child_handler
7233 = (old_action.sa_handler == SIG_DFL || old_action.sa_handler == SIG_IGN
7234 ? dummy_handler
7235 : old_action.sa_handler);
7236 unblock_child_signal ();
7205} 7237}
7206 7238
7207 7239
@@ -7222,7 +7254,8 @@ init_process_emacs (void)
7222#if defined HAVE_GLIB && !defined WINDOWSNT 7254#if defined HAVE_GLIB && !defined WINDOWSNT
7223 /* Tickle glib's child-handling code. Ask glib to wait for Emacs itself; 7255 /* Tickle glib's child-handling code. Ask glib to wait for Emacs itself;
7224 this should always fail, but is enough to initialize glib's 7256 this should always fail, but is enough to initialize glib's
7225 private SIGCHLD handler. */ 7257 private SIGCHLD handler, allowing catch_child_signal to copy
7258 it into lib_child_handler. */
7226 g_source_unref (g_child_watch_source_new (getpid ())); 7259 g_source_unref (g_child_watch_source_new (getpid ()));
7227#endif 7260#endif
7228 catch_child_signal (); 7261 catch_child_signal ();