{
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);
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)
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]);
}
-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);
}
/**
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)
#define HTTP_SEND_ERRORS
#define GGO_ERRORS
#define COLOR_ERRORS
+#define SIGNAL_ERRORS
+
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"), \
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);
}
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)
.check_ambiguity = 0,
.print_errors = 1
};
- int ret, afs_socket;
+ int afs_socket;
valid_fd_012();
init_random_seed();
* 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();
* \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;
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);
}
/**
*
* \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);
}
/**
};
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);