restyle signal module to match project style

Reduces lint errors from 15 to 15 (-0%). Line count from 754 to 438 (-42%).

Another step in resolving issue #2902.
This commit is contained in:
Kurtis Rader 2016-05-03 13:02:26 -07:00
parent fa53563733
commit 0aa7fd95b8
2 changed files with 151 additions and 467 deletions

View file

@ -1,10 +1,7 @@
/** \file signal.c // The library for various signal related issues.
The library for various signal related issues
*/
#include <stdio.h>
#include <signal.h>
#include <errno.h> #include <errno.h>
#include <signal.h>
#include <stdio.h>
#ifdef HAVE_SIGINFO_H #ifdef HAVE_SIGINFO_H
#include <siginfo.h> #include <siginfo.h>
#endif #endif
@ -12,383 +9,167 @@ The library for various signal related issues
#include <stdbool.h> #include <stdbool.h>
#include "common.h" #include "common.h"
#include "fallback.h" // IWYU pragma: keep
#include "wutil.h" // IWYU pragma: keep
#include "signal.h"
#include "event.h" #include "event.h"
#include "reader.h" #include "fallback.h" // IWYU pragma: keep
#include "proc.h" #include "proc.h"
#include "reader.h"
#include "signal.h"
#include "wutil.h" // IWYU pragma: keep
/** /// Struct describing an entry for the lookup table used to convert between signal names and signal
Struct describing an entry for the lookup table used to convert /// ids, etc.
between signal names and signal ids, etc. struct lookup_entry {
*/ /// Signal id.
struct lookup_entry
{
/**
Signal id
*/
int signal; int signal;
/** /// Signal name.
Signal name
*/
const wchar_t *name; const wchar_t *name;
/** /// Signal description.
Signal description
*/
const wchar_t *desc; const wchar_t *desc;
}; };
/** /// The number of signal blocks in place. Increased by signal_block, decreased by signal_unblock.
The number of signal blocks in place. Increased by signal_block, decreased by signal_unblock. static int block_count = 0;
*/
static int block_count=0;
/// Lookup table used to convert between signal names and signal ids, etc.
/** static const struct lookup_entry lookup[] = {
Lookup table used to convert between signal names and signal ids,
etc.
*/
static const struct lookup_entry lookup[] =
{
#ifdef SIGHUP #ifdef SIGHUP
{ {SIGHUP, L"SIGHUP", N_(L"Terminal hung up")},
SIGHUP,
L"SIGHUP",
N_(L"Terminal hung up")
}
,
#endif #endif
#ifdef SIGINT #ifdef SIGINT
{ {SIGINT, L"SIGINT", N_(L"Quit request from job control (^C)")},
SIGINT,
L"SIGINT",
N_(L"Quit request from job control (^C)")
}
,
#endif #endif
#ifdef SIGQUIT #ifdef SIGQUIT
{ {SIGQUIT, L"SIGQUIT", N_(L"Quit request from job control with core dump (^\\)")},
SIGQUIT,
L"SIGQUIT",
N_(L"Quit request from job control with core dump (^\\)")
}
,
#endif #endif
#ifdef SIGILL #ifdef SIGILL
{ {SIGILL, L"SIGILL", N_(L"Illegal instruction")},
SIGILL,
L"SIGILL",
N_(L"Illegal instruction")
}
,
#endif #endif
#ifdef SIGTRAP #ifdef SIGTRAP
{ {SIGTRAP, L"SIGTRAP", N_(L"Trace or breakpoint trap")},
SIGTRAP,
L"SIGTRAP",
N_(L"Trace or breakpoint trap")
}
,
#endif #endif
#ifdef SIGABRT #ifdef SIGABRT
{ {SIGABRT, L"SIGABRT", N_(L"Abort")},
SIGABRT,
L"SIGABRT",
N_(L"Abort")
}
,
#endif #endif
#ifdef SIGBUS #ifdef SIGBUS
{ {SIGBUS, L"SIGBUS", N_(L"Misaligned address error")},
SIGBUS,
L"SIGBUS",
N_(L"Misaligned address error")
}
,
#endif #endif
#ifdef SIGFPE #ifdef SIGFPE
{ {SIGFPE, L"SIGFPE", N_(L"Floating point exception")},
SIGFPE,
L"SIGFPE",
N_(L"Floating point exception")
}
,
#endif #endif
#ifdef SIGKILL #ifdef SIGKILL
{ {SIGKILL, L"SIGKILL", N_(L"Forced quit")},
SIGKILL,
L"SIGKILL",
N_(L"Forced quit")
}
,
#endif #endif
#ifdef SIGUSR1 #ifdef SIGUSR1
{ {SIGUSR1, L"SIGUSR1", N_(L"User defined signal 1")},
SIGUSR1,
L"SIGUSR1",
N_(L"User defined signal 1")
}
,
#endif #endif
#ifdef SIGUSR2 #ifdef SIGUSR2
{ {SIGUSR2, L"SIGUSR2", N_(L"User defined signal 2")},
SIGUSR2, L"SIGUSR2",
N_(L"User defined signal 2")
}
,
#endif #endif
#ifdef SIGSEGV #ifdef SIGSEGV
{ {SIGSEGV, L"SIGSEGV", N_(L"Address boundary error")},
SIGSEGV,
L"SIGSEGV",
N_(L"Address boundary error")
}
,
#endif #endif
#ifdef SIGPIPE #ifdef SIGPIPE
{ {SIGPIPE, L"SIGPIPE", N_(L"Broken pipe")},
SIGPIPE,
L"SIGPIPE",
N_(L"Broken pipe")
}
,
#endif #endif
#ifdef SIGALRM #ifdef SIGALRM
{ {SIGALRM, L"SIGALRM", N_(L"Timer expired")},
SIGALRM,
L"SIGALRM",
N_(L"Timer expired")
}
,
#endif #endif
#ifdef SIGTERM #ifdef SIGTERM
{ {SIGTERM, L"SIGTERM", N_(L"Polite quit request")},
SIGTERM,
L"SIGTERM",
N_(L"Polite quit request")
}
,
#endif #endif
#ifdef SIGCHLD #ifdef SIGCHLD
{ {SIGCHLD, L"SIGCHLD", N_(L"Child process status changed")},
SIGCHLD,
L"SIGCHLD",
N_(L"Child process status changed")
}
,
#endif #endif
#ifdef SIGCONT #ifdef SIGCONT
{ {SIGCONT, L"SIGCONT", N_(L"Continue previously stopped process")},
SIGCONT,
L"SIGCONT",
N_(L"Continue previously stopped process")
}
,
#endif #endif
#ifdef SIGSTOP #ifdef SIGSTOP
{ {SIGSTOP, L"SIGSTOP", N_(L"Forced stop")},
SIGSTOP,
L"SIGSTOP",
N_(L"Forced stop")
}
,
#endif #endif
#ifdef SIGTSTP #ifdef SIGTSTP
{ {SIGTSTP, L"SIGTSTP", N_(L"Stop request from job control (^Z)")},
SIGTSTP,
L"SIGTSTP",
N_(L"Stop request from job control (^Z)")
}
,
#endif #endif
#ifdef SIGTTIN #ifdef SIGTTIN
{ {SIGTTIN, L"SIGTTIN", N_(L"Stop from terminal input")},
SIGTTIN,
L"SIGTTIN",
N_(L"Stop from terminal input")
}
,
#endif #endif
#ifdef SIGTTOU #ifdef SIGTTOU
{ {SIGTTOU, L"SIGTTOU", N_(L"Stop from terminal output")},
SIGTTOU,
L"SIGTTOU",
N_(L"Stop from terminal output")
}
,
#endif #endif
#ifdef SIGURG #ifdef SIGURG
{ {SIGURG, L"SIGURG", N_(L"Urgent socket condition")},
SIGURG,
L"SIGURG",
N_(L"Urgent socket condition")
}
,
#endif #endif
#ifdef SIGXCPU #ifdef SIGXCPU
{ {SIGXCPU, L"SIGXCPU", N_(L"CPU time limit exceeded")},
SIGXCPU,
L"SIGXCPU",
N_(L"CPU time limit exceeded")
}
,
#endif #endif
#ifdef SIGXFSZ #ifdef SIGXFSZ
{ {SIGXFSZ, L"SIGXFSZ", N_(L"File size limit exceeded")},
SIGXFSZ,
L"SIGXFSZ",
N_(L"File size limit exceeded")
}
,
#endif #endif
#ifdef SIGVTALRM #ifdef SIGVTALRM
{ {SIGVTALRM, L"SIGVTALRM", N_(L"Virtual timer expired")},
SIGVTALRM,
L"SIGVTALRM",
N_(L"Virtual timer expired")
}
,
#endif #endif
#ifdef SIGPROF #ifdef SIGPROF
{ {SIGPROF, L"SIGPROF", N_(L"Profiling timer expired")},
SIGPROF,
L"SIGPROF",
N_(L"Profiling timer expired")
}
,
#endif #endif
#ifdef SIGWINCH #ifdef SIGWINCH
{ {SIGWINCH, L"SIGWINCH", N_(L"Window size change")},
SIGWINCH,
L"SIGWINCH",
N_(L"Window size change")
}
,
#endif #endif
#ifdef SIGWIND #ifdef SIGWIND
{ {SIGWIND, L"SIGWIND", N_(L"Window size change")},
SIGWIND,
L"SIGWIND",
N_(L"Window size change")
}
,
#endif #endif
#ifdef SIGIO #ifdef SIGIO
{ {SIGIO, L"SIGIO", N_(L"I/O on asynchronous file descriptor is possible")},
SIGIO,
L"SIGIO",
N_(L"I/O on asynchronous file descriptor is possible")
}
,
#endif #endif
#ifdef SIGPWR #ifdef SIGPWR
{ {SIGPWR, L"SIGPWR", N_(L"Power failure")},
SIGPWR,
L"SIGPWR",
N_(L"Power failure")
}
,
#endif #endif
#ifdef SIGSYS #ifdef SIGSYS
{ {SIGSYS, L"SIGSYS", N_(L"Bad system call")},
SIGSYS,
L"SIGSYS",
N_(L"Bad system call")
}
,
#endif #endif
#ifdef SIGINFO #ifdef SIGINFO
{ {SIGINFO, L"SIGINFO", N_(L"Information request")},
SIGINFO,
L"SIGINFO",
N_(L"Information request")
}
,
#endif #endif
#ifdef SIGSTKFLT #ifdef SIGSTKFLT
{ {SIGSTKFLT, L"SISTKFLT", N_(L"Stack fault")},
SIGSTKFLT,
L"SISTKFLT",
N_(L"Stack fault")
}
,
#endif #endif
#ifdef SIGEMT #ifdef SIGEMT
{ {SIGEMT, L"SIGEMT", N_(L"Emulator trap")},
SIGEMT,
L"SIGEMT",
N_(L"Emulator trap")
}
,
#endif #endif
#ifdef SIGIOT #ifdef SIGIOT
{ {SIGIOT, L"SIGIOT", N_(L"Abort (Alias for SIGABRT)")},
SIGIOT,
L"SIGIOT",
N_(L"Abort (Alias for SIGABRT)")
}
,
#endif #endif
#ifdef SIGUNUSED #ifdef SIGUNUSED
{ {SIGUNUSED, L"SIGUNUSED", N_(L"Unused signal")},
SIGUNUSED,
L"SIGUNUSED",
N_(L"Unused signal")
}
,
#endif #endif
{ {0, 0, 0}};
0,
0,
0
}
}
;
/// Test if \c name is a string describing the signal named \c canonical.
static int match_signal_name(const wchar_t *canonical, const wchar_t *name) {
if (wcsncasecmp(name, L"sig", 3) == 0) name += 3;
/** return wcscasecmp(canonical + 3, name) == 0;
Test if \c name is a string describing the signal named \c canonical.
*/
static int match_signal_name(const wchar_t *canonical,
const wchar_t *name)
{
if (wcsncasecmp(name, L"sig", 3)==0)
name +=3;
return wcscasecmp(canonical+3,name) == 0;
} }
int wcs2sig(const wchar_t *str) {
int wcs2sig(const wchar_t *str)
{
int i; int i;
wchar_t *end=0; wchar_t *end = 0;
for (i=0; lookup[i].desc ; i++) for (i = 0; lookup[i].desc; i++) {
{ if (match_signal_name(lookup[i].name, str)) {
if (match_signal_name(lookup[i].name, str))
{
return lookup[i].signal; return lookup[i].signal;
} }
} }
errno=0; errno = 0;
int res = fish_wcstoi(str, &end, 10); int res = fish_wcstoi(str, &end, 10);
if (!errno && res>=0 && !*end) if (!errno && res >= 0 && !*end) return res;
return res;
return -1; return -1;
} }
const wchar_t *sig2wcs(int sig) {
const wchar_t *sig2wcs(int sig)
{
int i; int i;
for (i=0; lookup[i].desc ; i++) for (i = 0; lookup[i].desc; i++) {
{ if (lookup[i].signal == sig) {
if (lookup[i].signal == sig)
{
return lookup[i].name; return lookup[i].name;
} }
} }
@ -396,14 +177,11 @@ const wchar_t *sig2wcs(int sig)
return _(L"Unknown"); return _(L"Unknown");
} }
const wchar_t *signal_get_desc(int sig) const wchar_t *signal_get_desc(int sig) {
{
int i; int i;
for (i=0; lookup[i].desc ; i++) for (i = 0; lookup[i].desc; i++) {
{ if (lookup[i].signal == sig) {
if (lookup[i].signal == sig)
{
return _(lookup[i].desc); return _(lookup[i].desc);
} }
} }
@ -411,103 +189,74 @@ const wchar_t *signal_get_desc(int sig)
return _(L"Unknown"); return _(L"Unknown");
} }
/** /// Standard signal handler.
Standard signal handler static void default_handler(int signal, siginfo_t *info, void *context) {
*/ if (event_is_signal_observed(signal)) {
static void default_handler(int signal, siginfo_t *info, void *context)
{
if (event_is_signal_observed(signal))
{
event_fire_signal(signal); event_fire_signal(signal);
} }
} }
/** /// Respond to a winch signal by checking the terminal size.
Respond to a winch signal by checking the terminal size static void handle_winch(int sig, siginfo_t *info, void *context) {
*/
static void handle_winch(int sig, siginfo_t *info, void *context)
{
common_handle_winch(sig); common_handle_winch(sig);
default_handler(sig, 0, 0); default_handler(sig, 0, 0);
} }
/** /// Respond to a hup signal by exiting, unless it is caught by a shellscript function, in which case
Respond to a hup signal by exiting, unless it is caught by a /// we do nothing.
shellscript function, in which case we do nothing. static void handle_hup(int sig, siginfo_t *info, void *context) {
*/ if (event_is_signal_observed(SIGHUP)) {
static void handle_hup(int sig, siginfo_t *info, void *context)
{
if (event_is_signal_observed(SIGHUP))
{
default_handler(sig, 0, 0); default_handler(sig, 0, 0);
} } else {
else
{
reader_exit(1, 1); reader_exit(1, 1);
} }
} }
/** Handle sigterm. The only thing we do is restore the front process ID, then die. */ /// Handle sigterm. The only thing we do is restore the front process ID, then die.
static void handle_term(int sig, siginfo_t *info, void *context) static void handle_term(int sig, siginfo_t *info, void *context) {
{
restore_term_foreground_process_group(); restore_term_foreground_process_group();
signal(SIGTERM, SIG_DFL); signal(SIGTERM, SIG_DFL);
raise(SIGTERM); raise(SIGTERM);
} }
/** /// Interactive mode ^C handler. Respond to int signal by setting interrupted-flag and stopping all
Interactive mode ^C handler. Respond to int signal by setting /// loops and conditionals.
interrupted-flag and stopping all loops and conditionals. static void handle_int(int sig, siginfo_t *info, void *context) {
*/
static void handle_int(int sig, siginfo_t *info, void *context)
{
reader_handle_int(sig); reader_handle_int(sig);
default_handler(sig, info, context); default_handler(sig, info, context);
} }
/** /// sigchld handler. Does notification and calls the handler in proc.c.
sigchld handler. Does notification and calls the handler in proc.c static void handle_chld(int sig, siginfo_t *info, void *context) {
*/
static void handle_chld(int sig, siginfo_t *info, void *context)
{
job_handle_signal(sig, info, context); job_handle_signal(sig, info, context);
default_handler(sig, info, context); default_handler(sig, info, context);
} }
void signal_reset_handlers() void signal_reset_handlers() {
{
int i; int i;
struct sigaction act; struct sigaction act;
sigemptyset(& act.sa_mask); sigemptyset(&act.sa_mask);
act.sa_flags=0; act.sa_flags = 0;
act.sa_handler=SIG_DFL; act.sa_handler = SIG_DFL;
for (i=0; lookup[i].desc ; i++) for (i = 0; lookup[i].desc; i++) {
{
sigaction(lookup[i].signal, &act, 0); sigaction(lookup[i].signal, &act, 0);
} }
} }
/// Sets appropriate signal handlers.
/** void signal_set_handlers() {
Sets appropriate signal handlers.
*/
void signal_set_handlers()
{
struct sigaction act; struct sigaction act;
if (get_is_interactive() == -1) if (get_is_interactive() == -1) return;
return;
sigemptyset(& act.sa_mask); sigemptyset(&act.sa_mask);
act.sa_flags=SA_SIGINFO; act.sa_flags = SA_SIGINFO;
act.sa_sigaction = &default_handler; act.sa_sigaction = &default_handler;
/* // First reset everything to a use default_handler, a function whose sole action is to fire of
First reset everything to a use default_handler, a function // an event.
whose sole action is to fire of an event
*/
sigaction(SIGINT, &act, 0); sigaction(SIGINT, &act, 0);
sigaction(SIGQUIT, &act, 0); sigaction(SIGQUIT, &act, 0);
sigaction(SIGTSTP, &act, 0); sigaction(SIGTSTP, &act, 0);
@ -515,19 +264,13 @@ void signal_set_handlers()
sigaction(SIGTTOU, &act, 0); sigaction(SIGTTOU, &act, 0);
sigaction(SIGCHLD, &act, 0); sigaction(SIGCHLD, &act, 0);
/* // Ignore sigpipe, which we may get from the universal variable notifier.
Ignore sigpipe, which we may get from the universal variable notifier.
*/
sigaction(SIGPIPE, &act, 0); sigaction(SIGPIPE, &act, 0);
if (get_is_interactive()) if (get_is_interactive()) {
{ // Interactive mode. Ignore interactive signals. We are a shell, we know whats best for the
/* // user.
Interactive mode. Ignore interactive signals. We are a act.sa_handler = SIG_IGN;
shell, we know whats best for the user. ;-)
*/
act.sa_handler=SIG_IGN;
sigaction(SIGINT, &act, 0); sigaction(SIGINT, &act, 0);
sigaction(SIGQUIT, &act, 0); sigaction(SIGQUIT, &act, 0);
@ -537,95 +280,71 @@ void signal_set_handlers()
act.sa_sigaction = &handle_int; act.sa_sigaction = &handle_int;
act.sa_flags = SA_SIGINFO; act.sa_flags = SA_SIGINFO;
if (sigaction(SIGINT, &act, 0)) if (sigaction(SIGINT, &act, 0)) {
{
wperror(L"sigaction"); wperror(L"sigaction");
FATAL_EXIT(); FATAL_EXIT();
} }
act.sa_sigaction = &handle_chld; act.sa_sigaction = &handle_chld;
act.sa_flags = SA_SIGINFO; act.sa_flags = SA_SIGINFO;
if (sigaction(SIGCHLD, &act, 0)) if (sigaction(SIGCHLD, &act, 0)) {
{
wperror(L"sigaction"); wperror(L"sigaction");
FATAL_EXIT(); FATAL_EXIT();
} }
#ifdef SIGWINCH #ifdef SIGWINCH
act.sa_flags = SA_SIGINFO; act.sa_flags = SA_SIGINFO;
act.sa_sigaction= &handle_winch; act.sa_sigaction = &handle_winch;
if (sigaction(SIGWINCH, &act, 0)) if (sigaction(SIGWINCH, &act, 0)) {
{
wperror(L"sigaction"); wperror(L"sigaction");
FATAL_EXIT(); FATAL_EXIT();
} }
#endif #endif
act.sa_flags = SA_SIGINFO; act.sa_flags = SA_SIGINFO;
act.sa_sigaction= &handle_hup; act.sa_sigaction = &handle_hup;
if (sigaction(SIGHUP, &act, 0)) if (sigaction(SIGHUP, &act, 0)) {
{
wperror(L"sigaction"); wperror(L"sigaction");
FATAL_EXIT(); FATAL_EXIT();
} }
// SIGTERM restores the terminal controlling process before dying // SIGTERM restores the terminal controlling process before dying.
act.sa_flags = SA_SIGINFO; act.sa_flags = SA_SIGINFO;
act.sa_sigaction= &handle_term; act.sa_sigaction = &handle_term;
if (sigaction(SIGTERM, &act, 0)) if (sigaction(SIGTERM, &act, 0)) {
{
wperror(L"sigaction"); wperror(L"sigaction");
FATAL_EXIT(); FATAL_EXIT();
} }
} else {
} // Non-interactive. Ignore interrupt, check exit status of processes to determine result
else // instead.
{ act.sa_handler = SIG_IGN;
/*
Non-interactive. Ignore interrupt, check exit status of
processes to determine result instead.
*/
act.sa_handler=SIG_IGN;
sigaction(SIGINT, &act, 0); sigaction(SIGINT, &act, 0);
sigaction(SIGQUIT, &act, 0); sigaction(SIGQUIT, &act, 0);
act.sa_handler=SIG_DFL; act.sa_handler = SIG_DFL;
act.sa_sigaction = &handle_chld; act.sa_sigaction = &handle_chld;
act.sa_flags = SA_SIGINFO; act.sa_flags = SA_SIGINFO;
if (sigaction(SIGCHLD, &act, 0)) if (sigaction(SIGCHLD, &act, 0)) {
{
wperror(L"sigaction"); wperror(L"sigaction");
exit_without_destructors(1); exit_without_destructors(1);
} }
} }
} }
void signal_handle(int sig, int do_handle) void signal_handle(int sig, int do_handle) {
{
struct sigaction act; struct sigaction act;
/* // These should always be handled.
These should always be handled if ((sig == SIGINT) || (sig == SIGQUIT) || (sig == SIGTSTP) || (sig == SIGTTIN) ||
*/ (sig == SIGTTOU) || (sig == SIGCHLD))
if ((sig == SIGINT) ||
(sig == SIGQUIT) ||
(sig == SIGTSTP) ||
(sig == SIGTTIN) ||
(sig == SIGTTOU) ||
(sig == SIGCHLD))
return; return;
sigemptyset(&act.sa_mask); sigemptyset(&act.sa_mask);
if (do_handle) if (do_handle) {
{
act.sa_flags = SA_SIGINFO; act.sa_flags = SA_SIGINFO;
act.sa_sigaction = &default_handler; act.sa_sigaction = &default_handler;
} } else {
else
{
act.sa_flags = 0; act.sa_flags = 0;
act.sa_handler = SIG_DFL; act.sa_handler = SIG_DFL;
} }
@ -633,57 +352,45 @@ void signal_handle(int sig, int do_handle)
sigaction(sig, &act, 0); sigaction(sig, &act, 0);
} }
void get_signals_with_handlers(sigset_t *set) void get_signals_with_handlers(sigset_t *set) {
{
sigemptyset(set); sigemptyset(set);
for (int i=0; lookup[i].desc ; i++) for (int i = 0; lookup[i].desc; i++) {
{
struct sigaction act = {}; struct sigaction act = {};
sigaction(lookup[i].signal, NULL, &act); sigaction(lookup[i].signal, NULL, &act);
if (act.sa_handler != SIG_DFL) if (act.sa_handler != SIG_DFL) sigaddset(set, lookup[i].signal);
sigaddset(set, lookup[i].signal);
} }
} }
void signal_block() void signal_block() {
{
ASSERT_IS_MAIN_THREAD(); ASSERT_IS_MAIN_THREAD();
sigset_t chldset; sigset_t chldset;
if (!block_count) if (!block_count) {
{
sigfillset(&chldset); sigfillset(&chldset);
VOMIT_ON_FAILURE(pthread_sigmask(SIG_BLOCK, &chldset, NULL)); VOMIT_ON_FAILURE(pthread_sigmask(SIG_BLOCK, &chldset, NULL));
} }
block_count++; block_count++;
// debug( 0, L"signal block level increased to %d", block_count ); // debug( 0, L"signal block level increased to %d", block_count );
} }
void signal_unblock() void signal_unblock() {
{
ASSERT_IS_MAIN_THREAD(); ASSERT_IS_MAIN_THREAD();
sigset_t chldset; sigset_t chldset;
block_count--; block_count--;
if (block_count < 0) if (block_count < 0) {
{
debug(0, _(L"Signal block mismatch")); debug(0, _(L"Signal block mismatch"));
bugreport(); bugreport();
FATAL_EXIT(); FATAL_EXIT();
} }
if (!block_count) if (!block_count) {
{
sigfillset(&chldset); sigfillset(&chldset);
VOMIT_ON_FAILURE(pthread_sigmask(SIG_UNBLOCK, &chldset, 0)); VOMIT_ON_FAILURE(pthread_sigmask(SIG_UNBLOCK, &chldset, 0));
} }
// debug( 0, L"signal block level decreased to %d", block_count ); // debug( 0, L"signal block level decreased to %d", block_count );
}
bool signal_is_blocked()
{
return !!block_count;
} }
bool signal_is_blocked() { return !!block_count; }

View file

@ -1,65 +1,42 @@
/** \file signal.h // The library for various signal related issues.
The library for various signal related issues
*/
#ifndef FISH_SIGNALH #ifndef FISH_SIGNALH
#define FISH_SIGNALH #define FISH_SIGNALH
#include <signal.h> #include <signal.h>
#include <stdbool.h> #include <stdbool.h>
/** /// Get the integer signal value representing the specified signal, or -1 of no signal was found.
Get the integer signal value representing the specified signal, or
-1 of no signal was found
*/
int wcs2sig(const wchar_t *str); int wcs2sig(const wchar_t *str);
/** /// Get string representation of a signal.
Get string representation of a signal
*/
const wchar_t *sig2wcs(int sig); const wchar_t *sig2wcs(int sig);
/** /// Returns a description of the specified signal.
Returns a description of the specified signal.
*/
const wchar_t *signal_get_desc(int sig); const wchar_t *signal_get_desc(int sig);
/** /// Set all signal handlers to SIG_DFL.
Set all signal handlers to SIG_DFL
*/
void signal_reset_handlers(); void signal_reset_handlers();
/** /// Set signal handlers to fish default handlers.
Set signal handlers to fish default handlers
*/
void signal_set_handlers(); void signal_set_handlers();
/** /// Tell fish what to do on the specified signal.
Tell fish what to do on the specified signal. ///
/// \param sig The signal to specify the action of
\param sig The signal to specify the action of /// \param do_handle If true fish will catch the specified signal and fire an event, otherwise the
\param do_handle If true fish will catch the specified signal and fire an event, otherwise the default action (SIG_DFL) will be set /// default action (SIG_DFL) will be set
*/
void signal_handle(int sig, int do_handle); void signal_handle(int sig, int do_handle);
/** /// Block all signals.
Block all signals
*/
void signal_block(); void signal_block();
/** /// Unblock all signals.
Unblock all signals
*/
void signal_unblock(); void signal_unblock();
/** /// Returns true if signals are being blocked.
Returns true if signals are being blocked
*/
bool signal_is_blocked(); bool signal_is_blocked();
/** /// Returns signals with non-default handlers.
Returns signals with non-default handlers
*/
void get_signals_with_handlers(sigset_t *set); void get_signals_with_handlers(sigset_t *set);
#endif #endif