From 3781a3df94ce9bb28c98369df7a140fb4c086c23 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Mon, 6 Apr 2009 19:02:16 +0200 Subject: [PATCH] Kill remaining instances of signal(). Also, make para_sigaction() and para_install_sighandler() return void and exit on errors. --- afs.c | 5 +---- audiod.c | 2 +- command.c | 28 +++++++--------------------- error.h | 6 ++---- gui.c | 5 ++--- server.c | 35 +++++++++-------------------------- signal.c | 20 +++++++++----------- signal.h | 4 ++-- 8 files changed, 33 insertions(+), 72 deletions(-) diff --git a/afs.c b/afs.c index f4a44bbb..2ebc0089 100644 --- a/afs.c +++ b/afs.c @@ -805,10 +805,7 @@ static void register_signal_task(void) { struct signal_task *st = &signal_task_struct; - if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) { - PARA_EMERG_LOG("failed to ignore SIGPIPE\n"); - exit(EXIT_FAILURE); - } + para_sigaction(SIGPIPE, SIG_IGN); st->fd = para_signal_init(); PARA_INFO_LOG("signal pipe: fd %d\n", st->fd); para_install_sighandler(SIGINT); diff --git a/audiod.c b/audiod.c index 3a2607de..6d7cce5e 100644 --- a/audiod.c +++ b/audiod.c @@ -286,7 +286,7 @@ static void setup_signal_handling(void) para_install_sighandler(SIGINT); para_install_sighandler(SIGTERM); para_install_sighandler(SIGHUP); - signal(SIGPIPE, SIG_IGN); + para_sigaction(SIGPIPE, SIG_IGN); } static void clear_slot(int slot_num) diff --git a/command.c b/command.c index ca08ed72..229ec5c6 100644 --- a/command.c +++ b/command.c @@ -313,9 +313,7 @@ int com_stat(int fd, int argc, char * const * argv) struct misc_meta_data tmp, *nmmd = &tmp; char *s; - ret = para_sigaction(SIGUSR1, dummy); - if (ret < 0) - return ret; + para_sigaction(SIGUSR1, dummy); if (argc > 1) num = atoi(argv[1]); @@ -652,22 +650,12 @@ out: } -static int reset_signals(void) +static void reset_signals(void) { - int ret = para_sigaction(SIGCHLD, SIG_IGN); - - if (ret < 0) - return ret; - ret = para_sigaction(SIGINT, SIG_DFL); - if (ret < 0) - return ret; - ret = para_sigaction(SIGTERM, SIG_DFL); - if (ret < 0) - return ret; - ret = para_sigaction(SIGHUP, SIG_DFL); - if (ret < 0) - return ret; - return 1; + para_sigaction(SIGCHLD, SIG_IGN); + para_sigaction(SIGINT, SIG_DFL); + para_sigaction(SIGTERM, SIG_DFL); + para_sigaction(SIGHUP, SIG_DFL); } /** @@ -709,9 +697,7 @@ __noreturn void handle_connect(int fd, const char *peername) char *p, *command = NULL; size_t numbytes; - ret = reset_signals(); - if (ret < 0) - goto err_out; + reset_signals(); /* we need a blocking fd here as recv() might return EAGAIN otherwise. */ ret = mark_fd_blocking(fd); if (ret < 0) diff --git a/error.h b/error.h index 94a41202..81910e2d 100644 --- a/error.h +++ b/error.h @@ -29,6 +29,8 @@ DEFINE_ERRLIST_OBJECT_ENUM; #define HTTP_SEND_ERRORS #define GGO_ERRORS #define COLOR_ERRORS +#define SIGNAL_ERRORS + extern const char **para_errlist[]; @@ -299,10 +301,6 @@ extern const char **para_errlist[]; PARA_ERROR(FILTER_SYNTAX, "syntax error"), \ -#define SIGNAL_ERRORS \ - PARA_ERROR(SIGNAL_SIG_ERR, "signal() returned SIG_ERR"), \ - - #define STRING_ERRORS \ PARA_ERROR(ATOI_OVERFLOW, "value too large"), \ PARA_ERROR(STRTOLL, "unknown strtoll error"), \ diff --git a/gui.c b/gui.c index 15422b96..fc2cd9a1 100644 --- a/gui.c +++ b/gui.c @@ -521,13 +521,12 @@ static void setup_signal_handling(void) para_install_sighandler(SIGCHLD); para_install_sighandler(SIGWINCH); para_install_sighandler(SIGUSR1); -// signal(SIGPIPE, SIG_IGN); - signal(SIGHUP, SIG_IGN); + para_sigaction(SIGHUP, SIG_IGN); } __noreturn static void do_exit(int ret) { - signal(SIGTERM, SIG_IGN); + para_sigaction(SIGTERM, SIG_IGN); kill(0, SIGTERM); exit(ret); } diff --git a/server.c b/server.c index c5c97612..79e67818 100644 --- a/server.c +++ b/server.c @@ -318,25 +318,15 @@ static void init_signal_task(void) st->task.post_select = signal_post_select; sprintf(st->task.status, "signal task"); + PARA_NOTICE_LOG("setting up signal handling\n"); st->fd = para_signal_init(); /* always successful */ - - PARA_NOTICE_LOG("setting up signal handlers\n"); - if (para_install_sighandler(SIGINT) < 0) - goto err; - if (para_install_sighandler(SIGTERM) < 0) - goto err; - if (para_install_sighandler(SIGHUP) < 0) - goto err; - if (para_install_sighandler(SIGCHLD) < 0) - goto err; - if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) - goto err; + para_install_sighandler(SIGINT); + para_install_sighandler(SIGTERM); + para_install_sighandler(SIGHUP); + para_install_sighandler(SIGCHLD); + para_sigaction(SIGPIPE, SIG_IGN); add_close_on_fork_list(st->fd); register_task(&st->task); - return; -err: - PARA_EMERG_LOG("could not install signal handlers\n"); - exit(EXIT_FAILURE); } static void command_pre_select(struct sched *s, struct task *t) @@ -485,7 +475,7 @@ static void server_init(int argc, char **argv) .check_ambiguity = 0, .print_errors = 1 }; - int ret, afs_socket; + int afs_socket; valid_fd_012(); init_random_seed(); @@ -514,20 +504,13 @@ static void server_init(int argc, char **argv) * before the child gets a chance to ignore this signal -- only the * good die young. */ - if (signal(SIGUSR1, SIG_IGN) == SIG_ERR) { - PARA_EMERG_LOG("failed to ignore SIGUSR1\n"); - exit(EXIT_FAILURE); - } + para_sigaction(SIGUSR1, SIG_IGN); /* * We have to install a SIGCHLD handler before the afs process is being * forked off. Otherwise, para_server does not notice if afs dies before * the SIGCHLD handler has been installed by init_signal_task() below. */ - ret = para_sigaction(SIGCHLD, tmp_sigchld_handler); - if (ret < 0) { - PARA_EMERG_LOG("SIGCHLD: %s\n", para_strerror(-ret)); - exit(EXIT_FAILURE); - } + para_sigaction(SIGCHLD, tmp_sigchld_handler); PARA_NOTICE_LOG("initializing the audio file selector\n"); afs_socket = init_afs(); init_signal_task(); diff --git a/signal.c b/signal.c index 84f73fc8..59a0d45a 100644 --- a/signal.c +++ b/signal.c @@ -122,12 +122,11 @@ void para_reap_children(void) * \param sig The number of the signal to catch. * \param handler to be installed, \p SIG_IGN, or \p SIG_DFL. * - * \return This function returns 1 on success and \p -E_SIGNAL_SIG_ERR on - * errors. + * This either succeeds or calls exit(EXIT_FAILURE). * * \sa sigaction(2). */ -int para_sigaction(int sig, void (*handler)(int)) +void para_sigaction(int sig, void (*handler)(int)) { struct sigaction act; @@ -144,9 +143,11 @@ int para_sigaction(int sig, void (*handler)(int)) act.sa_flags |= SA_RESTART; #endif } - if (sigaction(sig, &act, NULL) < 0) - return -E_SIGNAL_SIG_ERR; - return 1; + if (sigaction(sig, &act, NULL) >= 0) + return; + PARA_EMERG_LOG("failed to install signal handler for signal %d\n", + sig); + exit(EXIT_FAILURE); } /** @@ -154,14 +155,11 @@ int para_sigaction(int sig, void (*handler)(int)) * * \param sig The number of the signal to catch. * - * \return This function returns 1 on success and \p -E_SIGNAL_SIG_ERR on - * errors. - * * \sa signal(2), sigaction(2). */ -int para_install_sighandler(int sig) +void para_install_sighandler(int sig) { - return para_sigaction(sig, &generic_signal_handler); + para_sigaction(sig, &generic_signal_handler); } /** diff --git a/signal.h b/signal.h index 610c4d89..685654d5 100644 --- a/signal.h +++ b/signal.h @@ -19,8 +19,8 @@ struct signal_task { }; int para_signal_init(void); -int para_sigaction(int sig, void (*handler)(int)); -int para_install_sighandler(int); +void para_sigaction(int sig, void (*handler)(int)); +void para_install_sighandler(int); void para_reap_children(void); int para_reap_child(pid_t *pid); int para_next_signal(void); -- 2.39.5