Sync readline/ to version 7.0 alpha
[deliverable/binutils-gdb.git] / readline / signals.c
1 /* signals.c -- signal handling support for readline. */
2
3 /* Copyright (C) 1987-2011 Free Software Foundation, Inc.
4
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.
7
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
11 (at your option) any later version.
12
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
16 GNU General Public License for more details.
17
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
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
43 /* Some standard library routines. */
44 #include "readline.h"
45 #include "history.h"
46
47 #include "rlprivate.h"
48
49 #if defined (HANDLE_SIGNALS)
50
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
65 /* This typedef is equivalent to the one for Function; it allows us
66 to say SigHandler *foo = signal (SIGKILL, SIG_IGN); */
67 typedef RETSIGTYPE SigHandler ();
68
69 #if defined (HAVE_POSIX_SIGNALS)
70 typedef struct sigaction sighandler_cxt;
71 # define rl_sigaction(s, nh, oh) sigaction(s, nh, oh)
72 #else
73 typedef struct { SigHandler *sa_handler; int sa_mask, sa_flags; } sighandler_cxt;
74 # define sigemptyset(m)
75 #endif /* !HAVE_POSIX_SIGNALS */
76
77 #ifndef SA_RESTART
78 # define SA_RESTART 0
79 #endif
80
81 static SigHandler *rl_set_sighandler PARAMS((int, SigHandler *, sighandler_cxt *));
82 static void rl_maybe_set_sighandler PARAMS((int, SigHandler *, sighandler_cxt *));
83 static void rl_maybe_restore_sighandler PARAMS((int, sighandler_cxt *));
84
85 static RETSIGTYPE rl_signal_handler PARAMS((int));
86 static RETSIGTYPE _rl_handle_signal PARAMS((int));
87
88 /* Exported variables for use by applications. */
89
90 /* If non-zero, readline will install its own signal handlers for
91 SIGINT, SIGTERM, SIGHUP, SIGQUIT, SIGALRM, SIGTSTP, SIGTTIN, and SIGTTOU. */
92 int rl_catch_signals = 1;
93
94 /* If non-zero, readline will install a signal handler for SIGWINCH. */
95 #ifdef SIGWINCH
96 int rl_catch_sigwinch = 1;
97 #else
98 int rl_catch_sigwinch = 0; /* for the readline state struct in readline.c */
99 #endif
100
101 /* Private variables. */
102 int _rl_interrupt_immediately = 0;
103 int 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). */
107 int _rl_echoctl = 0;
108
109 int _rl_intr_char = 0;
110 int _rl_quit_char = 0;
111 int _rl_susp_char = 0;
112
113 static int signals_set_flag;
114 static int sigwinch_set_flag;
115
116 /* **************************************************************** */
117 /* */
118 /* Signal Handling */
119 /* */
120 /* **************************************************************** */
121
122 static sighandler_cxt old_int, old_term, old_hup, old_alrm, old_quit;
123 #if defined (SIGTSTP)
124 static sighandler_cxt old_tstp, old_ttou, old_ttin;
125 #endif
126 #if defined (SIGWINCH)
127 static sighandler_cxt old_winch;
128 #endif
129
130 _rl_sigcleanup_func_t *_rl_sigcleanup;
131 void *_rl_sigcleanarg;
132
133 /* Readline signal handler functions. */
134
135 /* Called from RL_CHECK_SIGNALS() macro */
136 RETSIGTYPE
137 _rl_signal_handler (sig)
138 int sig;
139 {
140 _rl_caught_signal = 0; /* XXX */
141
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
157 SIGHANDLER_RETURN;
158 }
159
160 static RETSIGTYPE
161 rl_signal_handler (sig)
162 int sig;
163 {
164 if (_rl_interrupt_immediately)
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
175 static RETSIGTYPE
176 _rl_handle_signal (sig)
177 int sig;
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
189 RL_SETSTATE(RL_STATE_SIGHANDLER);
190
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. */
194 # if defined (SIGALRM)
195 if (sig == SIGINT || sig == SIGALRM)
196 # else
197 if (sig == SIGINT)
198 # endif
199 rl_set_sighandler (sig, SIG_IGN, &dummy_cxt);
200 #endif /* !HAVE_BSD_SIGNALS && !HAVE_POSIX_SIGNALS */
201
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
211 switch (sig)
212 {
213 case SIGINT:
214 _rl_reset_completion_state ();
215 rl_free_line_state ();
216 #if defined (READLINE_CALLBACKS)
217 rl_callback_sigcleanup ();
218 #endif
219
220 /* FALLTHROUGH */
221
222 #if defined (SIGTSTP)
223 case SIGTSTP:
224 case SIGTTIN:
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:
236 #endif /* SIGTSTP */
237 case SIGTERM:
238 case SIGHUP:
239 #if defined (SIGALRM)
240 case SIGALRM:
241 #endif
242 #if defined (SIGQUIT)
243 case SIGQUIT:
244 #endif
245 rl_echo_signal_char (sig);
246 rl_cleanup_after_signal ();
247
248 #if defined (HAVE_POSIX_SIGNALS)
249 /* Unblock SIGTTOU blocked above */
250 if (sig == SIGTTIN || sig == SIGTSTP)
251 sigprocmask (SIG_UNBLOCK, &set, (sigset_t *)NULL);
252
253 sigemptyset (&set);
254 sigprocmask (SIG_BLOCK, (sigset_t *)NULL, &set);
255 sigdelset (&set, sig);
256 #else /* !HAVE_POSIX_SIGNALS */
257 # if defined (HAVE_BSD_SIGNALS)
258 omask = sigblock (0);
259 # endif /* HAVE_BSD_SIGNALS */
260 #endif /* !HAVE_POSIX_SIGNALS */
261
262 #if defined (__EMX__)
263 signal (sig, SIG_ACK);
264 #endif
265
266 #if defined (HAVE_KILL)
267 kill (getpid (), sig);
268 #else
269 raise (sig); /* assume we have raise */
270 #endif
271
272 /* Let the signal that we just sent through. */
273 #if defined (HAVE_POSIX_SIGNALS)
274 sigprocmask (SIG_SETMASK, &set, (sigset_t *)NULL);
275 #else /* !HAVE_POSIX_SIGNALS */
276 # if defined (HAVE_BSD_SIGNALS)
277 sigsetmask (omask & ~(sigmask (sig)));
278 # endif /* HAVE_BSD_SIGNALS */
279 #endif /* !HAVE_POSIX_SIGNALS */
280
281 rl_reset_after_signal ();
282 }
283
284 RL_UNSETSTATE(RL_STATE_SIGHANDLER);
285 SIGHANDLER_RETURN;
286 }
287
288 #if defined (SIGWINCH)
289 static RETSIGTYPE
290 rl_sigwinch_handler (sig)
291 int sig;
292 {
293 SigHandler *oh;
294
295 #if defined (MUST_REINSTALL_SIGHANDLERS)
296 sighandler_cxt dummy_winch;
297
298 /* We don't want to change old_winch -- it holds the state of SIGWINCH
299 disposition set by the calling application. We need this state
300 because we call the application's SIGWINCH handler after updating
301 our own idea of the screen size. */
302 rl_set_sighandler (SIGWINCH, rl_sigwinch_handler, &dummy_winch);
303 #endif
304
305 RL_SETSTATE(RL_STATE_SIGHANDLER);
306 _rl_caught_signal = sig;
307
308 /* If another sigwinch handler has been installed, call it. */
309 oh = (SigHandler *)old_winch.sa_handler;
310 if (oh && oh != (SigHandler *)SIG_IGN && oh != (SigHandler *)SIG_DFL)
311 (*oh) (sig);
312
313 RL_UNSETSTATE(RL_STATE_SIGHANDLER);
314 SIGHANDLER_RETURN;
315 }
316 #endif /* SIGWINCH */
317
318 /* Functions to manage signal handling. */
319
320 #if !defined (HAVE_POSIX_SIGNALS)
321 static int
322 rl_sigaction (sig, nh, oh)
323 int sig;
324 sighandler_cxt *nh, *oh;
325 {
326 oh->sa_handler = signal (sig, nh->sa_handler);
327 return 0;
328 }
329 #endif /* !HAVE_POSIX_SIGNALS */
330
331 /* Set up a readline-specific signal handler, saving the old signal
332 information in OHANDLER. Return the old signal handler, like
333 signal(). */
334 static SigHandler *
335 rl_set_sighandler (sig, handler, ohandler)
336 int sig;
337 SigHandler *handler;
338 sighandler_cxt *ohandler;
339 {
340 sighandler_cxt old_handler;
341 #if defined (HAVE_POSIX_SIGNALS)
342 struct sigaction act;
343
344 act.sa_handler = handler;
345 # if defined (SIGWINCH)
346 act.sa_flags = (sig == SIGWINCH) ? SA_RESTART : 0;
347 # else
348 act.sa_flags = 0;
349 # endif /* SIGWINCH */
350 sigemptyset (&act.sa_mask);
351 sigemptyset (&ohandler->sa_mask);
352 sigaction (sig, &act, &old_handler);
353 #else
354 old_handler.sa_handler = (SigHandler *)signal (sig, handler);
355 #endif /* !HAVE_POSIX_SIGNALS */
356
357 /* XXX -- assume we have memcpy */
358 /* If rl_set_signals is called twice in a row, don't set the old handler to
359 rl_signal_handler, because that would cause infinite recursion. */
360 if (handler != rl_signal_handler || old_handler.sa_handler != rl_signal_handler)
361 memcpy (ohandler, &old_handler, sizeof (sighandler_cxt));
362
363 return (ohandler->sa_handler);
364 }
365
366 /* Set disposition of SIG to HANDLER, returning old state in OHANDLER. Don't
367 change disposition if OHANDLER indicates the signal was ignored. */
368 static void
369 rl_maybe_set_sighandler (sig, handler, ohandler)
370 int sig;
371 SigHandler *handler;
372 sighandler_cxt *ohandler;
373 {
374 sighandler_cxt dummy;
375 SigHandler *oh;
376
377 sigemptyset (&dummy.sa_mask);
378 dummy.sa_flags = 0;
379 oh = rl_set_sighandler (sig, handler, ohandler);
380 if (oh == (SigHandler *)SIG_IGN)
381 rl_sigaction (sig, ohandler, &dummy);
382 }
383
384 /* Set the disposition of SIG to HANDLER, if HANDLER->sa_handler indicates the
385 signal was not being ignored. MUST only be called for signals whose
386 disposition was changed using rl_maybe_set_sighandler or for which the
387 SIG_IGN check was performed inline (e.g., SIGALRM below). */
388 static void
389 rl_maybe_restore_sighandler (sig, handler)
390 int sig;
391 sighandler_cxt *handler;
392 {
393 sighandler_cxt dummy;
394
395 sigemptyset (&dummy.sa_mask);
396 dummy.sa_flags = 0;
397 if (handler->sa_handler != SIG_IGN)
398 rl_sigaction (sig, handler, &dummy);
399 }
400
401 int
402 rl_set_signals ()
403 {
404 sighandler_cxt dummy;
405 SigHandler *oh;
406 #if defined (HAVE_POSIX_SIGNALS)
407 static int sigmask_set = 0;
408 static sigset_t bset, oset;
409 #endif
410
411 #if defined (HAVE_POSIX_SIGNALS)
412 if (rl_catch_signals && sigmask_set == 0)
413 {
414 sigemptyset (&bset);
415
416 sigaddset (&bset, SIGINT);
417 sigaddset (&bset, SIGTERM);
418 sigaddset (&bset, SIGHUP);
419 #if defined (SIGQUIT)
420 sigaddset (&bset, SIGQUIT);
421 #endif
422 #if defined (SIGALRM)
423 sigaddset (&bset, SIGALRM);
424 #endif
425 #if defined (SIGTSTP)
426 sigaddset (&bset, SIGTSTP);
427 #endif
428 #if defined (SIGTTIN)
429 sigaddset (&bset, SIGTTIN);
430 #endif
431 #if defined (SIGTTOU)
432 sigaddset (&bset, SIGTTOU);
433 #endif
434 sigmask_set = 1;
435 }
436 #endif /* HAVE_POSIX_SIGNALS */
437
438 if (rl_catch_signals && signals_set_flag == 0)
439 {
440 #if defined (HAVE_POSIX_SIGNALS)
441 sigemptyset (&oset);
442 sigprocmask (SIG_BLOCK, &bset, &oset);
443 #endif
444
445 rl_maybe_set_sighandler (SIGINT, rl_signal_handler, &old_int);
446 rl_maybe_set_sighandler (SIGTERM, rl_signal_handler, &old_term);
447 rl_maybe_set_sighandler (SIGHUP, rl_signal_handler, &old_hup);
448 #if defined (SIGQUIT)
449 rl_maybe_set_sighandler (SIGQUIT, rl_signal_handler, &old_quit);
450 #endif
451
452 #if defined (SIGALRM)
453 oh = rl_set_sighandler (SIGALRM, rl_signal_handler, &old_alrm);
454 if (oh == (SigHandler *)SIG_IGN)
455 rl_sigaction (SIGALRM, &old_alrm, &dummy);
456 #if defined (HAVE_POSIX_SIGNALS) && defined (SA_RESTART)
457 /* If the application using readline has already installed a signal
458 handler with SA_RESTART, SIGALRM will cause reads to be restarted
459 automatically, so readline should just get out of the way. Since
460 we tested for SIG_IGN above, we can just test for SIG_DFL here. */
461 if (oh != (SigHandler *)SIG_DFL && (old_alrm.sa_flags & SA_RESTART))
462 rl_sigaction (SIGALRM, &old_alrm, &dummy);
463 #endif /* HAVE_POSIX_SIGNALS */
464 #endif /* SIGALRM */
465
466 #if defined (SIGTSTP)
467 rl_maybe_set_sighandler (SIGTSTP, rl_signal_handler, &old_tstp);
468 #endif /* SIGTSTP */
469
470 #if defined (SIGTTOU)
471 rl_maybe_set_sighandler (SIGTTOU, rl_signal_handler, &old_ttou);
472 #endif /* SIGTTOU */
473
474 #if defined (SIGTTIN)
475 rl_maybe_set_sighandler (SIGTTIN, rl_signal_handler, &old_ttin);
476 #endif /* SIGTTIN */
477
478 signals_set_flag = 1;
479
480 #if defined (HAVE_POSIX_SIGNALS)
481 sigprocmask (SIG_SETMASK, &oset, (sigset_t *)NULL);
482 #endif
483 }
484
485 #if defined (SIGWINCH)
486 if (rl_catch_sigwinch && sigwinch_set_flag == 0)
487 {
488 rl_maybe_set_sighandler (SIGWINCH, rl_sigwinch_handler, &old_winch);
489 sigwinch_set_flag = 1;
490 }
491 #endif /* SIGWINCH */
492
493 return 0;
494 }
495
496 int
497 rl_clear_signals ()
498 {
499 sighandler_cxt dummy;
500
501 if (rl_catch_signals && signals_set_flag == 1)
502 {
503 sigemptyset (&dummy.sa_mask);
504
505 /* Since rl_maybe_set_sighandler doesn't override a SIG_IGN handler,
506 we should in theory not have to restore a handler where
507 old_xxx.sa_handler == SIG_IGN. That's what rl_maybe_restore_sighandler
508 does. Fewer system calls should reduce readline's per-line
509 overhead */
510 rl_maybe_restore_sighandler (SIGINT, &old_int);
511 rl_maybe_restore_sighandler (SIGTERM, &old_term);
512 rl_maybe_restore_sighandler (SIGHUP, &old_hup);
513 #if defined (SIGQUIT)
514 rl_maybe_restore_sighandler (SIGQUIT, &old_quit);
515 #endif
516 #if defined (SIGALRM)
517 rl_maybe_restore_sighandler (SIGALRM, &old_alrm);
518 #endif
519
520 #if defined (SIGTSTP)
521 rl_maybe_restore_sighandler (SIGTSTP, &old_tstp);
522 #endif /* SIGTSTP */
523
524 #if defined (SIGTTOU)
525 rl_maybe_restore_sighandler (SIGTTOU, &old_ttou);
526 #endif /* SIGTTOU */
527
528 #if defined (SIGTTIN)
529 rl_maybe_restore_sighandler (SIGTTIN, &old_ttin);
530 #endif /* SIGTTIN */
531
532 signals_set_flag = 0;
533 }
534
535 #if defined (SIGWINCH)
536 if (rl_catch_sigwinch && sigwinch_set_flag == 1)
537 {
538 sigemptyset (&dummy.sa_mask);
539 rl_sigaction (SIGWINCH, &old_winch, &dummy);
540 sigwinch_set_flag = 0;
541 }
542 #endif
543
544 return 0;
545 }
546
547 /* Clean up the terminal and readline state after catching a signal, before
548 resending it to the calling application. */
549 void
550 rl_cleanup_after_signal ()
551 {
552 _rl_clean_up_for_exit ();
553 if (rl_deprep_term_function)
554 (*rl_deprep_term_function) ();
555 rl_clear_pending_input ();
556 rl_clear_signals ();
557 }
558
559 /* Reset the terminal and readline state after a signal handler returns. */
560 void
561 rl_reset_after_signal ()
562 {
563 if (rl_prep_term_function)
564 (*rl_prep_term_function) (_rl_meta_flag);
565 rl_set_signals ();
566 }
567
568 /* Free up the readline variable line state for the current line (undo list,
569 any partial history entry, any keyboard macros in progress, and any
570 numeric arguments in process) after catching a signal, before calling
571 rl_cleanup_after_signal(). */
572 void
573 rl_free_line_state ()
574 {
575 register HIST_ENTRY *entry;
576
577 rl_free_undo_list ();
578
579 entry = current_history ();
580 if (entry)
581 entry->data = (char *)NULL;
582
583 _rl_kill_kbd_macro ();
584 rl_clear_message ();
585 _rl_reset_argument ();
586 }
587
588 #endif /* HANDLE_SIGNALS */
589
590 /* **************************************************************** */
591 /* */
592 /* SIGINT Management */
593 /* */
594 /* **************************************************************** */
595
596 #if defined (HAVE_POSIX_SIGNALS)
597 static sigset_t sigint_set, sigint_oset;
598 static sigset_t sigwinch_set, sigwinch_oset;
599 #else /* !HAVE_POSIX_SIGNALS */
600 # if defined (HAVE_BSD_SIGNALS)
601 static int sigint_oldmask;
602 static int sigwinch_oldmask;
603 # endif /* HAVE_BSD_SIGNALS */
604 #endif /* !HAVE_POSIX_SIGNALS */
605
606 static int sigint_blocked;
607 static int sigwinch_blocked;
608
609 /* Cause SIGINT to not be delivered until the corresponding call to
610 release_sigint(). */
611 void
612 _rl_block_sigint ()
613 {
614 if (sigint_blocked)
615 return;
616
617 sigint_blocked = 1;
618 }
619
620 /* Allow SIGINT to be delivered. */
621 void
622 _rl_release_sigint ()
623 {
624 if (sigint_blocked == 0)
625 return;
626
627 sigint_blocked = 0;
628 RL_CHECK_SIGNALS ();
629 }
630
631 /* Cause SIGWINCH to not be delivered until the corresponding call to
632 release_sigwinch(). */
633 void
634 _rl_block_sigwinch ()
635 {
636 if (sigwinch_blocked)
637 return;
638
639 #if defined (SIGWINCH)
640
641 #if defined (HAVE_POSIX_SIGNALS)
642 sigemptyset (&sigwinch_set);
643 sigemptyset (&sigwinch_oset);
644 sigaddset (&sigwinch_set, SIGWINCH);
645 sigprocmask (SIG_BLOCK, &sigwinch_set, &sigwinch_oset);
646 #else /* !HAVE_POSIX_SIGNALS */
647 # if defined (HAVE_BSD_SIGNALS)
648 sigwinch_oldmask = sigblock (sigmask (SIGWINCH));
649 # else /* !HAVE_BSD_SIGNALS */
650 # if defined (HAVE_USG_SIGHOLD)
651 sighold (SIGWINCH);
652 # endif /* HAVE_USG_SIGHOLD */
653 # endif /* !HAVE_BSD_SIGNALS */
654 #endif /* !HAVE_POSIX_SIGNALS */
655
656 #endif /* SIGWINCH */
657
658 sigwinch_blocked = 1;
659 }
660
661 /* Allow SIGWINCH to be delivered. */
662 void
663 _rl_release_sigwinch ()
664 {
665 if (sigwinch_blocked == 0)
666 return;
667
668 #if defined (SIGWINCH)
669
670 #if defined (HAVE_POSIX_SIGNALS)
671 sigprocmask (SIG_SETMASK, &sigwinch_oset, (sigset_t *)NULL);
672 #else
673 # if defined (HAVE_BSD_SIGNALS)
674 sigsetmask (sigwinch_oldmask);
675 # else /* !HAVE_BSD_SIGNALS */
676 # if defined (HAVE_USG_SIGHOLD)
677 sigrelse (SIGWINCH);
678 # endif /* HAVE_USG_SIGHOLD */
679 # endif /* !HAVE_BSD_SIGNALS */
680 #endif /* !HAVE_POSIX_SIGNALS */
681
682 #endif /* SIGWINCH */
683
684 sigwinch_blocked = 0;
685 }
686
687 /* **************************************************************** */
688 /* */
689 /* Echoing special control characters */
690 /* */
691 /* **************************************************************** */
692 void
693 rl_echo_signal_char (sig)
694 int sig;
695 {
696 char cstr[3];
697 int cslen, c;
698
699 if (_rl_echoctl == 0 || _rl_echo_control_chars == 0)
700 return;
701
702 switch (sig)
703 {
704 case SIGINT: c = _rl_intr_char; break;
705 #if defined (SIGQUIT)
706 case SIGQUIT: c = _rl_quit_char; break;
707 #endif
708 #if defined (SIGTSTP)
709 case SIGTSTP: c = _rl_susp_char; break;
710 #endif
711 default: return;
712 }
713
714 if (CTRL_CHAR (c) || c == RUBOUT)
715 {
716 cstr[0] = '^';
717 cstr[1] = CTRL_CHAR (c) ? UNCTRL (c) : '?';
718 cstr[cslen = 2] = '\0';
719 }
720 else
721 {
722 cstr[0] = c;
723 cstr[cslen = 1] = '\0';
724 }
725
726 _rl_output_some_chars (cstr, cslen);
727 }
This page took 0.049071 seconds and 4 git commands to generate.