summaryrefslogtreecommitdiff
path: root/src/exchange/taler-exchange-httpd_keystate.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-01-20 12:10:44 +0100
committerChristian Grothoff <christian@grothoff.org>2020-01-20 12:10:44 +0100
commit52797133a472266c9e06fb5f66bd8793e443bd7e (patch)
tree0852b2d8d445fd22c58c9f6900fb30f94cfbc0e5 /src/exchange/taler-exchange-httpd_keystate.c
parent8a4201c43bd70032eecfeaa41a5d0b56a391c66a (diff)
downloadexchange-52797133a472266c9e06fb5f66bd8793e443bd7e.tar.gz
exchange-52797133a472266c9e06fb5f66bd8793e443bd7e.tar.bz2
exchange-52797133a472266c9e06fb5f66bd8793e443bd7e.zip
fix signal initialization race on startup with shutdown
Diffstat (limited to 'src/exchange/taler-exchange-httpd_keystate.c')
-rw-r--r--src/exchange/taler-exchange-httpd_keystate.c63
1 files changed, 32 insertions, 31 deletions
diff --git a/src/exchange/taler-exchange-httpd_keystate.c b/src/exchange/taler-exchange-httpd_keystate.c
index d70c0e7fc..27f22925d 100644
--- a/src/exchange/taler-exchange-httpd_keystate.c
+++ b/src/exchange/taler-exchange-httpd_keystate.c
@@ -2170,30 +2170,8 @@ handle_sigchld ()
int
TEH_KS_loop (void)
{
- struct GNUNET_SIGNAL_Context *sigusr1;
- struct GNUNET_SIGNAL_Context *sigterm;
- struct GNUNET_SIGNAL_Context *sigint;
- struct GNUNET_SIGNAL_Context *sighup;
- struct GNUNET_SIGNAL_Context *sigchld;
int ret;
- if (0 != pipe (reload_pipe))
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
- "pipe");
- return GNUNET_SYSERR;
- }
- sigusr1 = GNUNET_SIGNAL_handler_install (SIGUSR1,
- &handle_sigusr1);
- sigterm = GNUNET_SIGNAL_handler_install (SIGTERM,
- &handle_sigterm);
- sigint = GNUNET_SIGNAL_handler_install (SIGINT,
- &handle_sigint);
- sighup = GNUNET_SIGNAL_handler_install (SIGHUP,
- &handle_sighup);
- sigchld = GNUNET_SIGNAL_handler_install (SIGCHLD,
- &handle_sigchld);
-
ret = 2;
while (2 == ret)
{
@@ -2267,32 +2245,48 @@ TEH_KS_loop (void)
break;
}
}
- GNUNET_SIGNAL_handler_uninstall (sigusr1);
- GNUNET_SIGNAL_handler_uninstall (sigterm);
- GNUNET_SIGNAL_handler_uninstall (sigint);
- GNUNET_SIGNAL_handler_uninstall (sighup);
- GNUNET_SIGNAL_handler_uninstall (sigchld);
- GNUNET_break (0 == close (reload_pipe[0]));
- GNUNET_break (0 == close (reload_pipe[1]));
return ret;
}
+static struct GNUNET_SIGNAL_Context *sigusr1;
+static struct GNUNET_SIGNAL_Context *sigterm;
+static struct GNUNET_SIGNAL_Context *sigint;
+static struct GNUNET_SIGNAL_Context *sighup;
+static struct GNUNET_SIGNAL_Context *sigchld;
+
/**
* Setup initial #internal_key_state.
*/
-void
+int
TEH_KS_init (void)
{
+ if (0 != pipe (reload_pipe))
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
+ "pipe");
+ return GNUNET_SYSERR;
+ }
+ sigusr1 = GNUNET_SIGNAL_handler_install (SIGUSR1,
+ &handle_sigusr1);
+ sigterm = GNUNET_SIGNAL_handler_install (SIGTERM,
+ &handle_sigterm);
+ sigint = GNUNET_SIGNAL_handler_install (SIGINT,
+ &handle_sigint);
+ sighup = GNUNET_SIGNAL_handler_install (SIGHUP,
+ &handle_sighup);
+ sigchld = GNUNET_SIGNAL_handler_install (SIGCHLD,
+ &handle_sigchld);
/* no need to lock here, as we are still single-threaded */
internal_key_state = make_fresh_key_state (GNUNET_TIME_absolute_get ());
if (NULL == internal_key_state)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to setup initial key state. This exchange cannot work.\n");
- return;
+ return GNUNET_SYSERR;
}
internal_key_state->refcnt = 1;
+ return GNUNET_OK;
}
@@ -2312,6 +2306,13 @@ TEH_KS_free ()
GNUNET_assert (1 == ks->refcnt);
ks->refcnt--;
ks_free (ks);
+ GNUNET_SIGNAL_handler_uninstall (sigusr1);
+ GNUNET_SIGNAL_handler_uninstall (sigterm);
+ GNUNET_SIGNAL_handler_uninstall (sigint);
+ GNUNET_SIGNAL_handler_uninstall (sighup);
+ GNUNET_SIGNAL_handler_uninstall (sigchld);
+ GNUNET_break (0 == close (reload_pipe[0]));
+ GNUNET_break (0 == close (reload_pipe[1]));
}