Import readline 7.0 (patch 5)
[deliverable/binutils-gdb.git] / readline / signals.c
CommitLineData
d60d9f65
SS
1/* signals.c -- signal handling support for readline. */
2
775e241e 3/* Copyright (C) 1987-2016 Free Software Foundation, Inc.
d60d9f65 4
cc88a640
JK
5 This file is part of the GNU Readline Library (Readline), a library
6 for reading lines of text with interactive input and history editing.
d60d9f65 7
cc88a640
JK
8 Readline is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
d60d9f65
SS
11 (at your option) any later version.
12
cc88a640
JK
13 Readline is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d60d9f65
SS
16 GNU General Public License for more details.
17
cc88a640
JK
18 You should have received a copy of the GNU General Public License
19 along with Readline. If not, see <http://www.gnu.org/licenses/>.
20*/
21
d60d9f65
SS
22#define READLINE_LIBRARY
23
24#if defined (HAVE_CONFIG_H)
25# include <config.h>
26#endif
27
28#include <stdio.h> /* Just for NULL. Yuck. */
29#include <sys/types.h>
30#include <signal.h>
31
32#if defined (HAVE_UNISTD_H)
33# include <unistd.h>
34#endif /* HAVE_UNISTD_H */
35
36/* System-specific feature definitions and include files. */
37#include "rldefs.h"
38
39#if defined (GWINSZ_IN_SYS_IOCTL)
40# include <sys/ioctl.h>
41#endif /* GWINSZ_IN_SYS_IOCTL */
42
d60d9f65
SS
43/* Some standard library routines. */
44#include "readline.h"
45#include "history.h"
46
1b17e766
EZ
47#include "rlprivate.h"
48
cc88a640
JK
49#if defined (HANDLE_SIGNALS)
50
d60d9f65
SS
51#if !defined (RETSIGTYPE)
52# if defined (VOID_SIGHANDLER)
53# define RETSIGTYPE void
54# else
55# define RETSIGTYPE int
56# endif /* !VOID_SIGHANDLER */
57#endif /* !RETSIGTYPE */
58
59#if defined (VOID_SIGHANDLER)
60# define SIGHANDLER_RETURN return
61#else
62# define SIGHANDLER_RETURN return (0)
63#endif
64
9255ee31 65/* This typedef is equivalent to the one for Function; it allows us
d60d9f65
SS
66 to say SigHandler *foo = signal (SIGKILL, SIG_IGN); */
67typedef RETSIGTYPE SigHandler ();
68
1b17e766
EZ
69#if defined (HAVE_POSIX_SIGNALS)
70typedef struct sigaction sighandler_cxt;
71# define rl_sigaction(s, nh, oh) sigaction(s, nh, oh)
72#else
73typedef struct { SigHandler *sa_handler; int sa_mask, sa_flags; } sighandler_cxt;
74# define sigemptyset(m)
75#endif /* !HAVE_POSIX_SIGNALS */
c862e87b 76
5bdf8622
DJ
77#ifndef SA_RESTART
78# define SA_RESTART 0
79#endif
80
9255ee31
EZ
81static SigHandler *rl_set_sighandler PARAMS((int, SigHandler *, sighandler_cxt *));
82static void rl_maybe_set_sighandler PARAMS((int, SigHandler *, sighandler_cxt *));
775e241e 83static void rl_maybe_restore_sighandler PARAMS((int, sighandler_cxt *));
d60d9f65 84
cc88a640
JK
85static RETSIGTYPE rl_signal_handler PARAMS((int));
86static RETSIGTYPE _rl_handle_signal PARAMS((int));
87
c862e87b
JM
88/* Exported variables for use by applications. */
89
90/* If non-zero, readline will install its own signal handlers for
775e241e 91 SIGINT, SIGTERM, SIGHUP, SIGQUIT, SIGALRM, SIGTSTP, SIGTTIN, and SIGTTOU. */
c862e87b
JM
92int rl_catch_signals = 1;
93
94/* If non-zero, readline will install a signal handler for SIGWINCH. */
95#ifdef SIGWINCH
96int rl_catch_sigwinch = 1;
5bdf8622
DJ
97#else
98int rl_catch_sigwinch = 0; /* for the readline state struct in readline.c */
c862e87b
JM
99#endif
100
cc88a640
JK
101/* Private variables. */
102int _rl_interrupt_immediately = 0;
103int volatile _rl_caught_signal = 0; /* should be sig_atomic_t, but that requires including <signal.h> everywhere */
104
105/* If non-zero, print characters corresponding to received signals as long as
106 the user has indicated his desire to do so (_rl_echo_control_chars). */
107int _rl_echoctl = 0;
108
109int _rl_intr_char = 0;
110int _rl_quit_char = 0;
111int _rl_susp_char = 0;
112
c862e87b
JM
113static int signals_set_flag;
114static int sigwinch_set_flag;
115
d60d9f65
SS
116/* **************************************************************** */
117/* */
118/* Signal Handling */
119/* */
120/* **************************************************************** */
121
775e241e 122static sighandler_cxt old_int, old_term, old_hup, old_alrm, old_quit;
c862e87b 123#if defined (SIGTSTP)
d60d9f65 124static sighandler_cxt old_tstp, old_ttou, old_ttin;
d60d9f65 125#endif
d60d9f65
SS
126#if defined (SIGWINCH)
127static sighandler_cxt old_winch;
128#endif
129
775e241e
TT
130_rl_sigcleanup_func_t *_rl_sigcleanup;
131void *_rl_sigcleanarg;
132
d60d9f65
SS
133/* Readline signal handler functions. */
134
cc88a640
JK
135/* Called from RL_CHECK_SIGNALS() macro */
136RETSIGTYPE
137_rl_signal_handler (sig)
138 int sig;
139{
140 _rl_caught_signal = 0; /* XXX */
141
775e241e
TT
142#if defined (SIGWINCH)
143 if (sig == SIGWINCH)
144 {
145 rl_resize_terminal ();
146 /* XXX - experimental for now */
147 /* Call a signal hook because though we called the original signal handler
148 in rl_sigwinch_handler below, we will not resend the signal to
149 ourselves. */
150 if (rl_signal_event_hook)
151 (*rl_signal_event_hook) ();
152 }
153 else
154#endif
155 _rl_handle_signal (sig);
156
cc88a640
JK
157 SIGHANDLER_RETURN;
158}
159
d60d9f65
SS
160static RETSIGTYPE
161rl_signal_handler (sig)
162 int sig;
cc88a640 163{
775e241e 164 if (_rl_interrupt_immediately)
cc88a640
JK
165 {
166 _rl_interrupt_immediately = 0;
167 _rl_handle_signal (sig);
168 }
169 else
170 _rl_caught_signal = sig;
171
172 SIGHANDLER_RETURN;
173}
174
175static RETSIGTYPE
176_rl_handle_signal (sig)
177 int sig;
d60d9f65
SS
178{
179#if defined (HAVE_POSIX_SIGNALS)
180 sigset_t set;
181#else /* !HAVE_POSIX_SIGNALS */
182# if defined (HAVE_BSD_SIGNALS)
183 long omask;
184# else /* !HAVE_BSD_SIGNALS */
185 sighandler_cxt dummy_cxt; /* needed for rl_set_sighandler call */
186# endif /* !HAVE_BSD_SIGNALS */
187#endif /* !HAVE_POSIX_SIGNALS */
188
9255ee31
EZ
189 RL_SETSTATE(RL_STATE_SIGHANDLER);
190
d60d9f65
SS
191#if !defined (HAVE_BSD_SIGNALS) && !defined (HAVE_POSIX_SIGNALS)
192 /* Since the signal will not be blocked while we are in the signal
193 handler, ignore it until rl_clear_signals resets the catcher. */
5bdf8622
DJ
194# if defined (SIGALRM)
195 if (sig == SIGINT || sig == SIGALRM)
196# else
197 if (sig == SIGINT)
198# endif
d60d9f65
SS
199 rl_set_sighandler (sig, SIG_IGN, &dummy_cxt);
200#endif /* !HAVE_BSD_SIGNALS && !HAVE_POSIX_SIGNALS */
201
775e241e
TT
202 /* If there's a sig cleanup function registered, call it and `deregister'
203 the cleanup function to avoid multiple calls */
204 if (_rl_sigcleanup)
205 {
206 (*_rl_sigcleanup) (sig, _rl_sigcleanarg);
207 _rl_sigcleanup = 0;
208 _rl_sigcleanarg = 0;
209 }
210
d60d9f65
SS
211 switch (sig)
212 {
213 case SIGINT:
cc88a640 214 _rl_reset_completion_state ();
c862e87b 215 rl_free_line_state ();
775e241e
TT
216#if defined (READLINE_CALLBACKS)
217 rl_callback_sigcleanup ();
218#endif
219
c862e87b 220 /* FALLTHROUGH */
d60d9f65
SS
221
222#if defined (SIGTSTP)
223 case SIGTSTP:
5836a818 224 case SIGTTIN:
775e241e
TT
225# if defined (HAVE_POSIX_SIGNALS)
226 /* Block SIGTTOU so we can restore the terminal settings to something
227 sane without stopping on SIGTTOU if we have been placed into the
228 background. Even trying to get the current terminal pgrp with
229 tcgetpgrp() will generate SIGTTOU, so we don't bother. Don't bother
230 doing this if we've been stopped on SIGTTOU; it's aready too late. */
231 sigemptyset (&set);
232 sigaddset (&set, SIGTTOU);
233 sigprocmask (SIG_BLOCK, &set, (sigset_t *)NULL);
234# endif
235 case SIGTTOU:
d60d9f65 236#endif /* SIGTSTP */
775e241e
TT
237 case SIGTERM:
238#if defined (SIGHUP)
239 case SIGHUP:
240#endif
5bdf8622 241#if defined (SIGALRM)
d60d9f65 242 case SIGALRM:
430b7832 243#endif
5bdf8622 244#if defined (SIGQUIT)
c862e87b 245 case SIGQUIT:
430b7832 246#endif
cc88a640 247 rl_echo_signal_char (sig);
c862e87b 248 rl_cleanup_after_signal ();
d60d9f65
SS
249
250#if defined (HAVE_POSIX_SIGNALS)
775e241e
TT
251 /* Unblock SIGTTOU blocked above */
252 if (sig == SIGTTIN || sig == SIGTSTP)
253 sigprocmask (SIG_UNBLOCK, &set, (sigset_t *)NULL);
254
cc88a640 255 sigemptyset (&set);
d60d9f65
SS
256 sigprocmask (SIG_BLOCK, (sigset_t *)NULL, &set);
257 sigdelset (&set, sig);
258#else /* !HAVE_POSIX_SIGNALS */
259# if defined (HAVE_BSD_SIGNALS)
260 omask = sigblock (0);
261# endif /* HAVE_BSD_SIGNALS */
262#endif /* !HAVE_POSIX_SIGNALS */
263
1b17e766
EZ
264#if defined (__EMX__)
265 signal (sig, SIG_ACK);
266#endif
267
5bdf8622 268#if defined (HAVE_KILL)
d60d9f65 269 kill (getpid (), sig);
430b7832 270#else
5bdf8622 271 raise (sig); /* assume we have raise */
430b7832 272#endif
d60d9f65
SS
273
274 /* Let the signal that we just sent through. */
275#if defined (HAVE_POSIX_SIGNALS)
276 sigprocmask (SIG_SETMASK, &set, (sigset_t *)NULL);
277#else /* !HAVE_POSIX_SIGNALS */
278# if defined (HAVE_BSD_SIGNALS)
279 sigsetmask (omask & ~(sigmask (sig)));
280# endif /* HAVE_BSD_SIGNALS */
281#endif /* !HAVE_POSIX_SIGNALS */
282
775e241e 283 rl_reset_after_signal ();
d60d9f65
SS
284 }
285
9255ee31 286 RL_UNSETSTATE(RL_STATE_SIGHANDLER);
d60d9f65
SS
287 SIGHANDLER_RETURN;
288}
289
290#if defined (SIGWINCH)
291static RETSIGTYPE
c862e87b 292rl_sigwinch_handler (sig)
d60d9f65
SS
293 int sig;
294{
295 SigHandler *oh;
296
297#if defined (MUST_REINSTALL_SIGHANDLERS)
298 sighandler_cxt dummy_winch;
299
300 /* We don't want to change old_winch -- it holds the state of SIGWINCH
301 disposition set by the calling application. We need this state
302 because we call the application's SIGWINCH handler after updating
303 our own idea of the screen size. */
c862e87b 304 rl_set_sighandler (SIGWINCH, rl_sigwinch_handler, &dummy_winch);
d60d9f65
SS
305#endif
306
9255ee31 307 RL_SETSTATE(RL_STATE_SIGHANDLER);
775e241e 308 _rl_caught_signal = sig;
d60d9f65
SS
309
310 /* If another sigwinch handler has been installed, call it. */
311 oh = (SigHandler *)old_winch.sa_handler;
312 if (oh && oh != (SigHandler *)SIG_IGN && oh != (SigHandler *)SIG_DFL)
313 (*oh) (sig);
314
9255ee31 315 RL_UNSETSTATE(RL_STATE_SIGHANDLER);
d60d9f65
SS
316 SIGHANDLER_RETURN;
317}
318#endif /* SIGWINCH */
319
320/* Functions to manage signal handling. */
321
322#if !defined (HAVE_POSIX_SIGNALS)
323static int
324rl_sigaction (sig, nh, oh)
325 int sig;
326 sighandler_cxt *nh, *oh;
327{
328 oh->sa_handler = signal (sig, nh->sa_handler);
329 return 0;
330}
331#endif /* !HAVE_POSIX_SIGNALS */
332
333/* Set up a readline-specific signal handler, saving the old signal
334 information in OHANDLER. Return the old signal handler, like
335 signal(). */
336static SigHandler *
337rl_set_sighandler (sig, handler, ohandler)
338 int sig;
339 SigHandler *handler;
340 sighandler_cxt *ohandler;
341{
1b17e766 342 sighandler_cxt old_handler;
d60d9f65
SS
343#if defined (HAVE_POSIX_SIGNALS)
344 struct sigaction act;
345
346 act.sa_handler = handler;
cc88a640 347# if defined (SIGWINCH)
5bdf8622 348 act.sa_flags = (sig == SIGWINCH) ? SA_RESTART : 0;
cc88a640 349# else
230335c4 350 act.sa_flags = 0;
cc88a640 351# endif /* SIGWINCH */
d60d9f65
SS
352 sigemptyset (&act.sa_mask);
353 sigemptyset (&ohandler->sa_mask);
1b17e766 354 sigaction (sig, &act, &old_handler);
d60d9f65 355#else
1b17e766 356 old_handler.sa_handler = (SigHandler *)signal (sig, handler);
d60d9f65 357#endif /* !HAVE_POSIX_SIGNALS */
1b17e766
EZ
358
359 /* XXX -- assume we have memcpy */
360 /* If rl_set_signals is called twice in a row, don't set the old handler to
361 rl_signal_handler, because that would cause infinite recursion. */
362 if (handler != rl_signal_handler || old_handler.sa_handler != rl_signal_handler)
363 memcpy (ohandler, &old_handler, sizeof (sighandler_cxt));
364
d60d9f65
SS
365 return (ohandler->sa_handler);
366}
367
775e241e
TT
368/* Set disposition of SIG to HANDLER, returning old state in OHANDLER. Don't
369 change disposition if OHANDLER indicates the signal was ignored. */
c862e87b
JM
370static void
371rl_maybe_set_sighandler (sig, handler, ohandler)
372 int sig;
373 SigHandler *handler;
374 sighandler_cxt *ohandler;
d60d9f65
SS
375{
376 sighandler_cxt dummy;
377 SigHandler *oh;
378
d60d9f65 379 sigemptyset (&dummy.sa_mask);
775e241e 380 dummy.sa_flags = 0;
c862e87b 381 oh = rl_set_sighandler (sig, handler, ohandler);
d60d9f65 382 if (oh == (SigHandler *)SIG_IGN)
c862e87b
JM
383 rl_sigaction (sig, ohandler, &dummy);
384}
d60d9f65 385
775e241e
TT
386/* Set the disposition of SIG to HANDLER, if HANDLER->sa_handler indicates the
387 signal was not being ignored. MUST only be called for signals whose
388 disposition was changed using rl_maybe_set_sighandler or for which the
389 SIG_IGN check was performed inline (e.g., SIGALRM below). */
390static void
391rl_maybe_restore_sighandler (sig, handler)
392 int sig;
393 sighandler_cxt *handler;
394{
395 sighandler_cxt dummy;
396
397 sigemptyset (&dummy.sa_mask);
398 dummy.sa_flags = 0;
399 if (handler->sa_handler != SIG_IGN)
400 rl_sigaction (sig, handler, &dummy);
401}
402
c862e87b
JM
403int
404rl_set_signals ()
405{
406 sighandler_cxt dummy;
407 SigHandler *oh;
cc88a640
JK
408#if defined (HAVE_POSIX_SIGNALS)
409 static int sigmask_set = 0;
410 static sigset_t bset, oset;
411#endif
412
413#if defined (HAVE_POSIX_SIGNALS)
414 if (rl_catch_signals && sigmask_set == 0)
415 {
416 sigemptyset (&bset);
417
418 sigaddset (&bset, SIGINT);
419 sigaddset (&bset, SIGTERM);
775e241e
TT
420#if defined (SIGHUP)
421 sigaddset (&bset, SIGHUP);
422#endif
cc88a640
JK
423#if defined (SIGQUIT)
424 sigaddset (&bset, SIGQUIT);
425#endif
426#if defined (SIGALRM)
427 sigaddset (&bset, SIGALRM);
428#endif
429#if defined (SIGTSTP)
430 sigaddset (&bset, SIGTSTP);
431#endif
432#if defined (SIGTTIN)
433 sigaddset (&bset, SIGTTIN);
434#endif
435#if defined (SIGTTOU)
436 sigaddset (&bset, SIGTTOU);
437#endif
438 sigmask_set = 1;
439 }
440#endif /* HAVE_POSIX_SIGNALS */
c862e87b
JM
441
442 if (rl_catch_signals && signals_set_flag == 0)
443 {
cc88a640
JK
444#if defined (HAVE_POSIX_SIGNALS)
445 sigemptyset (&oset);
446 sigprocmask (SIG_BLOCK, &bset, &oset);
447#endif
448
c862e87b
JM
449 rl_maybe_set_sighandler (SIGINT, rl_signal_handler, &old_int);
450 rl_maybe_set_sighandler (SIGTERM, rl_signal_handler, &old_term);
775e241e
TT
451#if defined (SIGHUP)
452 rl_maybe_set_sighandler (SIGHUP, rl_signal_handler, &old_hup);
453#endif
5bdf8622 454#if defined (SIGQUIT)
c862e87b 455 rl_maybe_set_sighandler (SIGQUIT, rl_signal_handler, &old_quit);
430b7832 456#endif
c862e87b 457
5bdf8622 458#if defined (SIGALRM)
c862e87b
JM
459 oh = rl_set_sighandler (SIGALRM, rl_signal_handler, &old_alrm);
460 if (oh == (SigHandler *)SIG_IGN)
461 rl_sigaction (SIGALRM, &old_alrm, &dummy);
d60d9f65 462#if defined (HAVE_POSIX_SIGNALS) && defined (SA_RESTART)
c862e87b
JM
463 /* If the application using readline has already installed a signal
464 handler with SA_RESTART, SIGALRM will cause reads to be restarted
465 automatically, so readline should just get out of the way. Since
466 we tested for SIG_IGN above, we can just test for SIG_DFL here. */
467 if (oh != (SigHandler *)SIG_DFL && (old_alrm.sa_flags & SA_RESTART))
468 rl_sigaction (SIGALRM, &old_alrm, &dummy);
d60d9f65 469#endif /* HAVE_POSIX_SIGNALS */
430b7832 470#endif /* SIGALRM */
d60d9f65 471
d60d9f65 472#if defined (SIGTSTP)
c862e87b 473 rl_maybe_set_sighandler (SIGTSTP, rl_signal_handler, &old_tstp);
d60d9f65
SS
474#endif /* SIGTSTP */
475
476#if defined (SIGTTOU)
c862e87b 477 rl_maybe_set_sighandler (SIGTTOU, rl_signal_handler, &old_ttou);
d60d9f65
SS
478#endif /* SIGTTOU */
479
c862e87b
JM
480#if defined (SIGTTIN)
481 rl_maybe_set_sighandler (SIGTTIN, rl_signal_handler, &old_ttin);
482#endif /* SIGTTIN */
d60d9f65 483
c862e87b 484 signals_set_flag = 1;
cc88a640
JK
485
486#if defined (HAVE_POSIX_SIGNALS)
487 sigprocmask (SIG_SETMASK, &oset, (sigset_t *)NULL);
488#endif
c862e87b 489 }
d60d9f65
SS
490
491#if defined (SIGWINCH)
c862e87b
JM
492 if (rl_catch_sigwinch && sigwinch_set_flag == 0)
493 {
494 rl_maybe_set_sighandler (SIGWINCH, rl_sigwinch_handler, &old_winch);
495 sigwinch_set_flag = 1;
496 }
d60d9f65
SS
497#endif /* SIGWINCH */
498
499 return 0;
500}
501
502int
503rl_clear_signals ()
504{
505 sighandler_cxt dummy;
506
c862e87b
JM
507 if (rl_catch_signals && signals_set_flag == 1)
508 {
509 sigemptyset (&dummy.sa_mask);
d60d9f65 510
775e241e
TT
511 /* Since rl_maybe_set_sighandler doesn't override a SIG_IGN handler,
512 we should in theory not have to restore a handler where
513 old_xxx.sa_handler == SIG_IGN. That's what rl_maybe_restore_sighandler
514 does. Fewer system calls should reduce readline's per-line
515 overhead */
516 rl_maybe_restore_sighandler (SIGINT, &old_int);
517 rl_maybe_restore_sighandler (SIGTERM, &old_term);
518#if defined (SIGHUP)
519 rl_maybe_restore_sighandler (SIGHUP, &old_hup);
520#endif
5bdf8622 521#if defined (SIGQUIT)
775e241e 522 rl_maybe_restore_sighandler (SIGQUIT, &old_quit);
430b7832 523#endif
5bdf8622 524#if defined (SIGALRM)
775e241e 525 rl_maybe_restore_sighandler (SIGALRM, &old_alrm);
430b7832 526#endif
d60d9f65
SS
527
528#if defined (SIGTSTP)
775e241e 529 rl_maybe_restore_sighandler (SIGTSTP, &old_tstp);
c862e87b 530#endif /* SIGTSTP */
d60d9f65
SS
531
532#if defined (SIGTTOU)
775e241e 533 rl_maybe_restore_sighandler (SIGTTOU, &old_ttou);
d60d9f65
SS
534#endif /* SIGTTOU */
535
c862e87b 536#if defined (SIGTTIN)
775e241e 537 rl_maybe_restore_sighandler (SIGTTIN, &old_ttin);
c862e87b 538#endif /* SIGTTIN */
d60d9f65 539
c862e87b
JM
540 signals_set_flag = 0;
541 }
d60d9f65
SS
542
543#if defined (SIGWINCH)
c862e87b
JM
544 if (rl_catch_sigwinch && sigwinch_set_flag == 1)
545 {
546 sigemptyset (&dummy.sa_mask);
547 rl_sigaction (SIGWINCH, &old_winch, &dummy);
548 sigwinch_set_flag = 0;
549 }
d60d9f65
SS
550#endif
551
552 return 0;
553}
c862e87b
JM
554
555/* Clean up the terminal and readline state after catching a signal, before
556 resending it to the calling application. */
557void
558rl_cleanup_after_signal ()
559{
560 _rl_clean_up_for_exit ();
5bdf8622
DJ
561 if (rl_deprep_term_function)
562 (*rl_deprep_term_function) ();
9255ee31 563 rl_clear_pending_input ();
cc88a640 564 rl_clear_signals ();
c862e87b
JM
565}
566
567/* Reset the terminal and readline state after a signal handler returns. */
568void
569rl_reset_after_signal ()
570{
5bdf8622
DJ
571 if (rl_prep_term_function)
572 (*rl_prep_term_function) (_rl_meta_flag);
c862e87b
JM
573 rl_set_signals ();
574}
575
576/* Free up the readline variable line state for the current line (undo list,
577 any partial history entry, any keyboard macros in progress, and any
578 numeric arguments in process) after catching a signal, before calling
579 rl_cleanup_after_signal(). */
580void
581rl_free_line_state ()
582{
583 register HIST_ENTRY *entry;
584
9255ee31 585 rl_free_undo_list ();
c862e87b
JM
586
587 entry = current_history ();
588 if (entry)
589 entry->data = (char *)NULL;
590
591 _rl_kill_kbd_macro ();
592 rl_clear_message ();
5bdf8622 593 _rl_reset_argument ();
c862e87b
JM
594}
595
775e241e
TT
596int
597rl_pending_signal ()
598{
599 return (_rl_caught_signal);
600}
d60d9f65 601#endif /* HANDLE_SIGNALS */
cc88a640
JK
602
603/* **************************************************************** */
604/* */
605/* SIGINT Management */
606/* */
607/* **************************************************************** */
608
609#if defined (HAVE_POSIX_SIGNALS)
610static sigset_t sigint_set, sigint_oset;
611static sigset_t sigwinch_set, sigwinch_oset;
612#else /* !HAVE_POSIX_SIGNALS */
613# if defined (HAVE_BSD_SIGNALS)
614static int sigint_oldmask;
615static int sigwinch_oldmask;
616# endif /* HAVE_BSD_SIGNALS */
617#endif /* !HAVE_POSIX_SIGNALS */
618
619static int sigint_blocked;
620static int sigwinch_blocked;
621
622/* Cause SIGINT to not be delivered until the corresponding call to
623 release_sigint(). */
624void
625_rl_block_sigint ()
626{
627 if (sigint_blocked)
628 return;
629
cc88a640
JK
630 sigint_blocked = 1;
631}
632
633/* Allow SIGINT to be delivered. */
634void
635_rl_release_sigint ()
636{
637 if (sigint_blocked == 0)
638 return;
639
cc88a640 640 sigint_blocked = 0;
775e241e 641 RL_CHECK_SIGNALS ();
cc88a640
JK
642}
643
644/* Cause SIGWINCH to not be delivered until the corresponding call to
645 release_sigwinch(). */
646void
647_rl_block_sigwinch ()
648{
649 if (sigwinch_blocked)
650 return;
651
775e241e
TT
652#if defined (SIGWINCH)
653
cc88a640
JK
654#if defined (HAVE_POSIX_SIGNALS)
655 sigemptyset (&sigwinch_set);
656 sigemptyset (&sigwinch_oset);
657 sigaddset (&sigwinch_set, SIGWINCH);
658 sigprocmask (SIG_BLOCK, &sigwinch_set, &sigwinch_oset);
659#else /* !HAVE_POSIX_SIGNALS */
660# if defined (HAVE_BSD_SIGNALS)
661 sigwinch_oldmask = sigblock (sigmask (SIGWINCH));
662# else /* !HAVE_BSD_SIGNALS */
663# if defined (HAVE_USG_SIGHOLD)
664 sighold (SIGWINCH);
665# endif /* HAVE_USG_SIGHOLD */
666# endif /* !HAVE_BSD_SIGNALS */
667#endif /* !HAVE_POSIX_SIGNALS */
668
775e241e
TT
669#endif /* SIGWINCH */
670
cc88a640
JK
671 sigwinch_blocked = 1;
672}
673
674/* Allow SIGWINCH to be delivered. */
675void
676_rl_release_sigwinch ()
677{
678 if (sigwinch_blocked == 0)
679 return;
680
775e241e
TT
681#if defined (SIGWINCH)
682
cc88a640
JK
683#if defined (HAVE_POSIX_SIGNALS)
684 sigprocmask (SIG_SETMASK, &sigwinch_oset, (sigset_t *)NULL);
685#else
686# if defined (HAVE_BSD_SIGNALS)
687 sigsetmask (sigwinch_oldmask);
688# else /* !HAVE_BSD_SIGNALS */
689# if defined (HAVE_USG_SIGHOLD)
690 sigrelse (SIGWINCH);
691# endif /* HAVE_USG_SIGHOLD */
692# endif /* !HAVE_BSD_SIGNALS */
693#endif /* !HAVE_POSIX_SIGNALS */
694
775e241e
TT
695#endif /* SIGWINCH */
696
cc88a640
JK
697 sigwinch_blocked = 0;
698}
699
700/* **************************************************************** */
701/* */
702/* Echoing special control characters */
703/* */
704/* **************************************************************** */
705void
706rl_echo_signal_char (sig)
707 int sig;
708{
709 char cstr[3];
710 int cslen, c;
711
712 if (_rl_echoctl == 0 || _rl_echo_control_chars == 0)
713 return;
714
715 switch (sig)
716 {
717 case SIGINT: c = _rl_intr_char; break;
718#if defined (SIGQUIT)
719 case SIGQUIT: c = _rl_quit_char; break;
720#endif
721#if defined (SIGTSTP)
722 case SIGTSTP: c = _rl_susp_char; break;
723#endif
724 default: return;
725 }
726
727 if (CTRL_CHAR (c) || c == RUBOUT)
728 {
729 cstr[0] = '^';
730 cstr[1] = CTRL_CHAR (c) ? UNCTRL (c) : '?';
731 cstr[cslen = 2] = '\0';
732 }
733 else
734 {
735 cstr[0] = c;
736 cstr[cslen = 1] = '\0';
737 }
738
739 _rl_output_some_chars (cstr, cslen);
740}
This page took 0.984285 seconds and 4 git commands to generate.