aboutsummaryrefslogtreecommitdiffstats
path: root/src/term.c
diff options
context:
space:
mode:
authorPaul Eggert2012-09-06 18:27:44 -0700
committerPaul Eggert2012-09-06 18:27:44 -0700
commit2fe282993cf9c84f5be424dc93d03f9705a7edd8 (patch)
tree229edb6fe29e66984b2992f3f9fa081cd7fe8920 /src/term.c
parent845ce106c0ab157e25416964330875ad6c24b699 (diff)
downloademacs-2fe282993cf9c84f5be424dc93d03f9705a7edd8.tar.gz
emacs-2fe282993cf9c84f5be424dc93d03f9705a7edd8.zip
Signal-handler cleanup.
Emacs's signal handlers were written in the old 4.2BSD style with sigblock and sigmask and so forth, and this led to some inefficiencies and confusion. Rewrite these to use pthread_sigmask etc. without copying signal sets around. Also, get rid of the confusing macros 'SIGNAL_THREAD_CHECK' and 'signal', and instead use functions that do not attempt to take over the system name space. This patch causes Emacs's text segment to shrink by 0.7% on my platform, Fedora 17 x86-64. * configure.ac (PTY_OPEN, PTY_TTY_NAME_SPRINTF): Adjust to syssignal.h changes. (SIGNAL_H_AB): Remove; no longer needed. * src/alloc.c, src/emacsgtkfixed.c, src/nsfns.m, src/widget.c, src/xmenu.c: Do not include <signal.h> or "syssignal.h", as these modules do not use signals. * src/atimer.c, src/callproc.c, src/data.c, src/dispnew.c, src/emacs.c: * src/floatfns.c, src/gtkutil.c, src/keyboard.c, src/process.c, src/sound.c: * src/sysdep.c, src/term.c, src/xterm.c: Do not include <signal.h>, as "syssignal.h" does that for us now. * src/atimer.c (sigmask_atimers): New function. (block_atimers, unblock_atimers): New functions, replacing the old macros BLOCK_ATIMERS and UNBLOCK_ATIMERS. All uses replaced. * src/conf_post.h [SIGNAL_H_AHB]: Do not include <signal.h>; no longer needed here. * src/emacs.c (main): Inspect existing signal handler with sigaction, so that there's no need to block and unblock SIGHUP. * src/sysdep.c (struct save_signal): New member 'action', replacing old member 'handler'. (save_signal_handlers, restore_signal_handlers): Use sigaction instead of 'signal' to save and restore. (get_set_sighandler, set_sighandler) [!WINDOWSNT]: New function. All users of 'signal' modified to use set_sighandler if they're writeonly, and to use sys_signal if they're read+write. (emacs_sigaction_init, forwarded_signal): New functions. (sys_signal): Remove. All uses replaced by calls to sigaction and emacs_sigaction_init, or by direct calls to 'signal'. (sys_sigmask) [!__GNUC__]: Remove; no longer needed. (sys_sigblock, sys_sigunblock, sys_sigsetmask): Remove; all uses replaced by pthread_sigmask etc. calls. * src/syssignal.h: Include <signal.h>. (emacs_sigaction_init, forwarded_signal): New decls. (SIGMASKTYPE): Remove. All uses replaced by its definiens, sigset_t. (SIGEMPTYMASK): Remove; all uses replaced by its definiens, empty_mask. (sigmask, sys_sigmask): Remove; no longer needed. (sigpause): Remove. All uses replaced by its definiens, sigsuspend. (sigblock, sigunblock, sigfree): (sigsetmask) [!defined sigsetmask]: Remove. All uses replaced by pthread_sigmask. (signal): Remove. Its remaining uses (with SIG_DFL and SIG_IGN) no longer need to be replaced, and its typical old uses are now done via emacs_sigaction_init and sigaction. (sys_sigblock, sys_sigunblock, sys_sigsetmask): Remove decls. (sys_sigdel): Remove; unused. (NSIG): Remove a FIXME; the code's fine. Remove an unnecessary ifdef. Fixes: debbugs:12327
Diffstat (limited to 'src/term.c')
-rw-r--r--src/term.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/term.c b/src/term.c
index 8cc5dfd2a87..0eaf76a13df 100644
--- a/src/term.c
+++ b/src/term.c
@@ -25,7 +25,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
25#include <sys/file.h> 25#include <sys/file.h>
26#include <sys/time.h> 26#include <sys/time.h>
27#include <unistd.h> 27#include <unistd.h>
28#include <signal.h>
29#include <setjmp.h> 28#include <setjmp.h>
30 29
31#include "lisp.h" 30#include "lisp.h"
@@ -2932,7 +2931,10 @@ dissociate_if_controlling_tty (int fd)
2932 no_controlling_tty = 1; 2931 no_controlling_tty = 1;
2933#else 2932#else
2934#ifdef TIOCNOTTY /* Try BSD ioctls. */ 2933#ifdef TIOCNOTTY /* Try BSD ioctls. */
2935 sigblock (sigmask (SIGTTOU)); 2934 sigset_t blocked;
2935 sigemptyset (&blocked);
2936 sigaddset (&blocked, SIGTTOU);
2937 pthread_sigmask (SIG_BLOCK, &blocked, 0);
2936 fd = emacs_open (DEV_TTY, O_RDWR, 0); 2938 fd = emacs_open (DEV_TTY, O_RDWR, 0);
2937 if (fd != -1 && ioctl (fd, TIOCNOTTY, 0) != -1) 2939 if (fd != -1 && ioctl (fd, TIOCNOTTY, 0) != -1)
2938 { 2940 {
@@ -2940,7 +2942,7 @@ dissociate_if_controlling_tty (int fd)
2940 } 2942 }
2941 if (fd != -1) 2943 if (fd != -1)
2942 emacs_close (fd); 2944 emacs_close (fd);
2943 sigunblock (sigmask (SIGTTOU)); 2945 pthread_sigmask (SIG_UNBLOCK, &blocked, 0);
2944#else 2946#else
2945 /* Unknown system. */ 2947 /* Unknown system. */
2946 croak (); 2948 croak ();
@@ -3074,9 +3076,14 @@ init_tty (const char *name, const char *terminal_type, int must_succeed)
3074 3076
3075 /* On some systems, tgetent tries to access the controlling 3077 /* On some systems, tgetent tries to access the controlling
3076 terminal. */ 3078 terminal. */
3077 sigblock (sigmask (SIGTTOU)); 3079 {
3078 status = tgetent (tty->termcap_term_buffer, terminal_type); 3080 sigset_t blocked;
3079 sigunblock (sigmask (SIGTTOU)); 3081 sigemptyset (&blocked);
3082 sigaddset (&blocked, SIGTTOU);
3083 pthread_sigmask (SIG_BLOCK, &blocked, 0);
3084 status = tgetent (tty->termcap_term_buffer, terminal_type);
3085 pthread_sigmask (SIG_UNBLOCK, &blocked, 0);
3086 }
3080 3087
3081 if (status < 0) 3088 if (status < 0)
3082 { 3089 {