]> git.ipfire.org Git - thirdparty/bash.git/blame - lib/readline/signals.c
Bash-4.1 distribution source
[thirdparty/bash.git] / lib / readline / signals.c
CommitLineData
726f6388
JA
1/* signals.c -- signal handling support for readline. */
2
3185942a 3/* Copyright (C) 1987-2009 Free Software Foundation, Inc.
726f6388 4
3185942a
JA
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.
726f6388 7
3185942a
JA
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
726f6388
JA
11 (at your option) any later version.
12
3185942a
JA
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
726f6388
JA
16 GNU General Public License for more details.
17
3185942a
JA
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
726f6388
JA
22#define READLINE_LIBRARY
23
ccc6cda3
JA
24#if defined (HAVE_CONFIG_H)
25# include <config.h>
26#endif
27
28#include <stdio.h> /* Just for NULL. Yuck. */
726f6388 29#include <sys/types.h>
726f6388
JA
30#include <signal.h>
31
32#if defined (HAVE_UNISTD_H)
33# include <unistd.h>
34#endif /* HAVE_UNISTD_H */
35
726f6388
JA
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
43/* Some standard library routines. */
44#include "readline.h"
45#include "history.h"
46
bb70624e
JA
47#include "rlprivate.h"
48
3185942a
JA
49#if defined (HANDLE_SIGNALS)
50
ccc6cda3
JA
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 */
726f6388
JA
58
59#if defined (VOID_SIGHANDLER)
ccc6cda3 60# define SIGHANDLER_RETURN return
726f6388 61#else
ccc6cda3
JA
62# define SIGHANDLER_RETURN return (0)
63#endif
726f6388 64
28ef6c31 65/* This typedef is equivalent to the one for Function; it allows us
726f6388 66 to say SigHandler *foo = signal (SIGKILL, SIG_IGN); */
ccc6cda3 67typedef RETSIGTYPE SigHandler ();
726f6388 68
bb70624e
JA
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 */
b72432fd 76
b80f6443
JA
77#ifndef SA_RESTART
78# define SA_RESTART 0
79#endif
80
f73dda09 81static SigHandler *rl_set_sighandler PARAMS((int, SigHandler *, sighandler_cxt *));
7117c2d2 82static void rl_maybe_set_sighandler PARAMS((int, SigHandler *, sighandler_cxt *));
726f6388 83
17345e5a
JA
84static RETSIGTYPE rl_signal_handler PARAMS((int));
85static RETSIGTYPE _rl_handle_signal PARAMS((int));
86
b72432fd
JA
87/* Exported variables for use by applications. */
88
89/* If non-zero, readline will install its own signal handlers for
90 SIGINT, SIGTERM, SIGQUIT, SIGALRM, SIGTSTP, SIGTTIN, and SIGTTOU. */
91int rl_catch_signals = 1;
92
93/* If non-zero, readline will install a signal handler for SIGWINCH. */
94#ifdef SIGWINCH
95int rl_catch_sigwinch = 1;
b80f6443
JA
96#else
97int rl_catch_sigwinch = 0; /* for the readline state struct in readline.c */
b72432fd
JA
98#endif
99
3185942a 100/* Private variables. */
17345e5a
JA
101int _rl_interrupt_immediately = 0;
102int volatile _rl_caught_signal = 0; /* should be sig_atomic_t, but that requires including <signal.h> everywhere */
103
0001803f
CR
104/* If non-zero, print characters corresponding to received signals as long as
105 the user has indicated his desire to do so (_rl_echo_control_chars). */
3185942a
JA
106int _rl_echoctl = 0;
107
108int _rl_intr_char = 0;
109int _rl_quit_char = 0;
110int _rl_susp_char = 0;
111
b72432fd
JA
112static int signals_set_flag;
113static int sigwinch_set_flag;
114
726f6388
JA
115/* **************************************************************** */
116/* */
117/* Signal Handling */
118/* */
119/* **************************************************************** */
120
b72432fd
JA
121static sighandler_cxt old_int, old_term, old_alrm, old_quit;
122#if defined (SIGTSTP)
d166f048 123static sighandler_cxt old_tstp, old_ttou, old_ttin;
d166f048 124#endif
ccc6cda3
JA
125#if defined (SIGWINCH)
126static sighandler_cxt old_winch;
127#endif
128
129/* Readline signal handler functions. */
130
17345e5a
JA
131/* Called from RL_CHECK_SIGNALS() macro */
132RETSIGTYPE
133_rl_signal_handler (sig)
134{
135 _rl_caught_signal = 0; /* XXX */
136
137 _rl_handle_signal (sig);
138 SIGHANDLER_RETURN;
139}
140
ccc6cda3 141static RETSIGTYPE
726f6388
JA
142rl_signal_handler (sig)
143 int sig;
17345e5a 144{
0001803f 145 if (_rl_interrupt_immediately || RL_ISSTATE(RL_STATE_CALLBACK))
17345e5a
JA
146 {
147 _rl_interrupt_immediately = 0;
148 _rl_handle_signal (sig);
149 }
0001803f
CR
150 else
151 _rl_caught_signal = sig;
17345e5a 152
17345e5a
JA
153 SIGHANDLER_RETURN;
154}
155
156static RETSIGTYPE
157_rl_handle_signal (sig)
158 int sig;
726f6388
JA
159{
160#if defined (HAVE_POSIX_SIGNALS)
161 sigset_t set;
162#else /* !HAVE_POSIX_SIGNALS */
163# if defined (HAVE_BSD_SIGNALS)
164 long omask;
d166f048
JA
165# else /* !HAVE_BSD_SIGNALS */
166 sighandler_cxt dummy_cxt; /* needed for rl_set_sighandler call */
167# endif /* !HAVE_BSD_SIGNALS */
726f6388
JA
168#endif /* !HAVE_POSIX_SIGNALS */
169
28ef6c31
JA
170 RL_SETSTATE(RL_STATE_SIGHANDLER);
171
726f6388
JA
172#if !defined (HAVE_BSD_SIGNALS) && !defined (HAVE_POSIX_SIGNALS)
173 /* Since the signal will not be blocked while we are in the signal
174 handler, ignore it until rl_clear_signals resets the catcher. */
95732b49 175# if defined (SIGALRM)
ccc6cda3 176 if (sig == SIGINT || sig == SIGALRM)
95732b49
JA
177# else
178 if (sig == SIGINT)
179# endif
d166f048 180 rl_set_sighandler (sig, SIG_IGN, &dummy_cxt);
ccc6cda3 181#endif /* !HAVE_BSD_SIGNALS && !HAVE_POSIX_SIGNALS */
726f6388
JA
182
183 switch (sig)
184 {
185 case SIGINT:
3185942a 186 _rl_reset_completion_state ();
b72432fd
JA
187 rl_free_line_state ();
188 /* FALLTHROUGH */
726f6388 189
95732b49 190 case SIGTERM:
726f6388
JA
191#if defined (SIGTSTP)
192 case SIGTSTP:
193 case SIGTTOU:
194 case SIGTTIN:
195#endif /* SIGTSTP */
95732b49 196#if defined (SIGALRM)
726f6388 197 case SIGALRM:
95732b49
JA
198#endif
199#if defined (SIGQUIT)
b72432fd 200 case SIGQUIT:
95732b49 201#endif
3185942a 202 rl_echo_signal_char (sig);
b72432fd 203 rl_cleanup_after_signal ();
726f6388
JA
204
205#if defined (HAVE_POSIX_SIGNALS)
0628567a 206 sigemptyset (&set);
726f6388
JA
207 sigprocmask (SIG_BLOCK, (sigset_t *)NULL, &set);
208 sigdelset (&set, sig);
209#else /* !HAVE_POSIX_SIGNALS */
210# if defined (HAVE_BSD_SIGNALS)
211 omask = sigblock (0);
212# endif /* HAVE_BSD_SIGNALS */
213#endif /* !HAVE_POSIX_SIGNALS */
214
bb70624e
JA
215#if defined (__EMX__)
216 signal (sig, SIG_ACK);
217#endif
218
95732b49 219#if defined (HAVE_KILL)
726f6388 220 kill (getpid (), sig);
95732b49
JA
221#else
222 raise (sig); /* assume we have raise */
223#endif
726f6388
JA
224
225 /* Let the signal that we just sent through. */
226#if defined (HAVE_POSIX_SIGNALS)
227 sigprocmask (SIG_SETMASK, &set, (sigset_t *)NULL);
228#else /* !HAVE_POSIX_SIGNALS */
229# if defined (HAVE_BSD_SIGNALS)
230 sigsetmask (omask & ~(sigmask (sig)));
231# endif /* HAVE_BSD_SIGNALS */
232#endif /* !HAVE_POSIX_SIGNALS */
233
b72432fd 234 rl_reset_after_signal ();
726f6388
JA
235 }
236
28ef6c31 237 RL_UNSETSTATE(RL_STATE_SIGHANDLER);
ccc6cda3 238 SIGHANDLER_RETURN;
726f6388
JA
239}
240
ccc6cda3
JA
241#if defined (SIGWINCH)
242static RETSIGTYPE
b72432fd 243rl_sigwinch_handler (sig)
ccc6cda3
JA
244 int sig;
245{
246 SigHandler *oh;
247
d166f048
JA
248#if defined (MUST_REINSTALL_SIGHANDLERS)
249 sighandler_cxt dummy_winch;
250
251 /* We don't want to change old_winch -- it holds the state of SIGWINCH
252 disposition set by the calling application. We need this state
253 because we call the application's SIGWINCH handler after updating
254 our own idea of the screen size. */
b72432fd 255 rl_set_sighandler (SIGWINCH, rl_sigwinch_handler, &dummy_winch);
d166f048
JA
256#endif
257
28ef6c31 258 RL_SETSTATE(RL_STATE_SIGHANDLER);
b72432fd 259 rl_resize_terminal ();
ccc6cda3
JA
260
261 /* If another sigwinch handler has been installed, call it. */
262 oh = (SigHandler *)old_winch.sa_handler;
263 if (oh && oh != (SigHandler *)SIG_IGN && oh != (SigHandler *)SIG_DFL)
264 (*oh) (sig);
265
28ef6c31 266 RL_UNSETSTATE(RL_STATE_SIGHANDLER);
ccc6cda3
JA
267 SIGHANDLER_RETURN;
268}
269#endif /* SIGWINCH */
270
271/* Functions to manage signal handling. */
272
273#if !defined (HAVE_POSIX_SIGNALS)
274static int
275rl_sigaction (sig, nh, oh)
276 int sig;
277 sighandler_cxt *nh, *oh;
278{
279 oh->sa_handler = signal (sig, nh->sa_handler);
280 return 0;
281}
282#endif /* !HAVE_POSIX_SIGNALS */
283
284/* Set up a readline-specific signal handler, saving the old signal
285 information in OHANDLER. Return the old signal handler, like
286 signal(). */
726f6388 287static SigHandler *
ccc6cda3 288rl_set_sighandler (sig, handler, ohandler)
726f6388
JA
289 int sig;
290 SigHandler *handler;
ccc6cda3 291 sighandler_cxt *ohandler;
726f6388 292{
bb70624e 293 sighandler_cxt old_handler;
ccc6cda3
JA
294#if defined (HAVE_POSIX_SIGNALS)
295 struct sigaction act;
726f6388
JA
296
297 act.sa_handler = handler;
3185942a 298# if defined (SIGWINCH)
b80f6443 299 act.sa_flags = (sig == SIGWINCH) ? SA_RESTART : 0;
3185942a
JA
300# else
301 act.sa_flags = 0;
302# endif /* SIGWINCH */
726f6388 303 sigemptyset (&act.sa_mask);
ccc6cda3 304 sigemptyset (&ohandler->sa_mask);
bb70624e 305 sigaction (sig, &act, &old_handler);
ccc6cda3 306#else
bb70624e 307 old_handler.sa_handler = (SigHandler *)signal (sig, handler);
726f6388 308#endif /* !HAVE_POSIX_SIGNALS */
bb70624e
JA
309
310 /* XXX -- assume we have memcpy */
311 /* If rl_set_signals is called twice in a row, don't set the old handler to
312 rl_signal_handler, because that would cause infinite recursion. */
313 if (handler != rl_signal_handler || old_handler.sa_handler != rl_signal_handler)
314 memcpy (ohandler, &old_handler, sizeof (sighandler_cxt));
315
ccc6cda3
JA
316 return (ohandler->sa_handler);
317}
726f6388 318
b72432fd
JA
319static void
320rl_maybe_set_sighandler (sig, handler, ohandler)
321 int sig;
322 SigHandler *handler;
323 sighandler_cxt *ohandler;
726f6388 324{
ccc6cda3
JA
325 sighandler_cxt dummy;
326 SigHandler *oh;
327
ccc6cda3 328 sigemptyset (&dummy.sa_mask);
b72432fd 329 oh = rl_set_sighandler (sig, handler, ohandler);
ccc6cda3 330 if (oh == (SigHandler *)SIG_IGN)
b72432fd
JA
331 rl_sigaction (sig, ohandler, &dummy);
332}
ccc6cda3 333
b72432fd
JA
334int
335rl_set_signals ()
336{
337 sighandler_cxt dummy;
338 SigHandler *oh;
0628567a
JA
339#if defined (HAVE_POSIX_SIGNALS)
340 static int sigmask_set = 0;
341 static sigset_t bset, oset;
342#endif
343
344#if defined (HAVE_POSIX_SIGNALS)
345 if (rl_catch_signals && sigmask_set == 0)
346 {
347 sigemptyset (&bset);
348
349 sigaddset (&bset, SIGINT);
3185942a 350 sigaddset (&bset, SIGTERM);
0628567a
JA
351#if defined (SIGQUIT)
352 sigaddset (&bset, SIGQUIT);
353#endif
354#if defined (SIGALRM)
355 sigaddset (&bset, SIGALRM);
356#endif
357#if defined (SIGTSTP)
358 sigaddset (&bset, SIGTSTP);
359#endif
360#if defined (SIGTTIN)
361 sigaddset (&bset, SIGTTIN);
362#endif
363#if defined (SIGTTOU)
364 sigaddset (&bset, SIGTTOU);
365#endif
366 sigmask_set = 1;
367 }
368#endif /* HAVE_POSIX_SIGNALS */
b72432fd
JA
369
370 if (rl_catch_signals && signals_set_flag == 0)
371 {
0628567a
JA
372#if defined (HAVE_POSIX_SIGNALS)
373 sigemptyset (&oset);
374 sigprocmask (SIG_BLOCK, &bset, &oset);
375#endif
376
b72432fd
JA
377 rl_maybe_set_sighandler (SIGINT, rl_signal_handler, &old_int);
378 rl_maybe_set_sighandler (SIGTERM, rl_signal_handler, &old_term);
95732b49 379#if defined (SIGQUIT)
b72432fd 380 rl_maybe_set_sighandler (SIGQUIT, rl_signal_handler, &old_quit);
95732b49 381#endif
b72432fd 382
95732b49 383#if defined (SIGALRM)
b72432fd
JA
384 oh = rl_set_sighandler (SIGALRM, rl_signal_handler, &old_alrm);
385 if (oh == (SigHandler *)SIG_IGN)
386 rl_sigaction (SIGALRM, &old_alrm, &dummy);
ccc6cda3 387#if defined (HAVE_POSIX_SIGNALS) && defined (SA_RESTART)
b72432fd
JA
388 /* If the application using readline has already installed a signal
389 handler with SA_RESTART, SIGALRM will cause reads to be restarted
390 automatically, so readline should just get out of the way. Since
391 we tested for SIG_IGN above, we can just test for SIG_DFL here. */
392 if (oh != (SigHandler *)SIG_DFL && (old_alrm.sa_flags & SA_RESTART))
393 rl_sigaction (SIGALRM, &old_alrm, &dummy);
ccc6cda3 394#endif /* HAVE_POSIX_SIGNALS */
95732b49 395#endif /* SIGALRM */
726f6388 396
726f6388 397#if defined (SIGTSTP)
b72432fd 398 rl_maybe_set_sighandler (SIGTSTP, rl_signal_handler, &old_tstp);
726f6388 399#endif /* SIGTSTP */
ccc6cda3 400
726f6388 401#if defined (SIGTTOU)
b72432fd 402 rl_maybe_set_sighandler (SIGTTOU, rl_signal_handler, &old_ttou);
726f6388
JA
403#endif /* SIGTTOU */
404
b72432fd
JA
405#if defined (SIGTTIN)
406 rl_maybe_set_sighandler (SIGTTIN, rl_signal_handler, &old_ttin);
407#endif /* SIGTTIN */
d166f048 408
b72432fd 409 signals_set_flag = 1;
0628567a
JA
410
411#if defined (HAVE_POSIX_SIGNALS)
412 sigprocmask (SIG_SETMASK, &oset, (sigset_t *)NULL);
413#endif
b72432fd 414 }
726f6388
JA
415
416#if defined (SIGWINCH)
b72432fd
JA
417 if (rl_catch_sigwinch && sigwinch_set_flag == 0)
418 {
419 rl_maybe_set_sighandler (SIGWINCH, rl_sigwinch_handler, &old_winch);
420 sigwinch_set_flag = 1;
421 }
726f6388 422#endif /* SIGWINCH */
ccc6cda3 423
726f6388
JA
424 return 0;
425}
426
ccc6cda3 427int
726f6388
JA
428rl_clear_signals ()
429{
ccc6cda3
JA
430 sighandler_cxt dummy;
431
b72432fd
JA
432 if (rl_catch_signals && signals_set_flag == 1)
433 {
434 sigemptyset (&dummy.sa_mask);
726f6388 435
b72432fd
JA
436 rl_sigaction (SIGINT, &old_int, &dummy);
437 rl_sigaction (SIGTERM, &old_term, &dummy);
95732b49 438#if defined (SIGQUIT)
b72432fd 439 rl_sigaction (SIGQUIT, &old_quit, &dummy);
95732b49
JA
440#endif
441#if defined (SIGALRM)
b72432fd 442 rl_sigaction (SIGALRM, &old_alrm, &dummy);
95732b49 443#endif
726f6388
JA
444
445#if defined (SIGTSTP)
b72432fd
JA
446 rl_sigaction (SIGTSTP, &old_tstp, &dummy);
447#endif /* SIGTSTP */
726f6388
JA
448
449#if defined (SIGTTOU)
b72432fd 450 rl_sigaction (SIGTTOU, &old_ttou, &dummy);
726f6388
JA
451#endif /* SIGTTOU */
452
b72432fd
JA
453#if defined (SIGTTIN)
454 rl_sigaction (SIGTTIN, &old_ttin, &dummy);
455#endif /* SIGTTIN */
ccc6cda3 456
b72432fd
JA
457 signals_set_flag = 0;
458 }
726f6388
JA
459
460#if defined (SIGWINCH)
b72432fd
JA
461 if (rl_catch_sigwinch && sigwinch_set_flag == 1)
462 {
463 sigemptyset (&dummy.sa_mask);
464 rl_sigaction (SIGWINCH, &old_winch, &dummy);
465 sigwinch_set_flag = 0;
466 }
726f6388
JA
467#endif
468
469 return 0;
470}
b72432fd
JA
471
472/* Clean up the terminal and readline state after catching a signal, before
473 resending it to the calling application. */
474void
475rl_cleanup_after_signal ()
476{
477 _rl_clean_up_for_exit ();
95732b49
JA
478 if (rl_deprep_term_function)
479 (*rl_deprep_term_function) ();
28ef6c31 480 rl_clear_pending_input ();
0628567a 481 rl_clear_signals ();
b72432fd
JA
482}
483
484/* Reset the terminal and readline state after a signal handler returns. */
485void
486rl_reset_after_signal ()
487{
95732b49
JA
488 if (rl_prep_term_function)
489 (*rl_prep_term_function) (_rl_meta_flag);
b72432fd
JA
490 rl_set_signals ();
491}
492
493/* Free up the readline variable line state for the current line (undo list,
494 any partial history entry, any keyboard macros in progress, and any
495 numeric arguments in process) after catching a signal, before calling
496 rl_cleanup_after_signal(). */
497void
498rl_free_line_state ()
499{
500 register HIST_ENTRY *entry;
501
28ef6c31 502 rl_free_undo_list ();
b72432fd
JA
503
504 entry = current_history ();
505 if (entry)
506 entry->data = (char *)NULL;
507
508 _rl_kill_kbd_macro ();
509 rl_clear_message ();
95732b49 510 _rl_reset_argument ();
b72432fd
JA
511}
512
726f6388 513#endif /* HANDLE_SIGNALS */
3185942a
JA
514
515/* **************************************************************** */
516/* */
517/* SIGINT Management */
518/* */
519/* **************************************************************** */
520
521#if defined (HAVE_POSIX_SIGNALS)
522static sigset_t sigint_set, sigint_oset;
0001803f 523static sigset_t sigwinch_set, sigwinch_oset;
3185942a
JA
524#else /* !HAVE_POSIX_SIGNALS */
525# if defined (HAVE_BSD_SIGNALS)
526static int sigint_oldmask;
0001803f 527static int sigwinch_oldmask;
3185942a
JA
528# endif /* HAVE_BSD_SIGNALS */
529#endif /* !HAVE_POSIX_SIGNALS */
530
531static int sigint_blocked;
0001803f 532static int sigwinch_blocked;
3185942a
JA
533
534/* Cause SIGINT to not be delivered until the corresponding call to
535 release_sigint(). */
536void
537_rl_block_sigint ()
538{
539 if (sigint_blocked)
540 return;
541
542#if defined (HAVE_POSIX_SIGNALS)
543 sigemptyset (&sigint_set);
544 sigemptyset (&sigint_oset);
545 sigaddset (&sigint_set, SIGINT);
546 sigprocmask (SIG_BLOCK, &sigint_set, &sigint_oset);
547#else /* !HAVE_POSIX_SIGNALS */
548# if defined (HAVE_BSD_SIGNALS)
549 sigint_oldmask = sigblock (sigmask (SIGINT));
550# else /* !HAVE_BSD_SIGNALS */
551# if defined (HAVE_USG_SIGHOLD)
552 sighold (SIGINT);
553# endif /* HAVE_USG_SIGHOLD */
554# endif /* !HAVE_BSD_SIGNALS */
555#endif /* !HAVE_POSIX_SIGNALS */
556
557 sigint_blocked = 1;
558}
559
560/* Allow SIGINT to be delivered. */
561void
562_rl_release_sigint ()
563{
564 if (sigint_blocked == 0)
565 return;
566
567#if defined (HAVE_POSIX_SIGNALS)
568 sigprocmask (SIG_SETMASK, &sigint_oset, (sigset_t *)NULL);
569#else
570# if defined (HAVE_BSD_SIGNALS)
571 sigsetmask (sigint_oldmask);
572# else /* !HAVE_BSD_SIGNALS */
573# if defined (HAVE_USG_SIGHOLD)
574 sigrelse (SIGINT);
575# endif /* HAVE_USG_SIGHOLD */
576# endif /* !HAVE_BSD_SIGNALS */
577#endif /* !HAVE_POSIX_SIGNALS */
578
579 sigint_blocked = 0;
580}
581
0001803f
CR
582/* Cause SIGWINCH to not be delivered until the corresponding call to
583 release_sigwinch(). */
584void
585_rl_block_sigwinch ()
586{
587 if (sigwinch_blocked)
588 return;
589
590#if defined (HAVE_POSIX_SIGNALS)
591 sigemptyset (&sigwinch_set);
592 sigemptyset (&sigwinch_oset);
593 sigaddset (&sigwinch_set, SIGWINCH);
594 sigprocmask (SIG_BLOCK, &sigwinch_set, &sigwinch_oset);
595#else /* !HAVE_POSIX_SIGNALS */
596# if defined (HAVE_BSD_SIGNALS)
597 sigwinch_oldmask = sigblock (sigmask (SIGWINCH));
598# else /* !HAVE_BSD_SIGNALS */
599# if defined (HAVE_USG_SIGHOLD)
600 sighold (SIGWINCH);
601# endif /* HAVE_USG_SIGHOLD */
602# endif /* !HAVE_BSD_SIGNALS */
603#endif /* !HAVE_POSIX_SIGNALS */
604
605 sigwinch_blocked = 1;
606}
607
608/* Allow SIGWINCH to be delivered. */
609void
610_rl_release_sigwinch ()
611{
612 if (sigwinch_blocked == 0)
613 return;
614
615#if defined (HAVE_POSIX_SIGNALS)
616 sigprocmask (SIG_SETMASK, &sigwinch_oset, (sigset_t *)NULL);
617#else
618# if defined (HAVE_BSD_SIGNALS)
619 sigsetmask (sigwinch_oldmask);
620# else /* !HAVE_BSD_SIGNALS */
621# if defined (HAVE_USG_SIGHOLD)
622 sigrelse (SIGWINCH);
623# endif /* HAVE_USG_SIGHOLD */
624# endif /* !HAVE_BSD_SIGNALS */
625#endif /* !HAVE_POSIX_SIGNALS */
626
627 sigwinch_blocked = 0;
628}
629
3185942a
JA
630/* **************************************************************** */
631/* */
632/* Echoing special control characters */
633/* */
634/* **************************************************************** */
635void
636rl_echo_signal_char (sig)
637 int sig;
638{
639 char cstr[3];
640 int cslen, c;
641
0001803f 642 if (_rl_echoctl == 0 || _rl_echo_control_chars == 0)
3185942a
JA
643 return;
644
645 switch (sig)
646 {
647 case SIGINT: c = _rl_intr_char; break;
0001803f 648#if defined (SIGQUIT)
3185942a 649 case SIGQUIT: c = _rl_quit_char; break;
0001803f
CR
650#endif
651#if defined (SIGTSTP)
3185942a 652 case SIGTSTP: c = _rl_susp_char; break;
0001803f 653#endif
3185942a
JA
654 default: return;
655 }
656
657 if (CTRL_CHAR (c) || c == RUBOUT)
658 {
659 cstr[0] = '^';
660 cstr[1] = CTRL_CHAR (c) ? UNCTRL (c) : '?';
661 cstr[cslen = 2] = '\0';
662 }
663 else
664 {
665 cstr[0] = c;
666 cstr[cslen = 1] = '\0';
667 }
668
669 _rl_output_some_chars (cstr, cslen);
670}