2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-31 22:45:39 +00:00

Make lib/isc/app.c opaque and thread-safe

This work cleans up the API which includes couple of things:

1. Make the isc_appctx_t type fully opaque

2. Protect all access to the isc_app_t members via stdatomics

3. sigwait() is part of POSIX.1, remove dead non-sigwait code

4. Remove unused code: isc_appctx_set{taskmgr,sockmgr,timermgr}
This commit is contained in:
Ondřej Surý
2019-05-13 20:58:20 +07:00
parent 4d30aee3e2
commit eb8c9bdd55
20 changed files with 213 additions and 509 deletions

View File

@@ -1622,9 +1622,9 @@ main(int argc, char *argv[]) {
fatal("failed to create mctx"); fatal("failed to create mctx");
CHECK(isc_appctx_create(mctx, &actx)); CHECK(isc_appctx_create(mctx, &actx));
CHECK(isc_taskmgr_createinctx(mctx, actx, 1, 0, &taskmgr)); CHECK(isc_taskmgr_createinctx(mctx, 1, 0, &taskmgr));
CHECK(isc_socketmgr_createinctx(mctx, actx, &socketmgr)); CHECK(isc_socketmgr_createinctx(mctx, &socketmgr));
CHECK(isc_timermgr_createinctx(mctx, actx, &timermgr)); CHECK(isc_timermgr_createinctx(mctx, &timermgr));
parse_args(argc, argv); parse_args(argc, argv);

View File

@@ -278,7 +278,7 @@ rndc_senddone(isc_task_t *task, isc_event_t *event) {
if (sends == 0 && recvs == 0) { if (sends == 0 && recvs == 0) {
isc_socket_detach(&sock); isc_socket_detach(&sock);
isc_task_shutdown(task); isc_task_shutdown(task);
RUNTIME_CHECK(isc_app_shutdown() == ISC_R_SUCCESS); isc_app_shutdown();
} }
} }
@@ -347,7 +347,7 @@ rndc_recvdone(isc_task_t *task, isc_event_t *event) {
if (sends == 0 && recvs == 0) { if (sends == 0 && recvs == 0) {
isc_socket_detach(&sock); isc_socket_detach(&sock);
isc_task_shutdown(task); isc_task_shutdown(task);
RUNTIME_CHECK(isc_app_shutdown() == ISC_R_SUCCESS); isc_app_shutdown();
} }
} }

View File

@@ -98,7 +98,7 @@ tick(isc_task_t *task, isc_event_t *event) {
info->ticks++; info->ticks++;
if (strcmp(info->name, "1") == 0) { if (strcmp(info->name, "1") == 0) {
if (info->ticks == 10) { if (info->ticks == 10) {
RUNTIME_CHECK(isc_app_shutdown() == ISC_R_SUCCESS); isc_app_shutdown();
} else if (info->ticks >= 15 && info->exiting) { } else if (info->ticks >= 15 && info->exiting) {
isc_timer_detach(&info->timer); isc_timer_detach(&info->timer);
isc_task_detach(&info->task); isc_task_detach(&info->task);

View File

@@ -635,10 +635,7 @@ LIBS="$PTHREAD_LIBS $LIBS"
CFLAGS="$CFLAGS $PTHREAD_CFLAGS" CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
CC="$PTHREAD_CC" CC="$PTHREAD_CC"
# AC_CHECK_FUNCS([pthread_attr_getstacksize pthread_attr_setstacksize])
# We'd like to use sigwait() too
#
AC_CHECK_FUNCS([sigwait pthread_attr_getstacksize pthread_attr_setstacksize])
AC_ARG_WITH([locktype], AC_ARG_WITH([locktype],
AS_HELP_STRING([--with-locktype=ARG], AS_HELP_STRING([--with-locktype=ARG],

View File

@@ -420,13 +420,13 @@ dns_client_create(dns_client_t **clientp, unsigned int options) {
result = isc_app_ctxstart(actx); result = isc_app_ctxstart(actx);
if (result != ISC_R_SUCCESS) if (result != ISC_R_SUCCESS)
goto cleanup; goto cleanup;
result = isc_taskmgr_createinctx(mctx, actx, 1, 0, &taskmgr); result = isc_taskmgr_createinctx(mctx, 1, 0, &taskmgr);
if (result != ISC_R_SUCCESS) if (result != ISC_R_SUCCESS)
goto cleanup; goto cleanup;
result = isc_socketmgr_createinctx(mctx, actx, &socketmgr); result = isc_socketmgr_createinctx(mctx, &socketmgr);
if (result != ISC_R_SUCCESS) if (result != ISC_R_SUCCESS)
goto cleanup; goto cleanup;
result = isc_timermgr_createinctx(mctx, actx, &timermgr); result = isc_timermgr_createinctx(mctx, &timermgr);
if (result != ISC_R_SUCCESS) if (result != ISC_R_SUCCESS)
goto cleanup; goto cleanup;
#if 0 #if 0

View File

@@ -101,15 +101,15 @@ ctxs_init(isc_mem_t **mctxp, isc_appctx_t **actxp,
if (result != ISC_R_SUCCESS) if (result != ISC_R_SUCCESS)
goto fail; goto fail;
result = isc_taskmgr_createinctx(*mctxp, *actxp, 1, 0, taskmgrp); result = isc_taskmgr_createinctx(*mctxp, 1, 0, taskmgrp);
if (result != ISC_R_SUCCESS) if (result != ISC_R_SUCCESS)
goto fail; goto fail;
result = isc_socketmgr_createinctx(*mctxp, *actxp, socketmgrp); result = isc_socketmgr_createinctx(*mctxp, socketmgrp);
if (result != ISC_R_SUCCESS) if (result != ISC_R_SUCCESS)
goto fail; goto fail;
result = isc_timermgr_createinctx(*mctxp, *actxp, timermgrp); result = isc_timermgr_createinctx(*mctxp, timermgrp);
if (result != ISC_R_SUCCESS) if (result != ISC_R_SUCCESS)
goto fail; goto fail;

View File

@@ -103,14 +103,7 @@ typedef isc_event_t isc_appevent_t;
* of the isc_app_ routines to work. app implementations must maintain * of the isc_app_ routines to work. app implementations must maintain
* all app context invariants. * all app context invariants.
*/ */
struct isc_appctx { struct isc_appctx;
unsigned int impmagic;
unsigned int magic;
};
#define ISCAPI_APPCTX_MAGIC ISC_MAGIC('A','a','p','c')
#define ISCAPI_APPCTX_VALID(c) ((c) != NULL && \
(c)->magic == ISCAPI_APPCTX_MAGIC)
ISC_LANG_BEGINDECLS ISC_LANG_BEGINDECLS
@@ -184,10 +177,10 @@ isc_app_isrunning(void);
*\li false App is not running. *\li false App is not running.
*/ */
isc_result_t void
isc_app_ctxshutdown(isc_appctx_t *ctx); isc_app_ctxshutdown(isc_appctx_t *ctx);
isc_result_t void
isc_app_shutdown(void); isc_app_shutdown(void);
/*!< /*!<
* \brief Request application shutdown. * \brief Request application shutdown.
@@ -205,13 +198,13 @@ isc_app_shutdown(void);
*\li ISC_R_UNEXPECTED *\li ISC_R_UNEXPECTED
*/ */
isc_result_t void
isc_app_ctxsuspend(isc_appctx_t *ctx); isc_app_ctxsuspend(isc_appctx_t *ctx);
/*!< /*!<
* \brief This has the same behavior as isc_app_ctxsuspend(). * \brief This has the same behavior as isc_app_ctxsuspend().
*/ */
isc_result_t void
isc_app_reload(void); isc_app_reload(void);
/*!< /*!<
* \brief Request application reload. * \brief Request application reload.
@@ -295,44 +288,6 @@ isc_appctx_destroy(isc_appctx_t **ctxp);
*\li *ctxp == NULL. *\li *ctxp == NULL.
*/ */
void
isc_appctx_settaskmgr(isc_appctx_t *ctx, isc_taskmgr_t *taskmgr);
/*!<
* \brief Associate a task manager with an application context.
*
* This must be done before running tasks within the application context.
*
* Requires:
*\li 'ctx' is a valid application context.
*\li 'taskmgr' is a valid task manager.
*/
void
isc_appctx_setsocketmgr(isc_appctx_t *ctx, isc_socketmgr_t *socketmgr);
/*!<
* \brief Associate a socket manager with an application context.
*
* This must be done before handling socket events within the application
* context.
*
* Requires:
*\li 'ctx' is a valid application context.
*\li 'socketmgr' is a valid socket manager.
*/
void
isc_appctx_settimermgr(isc_appctx_t *ctx, isc_timermgr_t *timermgr);
/*!<
* \brief Associate a socket timer with an application context.
*
* This must be done before handling timer events within the application
* context.
*
* Requires:
*\li 'ctx' is a valid application context.
*\li 'timermgr' is a valid timer manager.
*/
ISC_LANG_ENDDECLS ISC_LANG_ENDDECLS
#endif /* ISC_APP_H */ #endif /* ISC_APP_H */

View File

@@ -805,8 +805,7 @@ isc_socket_sendto2(isc_socket_t *sock, isc_region_t *region,
/*@}*/ /*@}*/
isc_result_t isc_result_t
isc_socketmgr_createinctx(isc_mem_t *mctx, isc_appctx_t *actx, isc_socketmgr_createinctx(isc_mem_t *mctx, isc_socketmgr_t **managerp);
isc_socketmgr_t **managerp);
isc_result_t isc_result_t
isc_socketmgr_create(isc_mem_t *mctx, isc_socketmgr_t **managerp); isc_socketmgr_create(isc_mem_t *mctx, isc_socketmgr_t **managerp);

View File

@@ -630,7 +630,7 @@ isc_task_privilege(isc_task_t *task);
*****/ *****/
isc_result_t isc_result_t
isc_taskmgr_createinctx(isc_mem_t *mctx, isc_appctx_t *actx, isc_taskmgr_createinctx(isc_mem_t *mctx,
unsigned int workers, unsigned int default_quantum, unsigned int workers, unsigned int default_quantum,
isc_taskmgr_t **managerp); isc_taskmgr_t **managerp);
isc_result_t isc_result_t

View File

@@ -316,8 +316,7 @@ isc_timer_gettype(isc_timer_t *timer);
*/ */
isc_result_t isc_result_t
isc_timermgr_createinctx(isc_mem_t *mctx, isc_appctx_t *actx, isc_timermgr_createinctx(isc_mem_t *mctx, isc_timermgr_t **managerp);
isc_timermgr_t **managerp);
isc_result_t isc_result_t
isc_timermgr_create(isc_mem_t *mctx, isc_timermgr_t **managerp); isc_timermgr_create(isc_mem_t *mctx, isc_timermgr_t **managerp);

View File

@@ -1871,7 +1871,7 @@ isc_taskmgr_renderjson(isc_taskmgr_t *mgr0, json_object *tasks) {
isc_result_t isc_result_t
isc_taskmgr_createinctx(isc_mem_t *mctx, isc_appctx_t *actx, isc_taskmgr_createinctx(isc_mem_t *mctx,
unsigned int workers, unsigned int default_quantum, unsigned int workers, unsigned int default_quantum,
isc_taskmgr_t **managerp) isc_taskmgr_t **managerp)
{ {
@@ -1880,8 +1880,5 @@ isc_taskmgr_createinctx(isc_mem_t *mctx, isc_appctx_t *actx,
result = isc_taskmgr_create(mctx, workers, default_quantum, result = isc_taskmgr_create(mctx, workers, default_quantum,
managerp); managerp);
if (result == ISC_R_SUCCESS)
isc_appctx_settaskmgr(actx, *managerp);
return (result); return (result);
} }

View File

@@ -784,15 +784,11 @@ isc_timermgr_destroy(isc_timermgr_t **managerp) {
} }
isc_result_t isc_result_t
isc_timermgr_createinctx(isc_mem_t *mctx, isc_appctx_t *actx, isc_timermgr_createinctx(isc_mem_t *mctx, isc_timermgr_t **managerp)
isc_timermgr_t **managerp)
{ {
isc_result_t result; isc_result_t result;
result = isc_timermgr_create(mctx, managerp); result = isc_timermgr_create(mctx, managerp);
if (result == ISC_R_SUCCESS)
isc_appctx_settimermgr(actx, *managerp);
return (result); return (result);
} }

View File

@@ -27,6 +27,7 @@
#endif #endif
#include <isc/platform.h> #include <isc/platform.h>
#include <isc/atomic.h>
#include <isc/app.h> #include <isc/app.h>
#include <isc/condition.h> #include <isc/condition.h>
#include <isc/mem.h> #include <isc/mem.h>
@@ -48,7 +49,7 @@
* as an event loop dispatching various events. * as an event loop dispatching various events.
*/ */
static pthread_t blockedthread; static pthread_t blockedthread;
static bool is_running; static atomic_bool is_running;
/* /*
* The application context of this module. This implementation actually * The application context of this module. This implementation actually
@@ -57,72 +58,41 @@ static bool is_running;
#define APPCTX_MAGIC ISC_MAGIC('A', 'p', 'c', 'x') #define APPCTX_MAGIC ISC_MAGIC('A', 'p', 'c', 'x')
#define VALID_APPCTX(c) ISC_MAGIC_VALID(c, APPCTX_MAGIC) #define VALID_APPCTX(c) ISC_MAGIC_VALID(c, APPCTX_MAGIC)
typedef struct isc__appctx { struct isc_appctx {
isc_appctx_t common; unsigned int magic;
isc_mem_t *mctx; isc_mem_t *mctx;
isc_mutex_t lock; isc_mutex_t lock;
isc_eventlist_t on_run; isc_eventlist_t on_run;
bool shutdown_requested; atomic_bool shutdown_requested;
bool running; atomic_bool running;
atomic_bool want_shutdown;
/*! atomic_bool want_reload;
* We assume that 'want_shutdown' can be read and written atomically. atomic_bool blocked;
*/
bool want_shutdown;
/*
* We assume that 'want_reload' can be read and written atomically.
*/
bool want_reload;
bool blocked;
isc_taskmgr_t *taskmgr;
isc_socketmgr_t *socketmgr;
isc_timermgr_t *timermgr;
isc_mutex_t readylock; isc_mutex_t readylock;
isc_condition_t ready; isc_condition_t ready;
} isc__appctx_t; };
static isc__appctx_t isc_g_appctx; static isc_appctx_t isc_g_appctx;
#ifndef HAVE_SIGWAIT
static void
exit_action(int arg) {
UNUSED(arg);
isc_g_appctx.want_shutdown = true;
}
static void static void
reload_action(int arg) {
UNUSED(arg);
isc_g_appctx.want_reload = true;
}
#endif
static isc_result_t
handle_signal(int sig, void (*handler)(int)) { handle_signal(int sig, void (*handler)(int)) {
struct sigaction sa; struct sigaction sa;
char strbuf[ISC_STRERRORSIZE];
memset(&sa, 0, sizeof(sa)); memset(&sa, 0, sizeof(sa));
sa.sa_handler = handler; sa.sa_handler = handler;
if (sigfillset(&sa.sa_mask) != 0 || if (sigfillset(&sa.sa_mask) != 0 ||
sigaction(sig, &sa, NULL) < 0) { sigaction(sig, &sa, NULL) < 0) {
char strbuf[ISC_STRERRORSIZE];
strerror_r(errno, strbuf, sizeof(strbuf)); strerror_r(errno, strbuf, sizeof(strbuf));
UNEXPECTED_ERROR(__FILE__, __LINE__, isc_error_fatal(__FILE__, __LINE__,
"handle_signal() %d setup: %s", "handle_signal() %d setup: %s",
sig, strbuf); sig, strbuf);
return (ISC_R_UNEXPECTED);
} }
return (ISC_R_SUCCESS);
} }
isc_result_t isc_result_t
isc_app_ctxstart(isc_appctx_t *ctx0) { isc_app_ctxstart(isc_appctx_t *ctx) {
isc__appctx_t *ctx = (isc__appctx_t *)ctx0;
isc_result_t result;
int presult; int presult;
sigset_t sset; sigset_t sset;
char strbuf[ISC_STRERRORSIZE]; char strbuf[ISC_STRERRORSIZE];
@@ -133,64 +103,27 @@ isc_app_ctxstart(isc_appctx_t *ctx0) {
* Start an ISC library application. * Start an ISC library application.
*/ */
isc_mutex_init(&ctx->readylock);
isc_condition_init(&ctx->ready);
isc_mutex_init(&ctx->lock); isc_mutex_init(&ctx->lock);
isc_mutex_init(&ctx->readylock);
isc_condition_init(&ctx->ready);
ISC_LIST_INIT(ctx->on_run); ISC_LIST_INIT(ctx->on_run);
ctx->shutdown_requested = false; atomic_init(&ctx->shutdown_requested, false);
ctx->running = false; atomic_init(&ctx->running, false);
ctx->want_shutdown = false; atomic_init(&ctx->want_shutdown, false);
ctx->want_reload = false; atomic_init(&ctx->want_reload, false);
ctx->blocked = false; atomic_init(&ctx->blocked, false);
#ifndef HAVE_SIGWAIT
/*
* Install do-nothing handlers for SIGINT and SIGTERM.
*
* We install them now because BSDI 3.1 won't block
* the default actions, regardless of what we do with
* pthread_sigmask().
*/
result = handle_signal(SIGINT, exit_action);
if (result != ISC_R_SUCCESS)
goto cleanup;
result = handle_signal(SIGTERM, exit_action);
if (result != ISC_R_SUCCESS)
goto cleanup;
#endif
/* /*
* Always ignore SIGPIPE. * Always ignore SIGPIPE.
*/ */
result = handle_signal(SIGPIPE, SIG_IGN); handle_signal(SIGPIPE, SIG_IGN);
if (result != ISC_R_SUCCESS)
goto cleanup;
/* handle_signal(SIGHUP, SIG_DFL);
* On Solaris 2, delivery of a signal whose action is SIG_IGN handle_signal(SIGTERM, SIG_DFL);
* will not cause sigwait() to return. We may have inherited handle_signal(SIGINT, SIG_DFL);
* unexpected actions for SIGHUP, SIGINT, and SIGTERM from our parent
* process (e.g, Solaris cron). Set an action of SIG_DFL to make
* sure sigwait() works as expected. Only do this for SIGTERM and
* SIGINT if we don't have sigwait(), since a different handler is
* installed above.
*/
result = handle_signal(SIGHUP, SIG_DFL);
if (result != ISC_R_SUCCESS)
goto cleanup;
#ifdef HAVE_SIGWAIT
result = handle_signal(SIGTERM, SIG_DFL);
if (result != ISC_R_SUCCESS)
goto cleanup;
result = handle_signal(SIGINT, SIG_DFL);
if (result != ISC_R_SUCCESS)
goto cleanup;
#endif
/* /*
* Block SIGHUP, SIGINT, SIGTERM. * Block SIGHUP, SIGINT, SIGTERM.
@@ -206,61 +139,45 @@ isc_app_ctxstart(isc_appctx_t *ctx0) {
sigaddset(&sset, SIGINT) != 0 || sigaddset(&sset, SIGINT) != 0 ||
sigaddset(&sset, SIGTERM) != 0) { sigaddset(&sset, SIGTERM) != 0) {
strerror_r(errno, strbuf, sizeof(strbuf)); strerror_r(errno, strbuf, sizeof(strbuf));
UNEXPECTED_ERROR(__FILE__, __LINE__, isc_error_fatal(__FILE__, __LINE__,
"isc_app_start() sigsetops: %s", strbuf); "isc_app_start() sigsetops: %s", strbuf);
result = ISC_R_UNEXPECTED;
goto cleanup;
} }
presult = pthread_sigmask(SIG_BLOCK, &sset, NULL); presult = pthread_sigmask(SIG_BLOCK, &sset, NULL);
if (presult != 0) { if (presult != 0) {
strerror_r(presult, strbuf, sizeof(strbuf)); strerror_r(presult, strbuf, sizeof(strbuf));
UNEXPECTED_ERROR(__FILE__, __LINE__, isc_error_fatal(__FILE__, __LINE__,
"isc_app_start() pthread_sigmask: %s", "isc_app_start() pthread_sigmask: %s",
strbuf); strbuf);
result = ISC_R_UNEXPECTED;
goto cleanup;
} }
return (ISC_R_SUCCESS); return (ISC_R_SUCCESS);
cleanup:
(void)isc_condition_destroy(&ctx->ready);
(void)isc_mutex_destroy(&ctx->readylock);
return (result);
} }
isc_result_t isc_result_t
isc_app_start(void) { isc_app_start(void) {
isc_g_appctx.common.impmagic = APPCTX_MAGIC; isc_g_appctx.magic = APPCTX_MAGIC;
isc_g_appctx.common.magic = ISCAPI_APPCTX_MAGIC;
isc_g_appctx.mctx = NULL; isc_g_appctx.mctx = NULL;
/* The remaining members will be initialized in ctxstart() */ /* The remaining members will be initialized in ctxstart() */
return (isc_app_ctxstart((isc_appctx_t *)&isc_g_appctx)); return (isc_app_ctxstart(&isc_g_appctx));
} }
isc_result_t isc_result_t
isc_app_onrun(isc_mem_t *mctx, isc_task_t *task, isc_taskaction_t action, isc_app_onrun(isc_mem_t *mctx, isc_task_t *task, isc_taskaction_t action,
void *arg) void *arg)
{ {
return (isc_app_ctxonrun((isc_appctx_t *)&isc_g_appctx, mctx, return (isc_app_ctxonrun(&isc_g_appctx, mctx, task, action, arg));
task, action, arg));
} }
isc_result_t isc_result_t
isc_app_ctxonrun(isc_appctx_t *ctx0, isc_mem_t *mctx, isc_task_t *task, isc_app_ctxonrun(isc_appctx_t *ctx, isc_mem_t *mctx, isc_task_t *task,
isc_taskaction_t action, void *arg) isc_taskaction_t action, void *arg)
{ {
isc__appctx_t *ctx = (isc__appctx_t *)ctx0;
isc_event_t *event; isc_event_t *event;
isc_task_t *cloned_task = NULL; isc_task_t *cloned_task = NULL;
isc_result_t result;
LOCK(&ctx->lock); if (atomic_load_acquire(&ctx->running)) {
return (ISC_R_ALREADYRUNNING);
if (ctx->running) {
result = ISC_R_ALREADYRUNNING;
goto unlock;
} }
/* /*
@@ -272,42 +189,34 @@ isc_app_ctxonrun(isc_appctx_t *ctx0, isc_mem_t *mctx, isc_task_t *task,
action, arg, sizeof(*event)); action, arg, sizeof(*event));
if (event == NULL) { if (event == NULL) {
isc_task_detach(&cloned_task); isc_task_detach(&cloned_task);
result = ISC_R_NOMEMORY; return (ISC_R_NOMEMORY);
goto unlock;
} }
LOCK(&ctx->lock);
ISC_LIST_APPEND(ctx->on_run, event, ev_link); ISC_LIST_APPEND(ctx->on_run, event, ev_link);
result = ISC_R_SUCCESS;
unlock:
UNLOCK(&ctx->lock); UNLOCK(&ctx->lock);
return (result); return (ISC_R_SUCCESS);
} }
isc_result_t isc_result_t
isc_app_ctxrun(isc_appctx_t *ctx0) { isc_app_ctxrun(isc_appctx_t *ctx) {
isc__appctx_t *ctx = (isc__appctx_t *)ctx0;
int result;
isc_event_t *event, *next_event; isc_event_t *event, *next_event;
isc_task_t *task; isc_task_t *task;
sigset_t sset; sigset_t sset;
char strbuf[ISC_STRERRORSIZE];
#ifdef HAVE_SIGWAIT
int sig; int sig;
#endif /* HAVE_SIGWAIT */ bool exp_false = false;
bool exp_true = true;
REQUIRE(VALID_APPCTX(ctx)); REQUIRE(VALID_APPCTX(ctx));
LOCK(&ctx->lock); if (atomic_compare_exchange_weak_acq_rel(
&ctx->running, &exp_false, true) == true)
if (!ctx->running) { {
ctx->running = true;
/* /*
* Post any on-run events (in FIFO order). * Post any on-run events (in FIFO order).
*/ */
LOCK(&ctx->lock);
for (event = ISC_LIST_HEAD(ctx->on_run); for (event = ISC_LIST_HEAD(ctx->on_run);
event != NULL; event != NULL;
event = next_event) { event = next_event) {
@@ -317,17 +226,15 @@ isc_app_ctxrun(isc_appctx_t *ctx0) {
event->ev_sender = NULL; event->ev_sender = NULL;
isc_task_sendanddetach(&task, &event); isc_task_sendanddetach(&task, &event);
} }
}
UNLOCK(&ctx->lock); UNLOCK(&ctx->lock);
}
/* /*
* BIND9 internal tools using multiple contexts do not * BIND9 internal tools using multiple contexts do not
* rely on signal. * rely on signal. */
*/ if (isc_bind9 && ctx != &isc_g_appctx) {
if (isc_bind9 && ctx != &isc_g_appctx)
return (ISC_R_SUCCESS); return (ISC_R_SUCCESS);
}
/* /*
* There is no danger if isc_app_shutdown() is called before we * There is no danger if isc_app_shutdown() is called before we
@@ -335,8 +242,7 @@ isc_app_ctxrun(isc_appctx_t *ctx0) {
* simply be made pending and we will get it when we call * simply be made pending and we will get it when we call
* sigwait(). * sigwait().
*/ */
while (!ctx->want_shutdown) { while (atomic_load_acquire(&ctx->want_shutdown) == false) {
#ifdef HAVE_SIGWAIT
if (isc_bind9) { if (isc_bind9) {
/* /*
* BIND9 internal; single context: * BIND9 internal; single context:
@@ -346,89 +252,57 @@ isc_app_ctxrun(isc_appctx_t *ctx0) {
sigaddset(&sset, SIGHUP) != 0 || sigaddset(&sset, SIGHUP) != 0 ||
sigaddset(&sset, SIGINT) != 0 || sigaddset(&sset, SIGINT) != 0 ||
sigaddset(&sset, SIGTERM) != 0) { sigaddset(&sset, SIGTERM) != 0) {
char strbuf[ISC_STRERRORSIZE];
strerror_r(errno, strbuf, sizeof(strbuf)); strerror_r(errno, strbuf, sizeof(strbuf));
UNEXPECTED_ERROR(__FILE__, __LINE__, isc_error_fatal(__FILE__, __LINE__,
"isc_app_run() sigsetops: %s", "isc_app_run() sigsetops: %s",
strbuf); strbuf);
return (ISC_R_UNEXPECTED);
} }
result = sigwait(&sset, &sig); if (sigwait(&sset, &sig) == 0) {
if (result == 0) { switch (sig) {
if (sig == SIGINT || sig == SIGTERM) case SIGINT:
ctx->want_shutdown = true; case SIGTERM:
else if (sig == SIGHUP) atomic_store_release(
ctx->want_reload = true; &ctx->want_shutdown, true);
break;
case SIGHUP:
atomic_store_release(
&ctx->want_reload, true);
break;
default:
INSIST(0);
ISC_UNREACHABLE();
}
} }
} else { } else {
/* /*
* External, or BIND9 using multiple contexts: * External, or BIND9 using multiple contexts:
* wait until woken up. * wait until woken up.
*/ */
LOCK(&ctx->readylock); if (atomic_load_acquire(&ctx->want_shutdown)) {
if (ctx->want_shutdown) {
/* shutdown() won the race. */
UNLOCK(&ctx->readylock);
break; break;
} }
if (!ctx->want_reload) if (!atomic_load_acquire(&ctx->want_reload)) {
LOCK(&ctx->readylock);
WAIT(&ctx->ready, &ctx->readylock); WAIT(&ctx->ready, &ctx->readylock);
UNLOCK(&ctx->readylock); UNLOCK(&ctx->readylock);
} }
#else /* Don't have sigwait(). */ }
if (isc_bind9) {
/*
* BIND9 internal; single context:
* Install a signal handler for SIGHUP, then wait for
* all signals.
*/
result = handle_signal(SIGHUP, reload_action);
if (result != ISC_R_SUCCESS)
return (ISC_R_SUCCESS);
if (sigemptyset(&sset) != 0) { exp_true = true;
strerror_r(errno, strbuf, sizeof(strbuf)); if (atomic_compare_exchange_weak_acq_rel(&ctx->want_reload,
UNEXPECTED_ERROR(__FILE__, __LINE__, &exp_true,
"isc_app_run() sigsetops: %s", false))
strbuf); {
return (ISC_R_UNEXPECTED);
}
#ifdef HAVE_GPERFTOOLS_PROFILER
if (sigaddset(&sset, SIGALRM) != 0) {
strerror_r(errno, strbuf, sizeof(strbuf));
UNEXPECTED_ERROR(__FILE__, __LINE__,
"isc_app_run() sigsetops: %s",
strbuf);
return (ISC_R_UNEXPECTED);
}
#endif
(void)sigsuspend(&sset);
} else {
/*
* External, or BIND9 using multiple contexts:
* wait until woken up.
*/
LOCK(&ctx->readylock);
if (ctx->want_shutdown) {
/* shutdown() won the race. */
UNLOCK(&ctx->readylock);
break;
}
if (!ctx->want_reload)
WAIT(&ctx->ready, &ctx->readylock);
UNLOCK(&ctx->readylock);
}
#endif /* HAVE_SIGWAIT */
if (ctx->want_reload) {
ctx->want_reload = false;
return (ISC_R_RELOAD); return (ISC_R_RELOAD);
} }
if (ctx->want_shutdown && ctx->blocked) if (atomic_load_acquire(&ctx->want_shutdown) &&
atomic_load_acquire(&ctx->blocked)) {
exit(1); exit(1);
} }
}
return (ISC_R_SUCCESS); return (ISC_R_SUCCESS);
} }
@@ -436,139 +310,113 @@ isc_app_ctxrun(isc_appctx_t *ctx0) {
isc_result_t isc_result_t
isc_app_run(void) { isc_app_run(void) {
isc_result_t result; isc_result_t result;
bool exp_false = false;
is_running = true; REQUIRE(atomic_compare_exchange_weak_acq_rel(
result = isc_app_ctxrun((isc_appctx_t *)&isc_g_appctx); &is_running, &exp_false, true) == true);
is_running = false; result = isc_app_ctxrun(&isc_g_appctx);
atomic_store_release(&is_running, false);
return (result); return (result);
} }
bool bool
isc_app_isrunning() { isc_app_isrunning() {
return (is_running); return (atomic_load_acquire(&is_running));
} }
isc_result_t void
isc_app_ctxshutdown(isc_appctx_t *ctx0) { isc_app_ctxshutdown(isc_appctx_t *ctx) {
isc__appctx_t *ctx = (isc__appctx_t *)ctx0; bool exp_false = false;
bool want_kill = true;
char strbuf[ISC_STRERRORSIZE];
REQUIRE(VALID_APPCTX(ctx)); REQUIRE(VALID_APPCTX(ctx));
LOCK(&ctx->lock); REQUIRE(atomic_load_acquire(&ctx->running));
REQUIRE(ctx->running); /* If ctx->shutdown_requested == true, we are already shutting
* down and we want to just bail out.
if (ctx->shutdown_requested) */
want_kill = false; if (atomic_compare_exchange_weak_acq_rel(
else &ctx->shutdown_requested,
ctx->shutdown_requested = true; &exp_false,
true))
UNLOCK(&ctx->lock); {
if (isc_bind9 && ctx != &isc_g_appctx) {
if (want_kill) {
if (isc_bind9 && ctx != &isc_g_appctx)
/* BIND9 internal, but using multiple contexts */ /* BIND9 internal, but using multiple contexts */
ctx->want_shutdown = true; atomic_store_release(&ctx->want_shutdown, true);
else { } else if (isc_bind9) {
if (isc_bind9) {
/* BIND9 internal, single context */ /* BIND9 internal, single context */
if (kill(getpid(), SIGTERM) < 0) { if (kill(getpid(), SIGTERM) < 0) {
char strbuf[ISC_STRERRORSIZE];
strerror_r(errno, strerror_r(errno,
strbuf, sizeof(strbuf)); strbuf, sizeof(strbuf));
UNEXPECTED_ERROR(__FILE__, __LINE__, isc_error_fatal(__FILE__, __LINE__,
"isc_app_shutdown() " "isc_app_shutdown() "
"kill: %s", strbuf); "kill: %s", strbuf);
return (ISC_R_UNEXPECTED);
} }
} } else {
else {
/* External, multiple contexts */ /* External, multiple contexts */
LOCK(&ctx->readylock); atomic_store_release(&ctx->want_shutdown, true);
ctx->want_shutdown = true;
UNLOCK(&ctx->readylock);
SIGNAL(&ctx->ready); SIGNAL(&ctx->ready);
} }
} }
} }
return (ISC_R_SUCCESS); void
}
isc_result_t
isc_app_shutdown(void) { isc_app_shutdown(void) {
return (isc_app_ctxshutdown((isc_appctx_t *)&isc_g_appctx)); isc_app_ctxshutdown(&isc_g_appctx);
} }
isc_result_t void
isc_app_ctxsuspend(isc_appctx_t *ctx0) { isc_app_ctxsuspend(isc_appctx_t *ctx) {
isc__appctx_t *ctx = (isc__appctx_t *)ctx0;
bool want_kill = true;
char strbuf[ISC_STRERRORSIZE];
REQUIRE(VALID_APPCTX(ctx)); REQUIRE(VALID_APPCTX(ctx));
LOCK(&ctx->lock); REQUIRE(atomic_load(&ctx->running));
REQUIRE(ctx->running);
/* /*
* Don't send the reload signal if we're shutting down. * Don't send the reload signal if we're shutting down.
*/ */
if (ctx->shutdown_requested) if (atomic_load_acquire(&ctx->shutdown_requested) == false) {
want_kill = false; if (isc_bind9 && ctx != &isc_g_appctx) {
UNLOCK(&ctx->lock);
if (want_kill) {
if (isc_bind9 && ctx != &isc_g_appctx)
/* BIND9 internal, but using multiple contexts */ /* BIND9 internal, but using multiple contexts */
ctx->want_reload = true; atomic_store_release(&ctx->want_reload, true);
else { } else if (isc_bind9) {
ctx->want_reload = true;
if (isc_bind9) {
/* BIND9 internal, single context */ /* BIND9 internal, single context */
if (kill(getpid(), SIGHUP) < 0) { if (kill(getpid(), SIGHUP) < 0) {
char strbuf[ISC_STRERRORSIZE];
strerror_r(errno, strerror_r(errno,
strbuf, sizeof(strbuf)); strbuf, sizeof(strbuf));
UNEXPECTED_ERROR(__FILE__, __LINE__, isc_error_fatal(__FILE__, __LINE__,
"isc_app_reload() " "isc_app_reload() "
"kill: %s", strbuf); "kill: %s", strbuf);
return (ISC_R_UNEXPECTED);
} }
} } else {
else {
/* External, multiple contexts */ /* External, multiple contexts */
LOCK(&ctx->readylock); atomic_store_release(&ctx->want_reload, true);
ctx->want_reload = true;
UNLOCK(&ctx->readylock);
SIGNAL(&ctx->ready); SIGNAL(&ctx->ready);
} }
}
}
return (ISC_R_SUCCESS);
} }
isc_result_t
isc_app_reload(void) {
return (isc_app_ctxsuspend((isc_appctx_t *)&isc_g_appctx));
} }
void void
isc_app_ctxfinish(isc_appctx_t *ctx0) { isc_app_reload(void) {
isc__appctx_t *ctx = (isc__appctx_t *)ctx0; return (isc_app_ctxsuspend(&isc_g_appctx));
}
void
isc_app_ctxfinish(isc_appctx_t *ctx) {
REQUIRE(VALID_APPCTX(ctx)); REQUIRE(VALID_APPCTX(ctx));
isc_mutex_destroy(&ctx->lock); isc_mutex_destroy(&ctx->lock);
isc_mutex_destroy(&ctx->readylock);
isc_condition_destroy(&ctx->ready);
} }
void void
isc_app_finish(void) { isc_app_finish(void) {
isc_app_ctxfinish((isc_appctx_t *)&isc_g_appctx); isc_app_ctxfinish(&isc_g_appctx);
} }
void void
@@ -577,7 +425,7 @@ isc_app_block(void) {
REQUIRE(isc_g_appctx.running); REQUIRE(isc_g_appctx.running);
REQUIRE(!isc_g_appctx.blocked); REQUIRE(!isc_g_appctx.blocked);
isc_g_appctx.blocked = true; atomic_store_release(&isc_g_appctx.blocked, true);
blockedthread = pthread_self(); blockedthread = pthread_self();
RUNTIME_CHECK(sigemptyset(&sset) == 0 && RUNTIME_CHECK(sigemptyset(&sset) == 0 &&
sigaddset(&sset, SIGINT) == 0 && sigaddset(&sset, SIGINT) == 0 &&
@@ -588,11 +436,13 @@ isc_app_block(void) {
void void
isc_app_unblock(void) { isc_app_unblock(void) {
sigset_t sset; sigset_t sset;
bool exp_true = true;
REQUIRE(isc_g_appctx.running); REQUIRE(atomic_load_acquire(&isc_g_appctx.running));
REQUIRE(isc_g_appctx.blocked); REQUIRE(atomic_compare_exchange_weak_acq_rel(
&isc_g_appctx.blocked,
isc_g_appctx.blocked = false; &exp_true,
false));
REQUIRE(blockedthread == pthread_self()); REQUIRE(blockedthread == pthread_self());
@@ -604,7 +454,7 @@ isc_app_unblock(void) {
isc_result_t isc_result_t
isc_appctx_create(isc_mem_t *mctx, isc_appctx_t **ctxp) { isc_appctx_create(isc_mem_t *mctx, isc_appctx_t **ctxp) {
isc__appctx_t *ctx; isc_appctx_t *ctx;
REQUIRE(mctx != NULL); REQUIRE(mctx != NULL);
REQUIRE(ctxp != NULL && *ctxp == NULL); REQUIRE(ctxp != NULL && *ctxp == NULL);
@@ -613,57 +463,26 @@ isc_appctx_create(isc_mem_t *mctx, isc_appctx_t **ctxp) {
if (ctx == NULL) if (ctx == NULL)
return (ISC_R_NOMEMORY); return (ISC_R_NOMEMORY);
ctx->common.impmagic = APPCTX_MAGIC; ctx->magic = APPCTX_MAGIC;
ctx->common.magic = ISCAPI_APPCTX_MAGIC;
ctx->mctx = NULL; ctx->mctx = NULL;
isc_mem_attach(mctx, &ctx->mctx); isc_mem_attach(mctx, &ctx->mctx);
ctx->taskmgr = NULL; *ctxp = ctx;
ctx->socketmgr = NULL;
ctx->timermgr = NULL;
*ctxp = (isc_appctx_t *)ctx;
return (ISC_R_SUCCESS); return (ISC_R_SUCCESS);
} }
void void
isc_appctx_destroy(isc_appctx_t **ctxp) { isc_appctx_destroy(isc_appctx_t **ctxp) {
isc__appctx_t *ctx; isc_appctx_t *ctx;
REQUIRE(ctxp != NULL); REQUIRE(ctxp != NULL);
ctx = (isc__appctx_t *)*ctxp; ctx = *ctxp;
REQUIRE(VALID_APPCTX(ctx)); REQUIRE(VALID_APPCTX(ctx));
*ctxp = NULL;
ctx->magic = 0;
isc_mem_putanddetach(&ctx->mctx, ctx, sizeof(*ctx)); isc_mem_putanddetach(&ctx->mctx, ctx, sizeof(*ctx));
*ctxp = NULL;
}
void
isc_appctx_settaskmgr(isc_appctx_t *ctx0, isc_taskmgr_t *taskmgr) {
isc__appctx_t *ctx = (isc__appctx_t *)ctx0;
REQUIRE(VALID_APPCTX(ctx));
ctx->taskmgr = taskmgr;
}
void
isc_appctx_setsocketmgr(isc_appctx_t *ctx0, isc_socketmgr_t *socketmgr) {
isc__appctx_t *ctx = (isc__appctx_t *)ctx0;
REQUIRE(VALID_APPCTX(ctx));
ctx->socketmgr = socketmgr;
}
void
isc_appctx_settimermgr(isc_appctx_t *ctx0, isc_timermgr_t *timermgr) {
isc__appctx_t *ctx = (isc__appctx_t *)ctx0;
REQUIRE(VALID_APPCTX(ctx));
ctx->timermgr = timermgr;
} }

View File

@@ -5608,15 +5608,11 @@ isc_socketmgr_renderjson(isc_socketmgr_t *mgr0, json_object *stats) {
#endif /* HAVE_JSON */ #endif /* HAVE_JSON */
isc_result_t isc_result_t
isc_socketmgr_createinctx(isc_mem_t *mctx, isc_appctx_t *actx, isc_socketmgr_createinctx(isc_mem_t *mctx, isc_socketmgr_t **managerp)
isc_socketmgr_t **managerp)
{ {
isc_result_t result; isc_result_t result;
result = isc_socketmgr_create(mctx, managerp); result = isc_socketmgr_create(mctx, managerp);
if (result == ISC_R_SUCCESS)
isc_appctx_setsocketmgr(actx, *managerp);
return (result); return (result);
} }

View File

@@ -50,7 +50,7 @@ enum {
SHUTDOWN_EVENT SHUTDOWN_EVENT
}; };
typedef struct isc__appctx { struct isc_appctx {
isc_appctx_t common; isc_appctx_t common;
isc_mem_t *mctx; isc_mem_t *mctx;
isc_eventlist_t on_run; isc_eventlist_t on_run;
@@ -69,13 +69,9 @@ typedef struct isc__appctx {
bool blocked; bool blocked;
HANDLE hEvents[NUM_EVENTS]; HANDLE hEvents[NUM_EVENTS];
};
isc_taskmgr_t *taskmgr; static isc_appctx_t isc_g_appctx;
isc_socketmgr_t *socketmgr;
isc_timermgr_t *timermgr;
} isc__appctx_t;
static isc__appctx_t isc_g_appctx;
/* /*
* We need to remember which thread is the main thread... * We need to remember which thread is the main thread...
@@ -83,8 +79,7 @@ static isc__appctx_t isc_g_appctx;
static isc_thread_t main_thread; static isc_thread_t main_thread;
isc_result_t isc_result_t
isc_app_ctxstart(isc_appctx_t *ctx0) { isc_app_ctxstart(isc_appctx_t *ctx) {
isc__appctx_t *ctx = (isc__appctx_t *)ctx0;
isc_result_t result; isc_result_t result;
REQUIRE(VALID_APPCTX(ctx)); REQUIRE(VALID_APPCTX(ctx));
@@ -115,27 +110,24 @@ isc_app_ctxstart(isc_appctx_t *ctx0) {
isc_result_t isc_result_t
isc_app_start(void) { isc_app_start(void) {
isc_g_appctx.common.impmagic = APPCTX_MAGIC; isc_g_appctx.magic = APPCTX_MAGIC;
isc_g_appctx.common.magic = ISCAPI_APPCTX_MAGIC;
isc_g_appctx.mctx = NULL; isc_g_appctx.mctx = NULL;
/* The remaining members will be initialized in ctxstart() */ /* The remaining members will be initialized in ctxstart() */
return (isc_app_ctxstart((isc_appctx_t *)&isc_g_appctx)); return (isc_app_ctxstart(&isc_g_appctx));
} }
isc_result_t isc_result_t
isc_app_onrun(isc_mem_t *mctx, isc_task_t *task, isc_taskaction_t action, isc_app_onrun(isc_mem_t *mctx, isc_task_t *task, isc_taskaction_t action,
void *arg) void *arg)
{ {
return (isc_app_ctxonrun((isc_appctx_t *)&isc_g_appctx, mctx, return (isc_app_ctxonrun(&isc_g_appctx, mctx, task, action, arg));
task, action, arg));
} }
isc_result_t isc_result_t
isc_app_ctxonrun(isc_appctx_t *ctx0, isc_mem_t *mctx, isc_task_t *task, isc_app_ctxonrun(isc_appctx_t *ctx, isc_mem_t *mctx, isc_task_t *task,
isc_taskaction_t action, void *arg) isc_taskaction_t action, void *arg)
{ {
isc__appctx_t *ctx = (isc__appctx_t *)ctx0;
isc_event_t *event; isc_event_t *event;
isc_task_t *cloned_task = NULL; isc_task_t *cloned_task = NULL;
isc_result_t result; isc_result_t result;
@@ -171,8 +163,7 @@ isc_app_ctxonrun(isc_appctx_t *ctx0, isc_mem_t *mctx, isc_task_t *task,
} }
isc_result_t isc_result_t
isc_app_ctxrun(isc_appctx_t *ctx0) { isc_app_ctxrun(isc_appctx_t *ctx) {
isc__appctx_t *ctx = (isc__appctx_t *)ctx0;
isc_event_t *event, *next_event; isc_event_t *event, *next_event;
isc_task_t *task; isc_task_t *task;
HANDLE *pHandles = NULL; HANDLE *pHandles = NULL;
@@ -248,7 +239,7 @@ isc_app_run(void) {
isc_result_t result; isc_result_t result;
is_running = true; is_running = true;
result = isc_app_ctxrun((isc_appctx_t *)&isc_g_appctx); result = isc_app_ctxrun(&isc_g_appctx);
is_running = false; is_running = false;
return (result); return (result);
@@ -260,8 +251,7 @@ isc_app_isrunning() {
} }
isc_result_t isc_result_t
isc_app_ctxshutdown(isc_appctx_t *ctx0) { isc_app_ctxshutdown(isc_appctx_t *ctx) {
isc__appctx_t *ctx = (isc__appctx_t *)ctx0;
bool want_kill = true; bool want_kill = true;
REQUIRE(VALID_APPCTX(ctx)); REQUIRE(VALID_APPCTX(ctx));
@@ -285,12 +275,11 @@ isc_app_ctxshutdown(isc_appctx_t *ctx0) {
isc_result_t isc_result_t
isc_app_shutdown(void) { isc_app_shutdown(void) {
return (isc_app_ctxshutdown((isc_appctx_t *)&isc_g_appctx)); return (isc_app_ctxshutdown(&isc_g_appctx));
} }
isc_result_t isc_result_t
isc_app_ctxsuspend(isc_appctx_t *ctx0) { isc_app_ctxsuspend(isc_appctx_t *ctx) {
isc__appctx_t *ctx = (isc__appctx_t *)ctx0;
bool want_kill = true; bool want_kill = true;
REQUIRE(VALID_APPCTX(ctx)); REQUIRE(VALID_APPCTX(ctx));
@@ -315,13 +304,11 @@ isc_app_ctxsuspend(isc_appctx_t *ctx0) {
isc_result_t isc_result_t
isc_app_reload(void) { isc_app_reload(void) {
return (isc_app_ctxsuspend((isc_appctx_t *)&isc_g_appctx)); return (isc_app_ctxsuspend(&isc_g_appctx));
} }
void void
isc_app_ctxfinish(isc_appctx_t *ctx0) { isc_app_ctxfinish(isc_appctx_t *ctx) {
isc__appctx_t *ctx = (isc__appctx_t *)ctx0;
REQUIRE(VALID_APPCTX(ctx)); REQUIRE(VALID_APPCTX(ctx));
isc_mutex_destroy(&ctx->lock); isc_mutex_destroy(&ctx->lock);
@@ -329,7 +316,7 @@ isc_app_ctxfinish(isc_appctx_t *ctx0) {
void void
isc_app_finish(void) { isc_app_finish(void) {
isc_app_ctxfinish((isc_appctx_t *)&isc_g_appctx); isc_app_ctxfinish(&isc_g_appctx);
} }
void void
@@ -352,33 +339,26 @@ isc_app_unblock(void) {
isc_result_t isc_result_t
isc_appctx_create(isc_mem_t *mctx, isc_appctx_t **ctxp) { isc_appctx_create(isc_mem_t *mctx, isc_appctx_t **ctxp) {
isc__appctx_t *ctx; isc_appctx_t *ctx;
REQUIRE(mctx != NULL); REQUIRE(mctx != NULL);
REQUIRE(ctxp != NULL && *ctxp == NULL); REQUIRE(ctxp != NULL && *ctxp == NULL);
ctx = isc_mem_get(mctx, sizeof(*ctx)); ctx = isc_mem_get(mctx, sizeof(*ctx));
if (ctx == NULL)
return (ISC_R_NOMEMORY);
ctx->common.impmagic = APPCTX_MAGIC; ctx->magic = APPCTX_MAGIC;
ctx->common.magic = ISCAPI_APPCTX_MAGIC;
ctx->mctx = NULL; ctx->mctx = NULL;
isc_mem_attach(mctx, &ctx->mctx); isc_mem_attach(mctx, &ctx->mctx);
ctx->taskmgr = NULL; *ctxp = ctx;
ctx->socketmgr = NULL;
ctx->timermgr = NULL;
*ctxp = (isc_appctx_t *)ctx;
return (ISC_R_SUCCESS); return (ISC_R_SUCCESS);
} }
void void
isc_appctx_destroy(isc_appctx_t **ctxp) { isc_appctx_destroy(isc_appctx_t **ctxp) {
isc__appctx_t *ctx; isc_appctx_t *ctx;
REQUIRE(ctxp != NULL); REQUIRE(ctxp != NULL);
ctx = (isc__appctx_t *)*ctxp; ctx = (isc__appctx_t *)*ctxp;
@@ -388,30 +368,3 @@ isc_appctx_destroy(isc_appctx_t **ctxp) {
*ctxp = NULL; *ctxp = NULL;
} }
void
isc_appctx_settaskmgr(isc_appctx_t *ctx0, isc_taskmgr_t *taskmgr) {
isc__appctx_t *ctx = (isc__appctx_t *)ctx0;
REQUIRE(VALID_APPCTX(ctx));
ctx->taskmgr = taskmgr;
}
void
isc_appctx_setsocketmgr(isc_appctx_t *ctx0, isc_socketmgr_t *socketmgr) {
isc__appctx_t *ctx = (isc__appctx_t *)ctx0;
REQUIRE(VALID_APPCTX(ctx));
ctx->socketmgr = socketmgr;
}
void
isc_appctx_settimermgr(isc_appctx_t *ctx0, isc_timermgr_t *timermgr) {
isc__appctx_t *ctx = (isc__appctx_t *)ctx0;
REQUIRE(VALID_APPCTX(ctx));
ctx->timermgr = timermgr;
}

View File

@@ -24,9 +24,6 @@ isc_app_start
isc_app_unblock isc_app_unblock
isc_appctx_create isc_appctx_create
isc_appctx_destroy isc_appctx_destroy
isc_appctx_setsocketmgr
isc_appctx_settaskmgr
isc_appctx_settimermgr
isc__buffer_activeregion isc__buffer_activeregion
isc__buffer_add isc__buffer_add
isc__buffer_availableregion isc__buffer_availableregion

View File

@@ -3872,16 +3872,12 @@ isc_socketmgr_renderjson(isc_socketmgr_t *mgr, json_object *stats) {
#endif /* HAVE_JSON */ #endif /* HAVE_JSON */
isc_result_t isc_result_t
isc_socketmgr_createinctx(isc_mem_t *mctx, isc_appctx_t *actx, isc_socketmgr_createinctx(isc_mem_t *mctx, isc_socketmgr_t **managerp)
isc_socketmgr_t **managerp)
{ {
isc_result_t result; isc_result_t result;
result = isc_socketmgr_create(mctx, managerp); result = isc_socketmgr_create(mctx, managerp);
if (result == ISC_R_SUCCESS)
isc_appctx_setsocketmgr(actx, *managerp);
return (result); return (result);
} }

View File

@@ -223,15 +223,15 @@ ctxs_init(isc_mem_t **mctxp, isc_appctx_t **actxp,
if (result != ISC_R_SUCCESS) if (result != ISC_R_SUCCESS)
goto fail; goto fail;
result = isc_taskmgr_createinctx(*mctxp, *actxp, 1, 0, taskmgrp); result = isc_taskmgr_createinctx(*mctxp, 1, 0, taskmgrp);
if (result != ISC_R_SUCCESS) if (result != ISC_R_SUCCESS)
goto fail; goto fail;
result = isc_socketmgr_createinctx(*mctxp, *actxp, socketmgrp); result = isc_socketmgr_createinctx(*mctxp, socketmgrp);
if (result != ISC_R_SUCCESS) if (result != ISC_R_SUCCESS)
goto fail; goto fail;
result = isc_timermgr_createinctx(*mctxp, *actxp, timermgrp); result = isc_timermgr_createinctx(*mctxp, timermgrp);
if (result != ISC_R_SUCCESS) if (result != ISC_R_SUCCESS)
goto fail; goto fail;

View File

@@ -379,13 +379,13 @@ main(int argc, char *argv[]) {
result = isc_app_ctxstart(actx); result = isc_app_ctxstart(actx);
if (result != ISC_R_SUCCESS) if (result != ISC_R_SUCCESS)
goto cleanup; goto cleanup;
result = isc_taskmgr_createinctx(mctx, actx, 1, 0, &taskmgr); result = isc_taskmgr_createinctx(mctx, 1, 0, &taskmgr);
if (result != ISC_R_SUCCESS) if (result != ISC_R_SUCCESS)
goto cleanup; goto cleanup;
result = isc_socketmgr_createinctx(mctx, actx, &socketmgr); result = isc_socketmgr_createinctx(mctx, &socketmgr);
if (result != ISC_R_SUCCESS) if (result != ISC_R_SUCCESS)
goto cleanup; goto cleanup;
result = isc_timermgr_createinctx(mctx, actx, &timermgr); result = isc_timermgr_createinctx(mctx, &timermgr);
if (result != ISC_R_SUCCESS) if (result != ISC_R_SUCCESS)
goto cleanup; goto cleanup;

View File

@@ -105,15 +105,15 @@ ctxs_init(isc_mem_t **mctxp, isc_appctx_t **actxp,
if (result != ISC_R_SUCCESS) if (result != ISC_R_SUCCESS)
goto fail; goto fail;
result = isc_taskmgr_createinctx(*mctxp, *actxp, 1, 0, taskmgrp); result = isc_taskmgr_createinctx(*mctxp, 1, 0, taskmgrp);
if (result != ISC_R_SUCCESS) if (result != ISC_R_SUCCESS)
goto fail; goto fail;
result = isc_socketmgr_createinctx(*mctxp, *actxp, socketmgrp); result = isc_socketmgr_createinctx(*mctxp, socketmgrp);
if (result != ISC_R_SUCCESS) if (result != ISC_R_SUCCESS)
goto fail; goto fail;
result = isc_timermgr_createinctx(*mctxp, *actxp, timermgrp); result = isc_timermgr_createinctx(*mctxp, timermgrp);
if (result != ISC_R_SUCCESS) if (result != ISC_R_SUCCESS)
goto fail; goto fail;