mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-09-05 09:05:40 +00:00
417. [func] Add isc_app_block() and isc_app_unblock(), which
allow an application to handle signals while blocking.
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: app.c,v 1.28 2000/08/30 23:47:16 bwelling Exp $ */
|
||||
/* $Id: app.c,v 1.29 2000/09/01 21:31:51 bwelling Exp $ */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
@@ -58,6 +58,11 @@ static isc_boolean_t want_shutdown = ISC_FALSE;
|
||||
*/
|
||||
static isc_boolean_t want_reload = ISC_FALSE;
|
||||
|
||||
static isc_boolean_t blocked = ISC_FALSE;
|
||||
#ifdef ISC_PLATFORM_USETHREADS
|
||||
static pthread_t blockedthread;
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_LINUXTHREADS
|
||||
/*
|
||||
* Linux has sigwait(), but it appears to prevent signal handlers from
|
||||
@@ -521,3 +526,43 @@ isc_app_finish(void) {
|
||||
|
||||
DESTROYLOCK(&lock);
|
||||
}
|
||||
|
||||
void
|
||||
isc_app_block(void) {
|
||||
#ifdef ISC_PLATFORM_USETHREADS
|
||||
sigset_t sset;
|
||||
#endif
|
||||
REQUIRE(running);
|
||||
REQUIRE(!blocked);
|
||||
|
||||
blocked = ISC_TRUE;
|
||||
#ifdef ISC_PLATFORM_USETHREADS
|
||||
blockedthread = pthread_self();
|
||||
RUNTIME_CHECK(sigemptyset(&sset) == 0 &&
|
||||
sigaddset(&sset, SIGINT) == 0 &&
|
||||
sigaddset(&sset, SIGTERM) == 0);
|
||||
RUNTIME_CHECK(pthread_sigmask(SIG_UNBLOCK, &sset, NULL) == 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
isc_app_unblock(void) {
|
||||
#ifdef ISC_PLATFORM_USETHREADS
|
||||
sigset_t sset;
|
||||
#endif
|
||||
|
||||
REQUIRE(running);
|
||||
REQUIRE(blocked);
|
||||
|
||||
blocked = ISC_FALSE;
|
||||
|
||||
#ifdef ISC_PLATFORM_USETHREADS
|
||||
REQUIRE(blockedthread == pthread_self());
|
||||
|
||||
RUNTIME_CHECK(sigemptyset(&sset) == 0 &&
|
||||
sigaddset(&sset, SIGINT) == 0 &&
|
||||
sigaddset(&sset, SIGTERM) == 0);
|
||||
RUNTIME_CHECK(pthread_sigmask(SIG_BLOCK, &sset, NULL) == 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user