setjmp/longjmp isn't supported by all compilers.
Having a pipe pair to wake an event wait loop from within a signal handler
is rather portable and common enough.
Signed-off-by: Kurt Van Dijck <dev.kurt@vandijck-laurijssen.be>
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
#include <netdb.h>
#include <utmp.h>
#include <pwd.h>
#include <netdb.h>
#include <utmp.h>
#include <pwd.h>
#include <sys/param.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/param.h>
#include <sys/types.h>
#include <sys/wait.h>
static sigset_t signals_handled;
static int waiting;
static sigset_t signals_handled;
static int waiting;
-static sigjmp_buf sigjmp;
char **script_env; /* Env. variable values for scripts */
int s_env_nalloc; /* # words avail at script_env */
char **script_env; /* Env. variable values for scripts */
int s_env_nalloc; /* # words avail at script_env */
handle_events()
{
struct timeval timo;
handle_events()
{
struct timeval timo;
kill_link = open_ccp_flag = 0;
kill_link = open_ccp_flag = 0;
- if (sigsetjmp(sigjmp, 1) == 0) {
- sigprocmask(SIG_BLOCK, &signals_handled, NULL);
- if (got_sighup || got_sigterm || got_sigusr2 || got_sigchld) {
- sigprocmask(SIG_UNBLOCK, &signals_handled, NULL);
- } else {
- waiting = 1;
- sigprocmask(SIG_UNBLOCK, &signals_handled, NULL);
- wait_input(timeleft(&timo));
- }
- }
+
+ /* alert via signal pipe */
+ waiting = 1;
+ /* flush signal pipe */
+ for (; read(sigpipe[0], buf, sizeof(buf)) > 0; );
+ add_fd(sigpipe[0]);
+ /* wait if necessary */
+ if (!(got_sighup || got_sigterm || got_sigusr2 || got_sigchld))
+ wait_input(timeleft(&timo));
+ remove_fd(sigpipe[0]);
+
calltimeout();
if (got_sighup) {
info("Hangup (SIGHUP)");
calltimeout();
if (got_sighup) {
info("Hangup (SIGHUP)");
+ /* create pipe to wake up event handler from signal handler */
+ if (pipe(sigpipe) < 0)
+ fatal("Couldn't create signal pipe: %m");
+ fcntl(sigpipe[0], F_SETFD, fcntl(sigpipe[0], F_GETFD) | FD_CLOEXEC);
+ fcntl(sigpipe[1], F_SETFD, fcntl(sigpipe[1], F_GETFD) | FD_CLOEXEC);
+ fcntl(sigpipe[0], F_SETFL, fcntl(sigpipe[0], F_GETFL) | O_NONBLOCK);
+ fcntl(sigpipe[1], F_SETFL, fcntl(sigpipe[1], F_GETFL) | O_NONBLOCK);
+
/*
* Compute mask of all interesting signals and install signal handlers
* for each. Only one signal handler may be active at a time. Therefore,
/*
* Compute mask of all interesting signals and install signal handlers
* for each. Only one signal handler may be active at a time. Therefore,
kill_my_pg(sig);
notify(sigreceived, sig);
if (waiting)
kill_my_pg(sig);
notify(sigreceived, sig);
if (waiting)
+ write(sigpipe[1], &sig, sizeof(sig));
kill_my_pg(sig);
notify(sigreceived, sig);
if (waiting)
kill_my_pg(sig);
notify(sigreceived, sig);
if (waiting)
+ write(sigpipe[1], &sig, sizeof(sig));
{
got_sigchld = 1;
if (waiting)
{
got_sigchld = 1;
if (waiting)
+ write(sigpipe[1], &sig, sizeof(sig));
{
got_sigusr2 = 1;
if (waiting)
{
got_sigusr2 = 1;
if (waiting)
+ write(sigpipe[1], &sig, sizeof(sig));
#include <netdb.h>
#include <utmp.h>
#include <pwd.h>
#include <netdb.h>
#include <utmp.h>
#include <pwd.h>
#include <sys/param.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/param.h>
#include <sys/types.h>
#include <sys/wait.h>