#include "config_readline.h"#include <stdio.h>#include <sys/types.h>#include <signal.h>#include "rldefs.h"#include "readline.h"#include "history.h"#include "rlprivate.h"Include dependency graph for signals.c:

Go to the source code of this file.
Classes | |
| struct | sighandler_cxt |
Defines | |
| #define | READLINE_LIBRARY |
| #define | RETSIGTYPE int |
| #define | SIGHANDLER_RETURN return (0) |
| #define | sigemptyset(m) |
| #define | SA_RESTART 0 |
Typedefs | |
| typedef RETSIGTYPE | SigHandler () |
Functions | |
| static SigHandler *rl_set_sighandler | PARAMS ((int, SigHandler *, sighandler_cxt *)) |
| static RETSIGTYPE | rl_signal_handler (int sig) |
| static int | rl_sigaction (int sig, sighandler_cxt *nh, sighandler_cxt *oh) |
| static SigHandler * | rl_set_sighandler (int sig, SigHandler *handler, sighandler_cxt *ohandler) |
| static void | rl_maybe_set_sighandler (int sig, SigHandler *handler, sighandler_cxt *ohandler) |
| int | rl_set_signals () |
| int | rl_clear_signals () |
| void | rl_cleanup_after_signal () |
| void | rl_reset_after_signal () |
| void | rl_free_line_state () |
Variables | |
| int | rl_catch_signals = 1 |
| int | rl_catch_sigwinch = 0 |
| static int | signals_set_flag |
| static int | sigwinch_set_flag |
| static sighandler_cxt | old_int |
| static sighandler_cxt | old_term |
| static sighandler_cxt | old_alrm |
| static sighandler_cxt | old_quit |
| typedef RETSIGTYPE SigHandler() |
| static SigHandler* rl_set_sighandler PARAMS | ( | (int, SigHandler *, sighandler_cxt *) | ) | [static] |
| void rl_cleanup_after_signal | ( | ) |
Definition at line 366 of file signals.c.
References _rl_clean_up_for_exit(), rl_clear_pending_input(), and rl_clear_signals().
00367 { 00368 _rl_clean_up_for_exit (); 00369 (*rl_deprep_term_function) (); 00370 rl_clear_signals (); 00371 rl_clear_pending_input (); 00372 }
Here is the call graph for this function:

| int rl_clear_signals | ( | ) |
Definition at line 323 of file signals.c.
References old_alrm, old_int, old_quit, old_term, rl_sigaction(), sighandler_cxt::sa_mask, sigemptyset, and SIGQUIT.
00324 { 00325 sighandler_cxt dummy; 00326 00327 if (rl_catch_signals && signals_set_flag == 1) 00328 { 00329 sigemptyset (&dummy.sa_mask); 00330 00331 rl_sigaction (SIGINT, &old_int, &dummy); 00332 rl_sigaction (SIGTERM, &old_term, &dummy); 00333 rl_sigaction (SIGQUIT, &old_quit, &dummy); 00334 rl_sigaction (SIGALRM, &old_alrm, &dummy); 00335 00336 #if defined (SIGTSTP) 00337 rl_sigaction (SIGTSTP, &old_tstp, &dummy); 00338 #endif /* SIGTSTP */ 00339 00340 #if defined (SIGTTOU) 00341 rl_sigaction (SIGTTOU, &old_ttou, &dummy); 00342 #endif /* SIGTTOU */ 00343 00344 #if defined (SIGTTIN) 00345 rl_sigaction (SIGTTIN, &old_ttin, &dummy); 00346 #endif /* SIGTTIN */ 00347 00348 signals_set_flag = 0; 00349 } 00350 00351 #if defined (SIGWINCH) 00352 if (rl_catch_sigwinch && sigwinch_set_flag == 1) 00353 { 00354 sigemptyset (&dummy.sa_mask); 00355 rl_sigaction (SIGWINCH, &old_winch, &dummy); 00356 sigwinch_set_flag = 0; 00357 } 00358 #endif 00359 00360 return 0; 00361 }
Here is the call graph for this function:

| void rl_free_line_state | ( | ) |
Definition at line 387 of file signals.c.
References _rl_init_argument(), _rl_kill_kbd_macro(), current_history(), NULL, rl_clear_message(), and rl_free_undo_list().
00388 { 00389 register HIST_ENTRY *entry; 00390 00391 rl_free_undo_list (); 00392 00393 entry = current_history (); 00394 if (entry) 00395 entry->data = (char *)NULL; 00396 00397 _rl_kill_kbd_macro (); 00398 rl_clear_message (); 00399 _rl_init_argument (); 00400 }
Here is the call graph for this function:

| static void rl_maybe_set_sighandler | ( | int | sig, | |
| SigHandler * | handler, | |||
| sighandler_cxt * | ohandler | |||
| ) | [static] |
Definition at line 258 of file signals.c.
References rl_set_sighandler(), rl_sigaction(), sighandler_cxt::sa_mask, and sigemptyset.
00262 { 00263 sighandler_cxt dummy; 00264 SigHandler *oh; 00265 00266 sigemptyset (&dummy.sa_mask); 00267 oh = rl_set_sighandler (sig, handler, ohandler); 00268 if (oh == (SigHandler *)SIG_IGN) 00269 rl_sigaction (sig, ohandler, &dummy); 00270 }
Here is the call graph for this function:

| void rl_reset_after_signal | ( | ) |
Definition at line 376 of file signals.c.
References _rl_meta_flag, and rl_set_signals().
00377 { 00378 (*rl_prep_term_function) (_rl_meta_flag); 00379 rl_set_signals (); 00380 }
Here is the call graph for this function:

| static SigHandler* rl_set_sighandler | ( | int | sig, | |
| SigHandler * | handler, | |||
| sighandler_cxt * | ohandler | |||
| ) | [static] |
Definition at line 230 of file signals.c.
References memcpy, rl_signal_handler(), sighandler_cxt::sa_handler, sighandler_cxt::sa_mask, SA_RESTART, and sigemptyset.
00234 { 00235 sighandler_cxt old_handler; 00236 #if defined (HAVE_POSIX_SIGNALS) 00237 struct sigaction act; 00238 00239 act.sa_handler = handler; 00240 act.sa_flags = (sig == SIGWINCH) ? SA_RESTART : 0; 00241 sigemptyset (&act.sa_mask); 00242 sigemptyset (&ohandler->sa_mask); 00243 sigaction (sig, &act, &old_handler); 00244 #else 00245 old_handler.sa_handler = (SigHandler *)signal (sig, handler); 00246 #endif /* !HAVE_POSIX_SIGNALS */ 00247 00248 /* XXX -- assume we have memcpy */ 00249 /* If rl_set_signals is called twice in a row, don't set the old handler to 00250 rl_signal_handler, because that would cause infinite recursion. */ 00251 if (handler != rl_signal_handler || old_handler.sa_handler != rl_signal_handler) 00252 memcpy (ohandler, &old_handler, sizeof (sighandler_cxt)); 00253 00254 return (ohandler->sa_handler); 00255 }
Here is the call graph for this function:

| int rl_set_signals | ( | ) |
Definition at line 273 of file signals.c.
References old_alrm, old_int, old_quit, old_term, rl_maybe_set_sighandler(), rl_set_sighandler(), rl_sigaction(), rl_signal_handler(), sighandler_cxt::sa_flags, SA_RESTART, and SIGQUIT.
00274 { 00275 sighandler_cxt dummy; 00276 SigHandler *oh; 00277 00278 if (rl_catch_signals && signals_set_flag == 0) 00279 { 00280 rl_maybe_set_sighandler (SIGINT, rl_signal_handler, &old_int); 00281 rl_maybe_set_sighandler (SIGTERM, rl_signal_handler, &old_term); 00282 rl_maybe_set_sighandler (SIGQUIT, rl_signal_handler, &old_quit); 00283 00284 oh = rl_set_sighandler (SIGALRM, rl_signal_handler, &old_alrm); 00285 if (oh == (SigHandler *)SIG_IGN) 00286 rl_sigaction (SIGALRM, &old_alrm, &dummy); 00287 #if defined (HAVE_POSIX_SIGNALS) && defined (SA_RESTART) 00288 /* If the application using readline has already installed a signal 00289 handler with SA_RESTART, SIGALRM will cause reads to be restarted 00290 automatically, so readline should just get out of the way. Since 00291 we tested for SIG_IGN above, we can just test for SIG_DFL here. */ 00292 if (oh != (SigHandler *)SIG_DFL && (old_alrm.sa_flags & SA_RESTART)) 00293 rl_sigaction (SIGALRM, &old_alrm, &dummy); 00294 #endif /* HAVE_POSIX_SIGNALS */ 00295 00296 #if defined (SIGTSTP) 00297 rl_maybe_set_sighandler (SIGTSTP, rl_signal_handler, &old_tstp); 00298 #endif /* SIGTSTP */ 00299 00300 #if defined (SIGTTOU) 00301 rl_maybe_set_sighandler (SIGTTOU, rl_signal_handler, &old_ttou); 00302 #endif /* SIGTTOU */ 00303 00304 #if defined (SIGTTIN) 00305 rl_maybe_set_sighandler (SIGTTIN, rl_signal_handler, &old_ttin); 00306 #endif /* SIGTTIN */ 00307 00308 signals_set_flag = 1; 00309 } 00310 00311 #if defined (SIGWINCH) 00312 if (rl_catch_sigwinch && sigwinch_set_flag == 0) 00313 { 00314 rl_maybe_set_sighandler (SIGWINCH, rl_sigwinch_handler, &old_winch); 00315 sigwinch_set_flag = 1; 00316 } 00317 #endif /* SIGWINCH */ 00318 00319 return 0; 00320 }
Here is the call graph for this function:

| static int rl_sigaction | ( | int | sig, | |
| sighandler_cxt * | nh, | |||
| sighandler_cxt * | oh | |||
| ) | [static] |
Definition at line 217 of file signals.c.
References sighandler_cxt::sa_handler.
00220 { 00221 oh->sa_handler = signal (sig, nh->sa_handler); 00222 return 0; 00223 }
| static RETSIGTYPE rl_signal_handler | ( | int | sig | ) | [static] |
Definition at line 114 of file signals.c.
References NULL, rl_cleanup_after_signal(), rl_free_line_state(), rl_reset_after_signal(), rl_set_sighandler(), RL_SETSTATE, RL_STATE_SIGHANDLER, RL_UNSETSTATE, SIGHANDLER_RETURN, and SIGQUIT.
00116 { 00117 #if defined (HAVE_POSIX_SIGNALS) 00118 sigset_t set; 00119 #else /* !HAVE_POSIX_SIGNALS */ 00120 # if defined (HAVE_BSD_SIGNALS) 00121 long omask; 00122 # else /* !HAVE_BSD_SIGNALS */ 00123 sighandler_cxt dummy_cxt; /* needed for rl_set_sighandler call */ 00124 # endif /* !HAVE_BSD_SIGNALS */ 00125 #endif /* !HAVE_POSIX_SIGNALS */ 00126 00127 RL_SETSTATE(RL_STATE_SIGHANDLER); 00128 00129 #if !defined (HAVE_BSD_SIGNALS) && !defined (HAVE_POSIX_SIGNALS) 00130 /* Since the signal will not be blocked while we are in the signal 00131 handler, ignore it until rl_clear_signals resets the catcher. */ 00132 if (sig == SIGINT || sig == SIGALRM) 00133 rl_set_sighandler (sig, SIG_IGN, &dummy_cxt); 00134 #endif /* !HAVE_BSD_SIGNALS && !HAVE_POSIX_SIGNALS */ 00135 00136 switch (sig) 00137 { 00138 case SIGINT: 00139 rl_free_line_state (); 00140 /* FALLTHROUGH */ 00141 00142 #if defined (SIGTSTP) 00143 case SIGTSTP: 00144 case SIGTTOU: 00145 case SIGTTIN: 00146 #endif /* SIGTSTP */ 00147 case SIGALRM: 00148 case SIGTERM: 00149 case SIGQUIT: 00150 rl_cleanup_after_signal (); 00151 00152 #if defined (HAVE_POSIX_SIGNALS) 00153 sigprocmask (SIG_BLOCK, (sigset_t *)NULL, &set); 00154 sigdelset (&set, sig); 00155 #else /* !HAVE_POSIX_SIGNALS */ 00156 # if defined (HAVE_BSD_SIGNALS) 00157 omask = sigblock (0); 00158 # endif /* HAVE_BSD_SIGNALS */ 00159 #endif /* !HAVE_POSIX_SIGNALS */ 00160 00161 #if defined (__EMX__) 00162 signal (sig, SIG_ACK); 00163 #endif 00164 00165 kill (getpid (), sig); 00166 00167 /* Let the signal that we just sent through. */ 00168 #if defined (HAVE_POSIX_SIGNALS) 00169 sigprocmask (SIG_SETMASK, &set, (sigset_t *)NULL); 00170 #else /* !HAVE_POSIX_SIGNALS */ 00171 # if defined (HAVE_BSD_SIGNALS) 00172 sigsetmask (omask & ~(sigmask (sig))); 00173 # endif /* HAVE_BSD_SIGNALS */ 00174 #endif /* !HAVE_POSIX_SIGNALS */ 00175 00176 rl_reset_after_signal (); 00177 } 00178 00179 RL_UNSETSTATE(RL_STATE_SIGHANDLER); 00180 SIGHANDLER_RETURN; 00181 }
Here is the call graph for this function:

sighandler_cxt old_alrm [static] |
sighandler_cxt old_int [static] |
sighandler_cxt old_quit [static] |
sighandler_cxt old_term [static] |
| int rl_catch_signals = 1 |
| int rl_catch_sigwinch = 0 |
int signals_set_flag [static] |
int sigwinch_set_flag [static] |
1.4.7

