dns_rdataset_t *rdataset;
dns_namelist_t namelist;
unsigned int resopt;
- isc_appctx_t *actx = NULL;
isc_nm_t *netmgr = NULL;
isc_taskmgr_t *taskmgr = NULL;
isc_timermgr_t *timermgr = NULL;
dns_master_style_t *style = NULL;
- struct sigaction sa;
progname = argv[0];
preparse_args(argc, argv);
fatal("dst_lib_init failed: %d", result);
}
- CHECK(isc_appctx_create(mctx, &actx));
-
isc_managers_create(mctx, 1, 0, &netmgr, &taskmgr, &timermgr);
parse_args(argc, argv);
setup_logging(stderr);
- CHECK(isc_app_ctxstart(actx));
-
- /* Unblock SIGINT if it's been blocked by isc_app_ctxstart() */
- memset(&sa, 0, sizeof(sa));
- sa.sa_handler = SIG_DFL;
- if (sigfillset(&sa.sa_mask) != 0 || sigaction(SIGINT, &sa, NULL) < 0) {
- fatal("Couldn't set up signal handler");
- }
-
/* Create client */
- result = dns_client_create(mctx, actx, taskmgr, netmgr, timermgr, 0,
- &client, srcaddr4, srcaddr6);
+ result = dns_client_create(mctx, taskmgr, netmgr, timermgr, 0, &client,
+ srcaddr4, srcaddr6);
if (result != ISC_R_SUCCESS) {
delv_log(ISC_LOG_ERROR, "dns_client_create: %s",
isc_result_totext(result));
isc_managers_destroy(&netmgr, &taskmgr, &timermgr);
- if (actx != NULL) {
- isc_appctx_destroy(&actx);
- }
if (lctx != NULL) {
isc_log_destroy(&lctx);
}
*/
isc_mem_t *ctxs_mctx = NULL;
-isc_appctx_t *ctxs_actx = NULL;
isc_nm_t *ctxs_netmgr = NULL;
isc_taskmgr_t *ctxs_taskmgr = NULL;
isc_timermgr_t *ctxs_timermgr = NULL;
ctxs_destroy(void) {
isc_managers_destroy(&ctxs_netmgr, &ctxs_taskmgr, &ctxs_timermgr);
- if (ctxs_actx != NULL) {
- isc_appctx_destroy(&ctxs_actx);
- }
-
- if (ctxs_mctx != NULL) {
- isc_mem_destroy(&ctxs_mctx);
- }
+ isc_mem_destroy(&ctxs_mctx);
}
-static isc_result_t
+static void
ctxs_init(void) {
- isc_result_t result;
-
isc_mem_create(&ctxs_mctx);
- result = isc_appctx_create(ctxs_mctx, &ctxs_actx);
- if (result != ISC_R_SUCCESS) {
- goto fail;
- }
-
isc_managers_create(ctxs_mctx, 1, 0, &ctxs_netmgr, &ctxs_taskmgr,
&ctxs_timermgr);
-
- result = isc_app_ctxstart(ctxs_actx);
- if (result != ISC_R_SUCCESS) {
- goto fail;
- }
-
- return (ISC_R_SUCCESS);
-
-fail:
- ctxs_destroy();
-
- return (result);
}
static char *algname = NULL;
altserveraddr = cp + 1;
}
- result = ctxs_init();
- if (result != ISC_R_SUCCESS) {
- goto cleanup;
- }
+ ctxs_init();
result = dst_lib_init(ctxs_mctx, NULL);
if (result != ISC_R_SUCCESS) {
}
clientopt = 0;
- result = dns_client_create(ctxs_mctx, ctxs_actx, ctxs_taskmgr,
- ctxs_netmgr, ctxs_timermgr, clientopt,
- &client, addr4, addr6);
+ result = dns_client_create(ctxs_mctx, ctxs_taskmgr, ctxs_netmgr,
+ ctxs_timermgr, clientopt, &client, addr4,
+ addr6);
if (result != ISC_R_SUCCESS) {
fprintf(stderr, "dns_client_create failed: %u, %s\n", result,
isc_result_totext(result));
dns_client_freeresanswer(client, &namelist);
/* Cleanup */
-cleanup:
- if (client != NULL) {
- dns_client_detach(&client);
- }
+ dns_client_detach(&client);
ctxs_destroy();
dst_lib_destroy();
unsigned int attributes;
isc_mutex_t lock;
isc_mem_t *mctx;
- isc_appctx_t *actx;
+ bool readydone;
+ isc_mutex_t readylock;
+ isc_condition_t ready;
isc_taskmgr_t *taskmgr;
isc_task_t *task;
isc_nm_t *nm;
}
isc_result_t
-dns_client_create(isc_mem_t *mctx, isc_appctx_t *actx, isc_taskmgr_t *taskmgr,
- isc_nm_t *nm, isc_timermgr_t *timermgr, unsigned int options,
+dns_client_create(isc_mem_t *mctx, isc_taskmgr_t *taskmgr, isc_nm_t *nm,
+ isc_timermgr_t *timermgr, unsigned int options,
dns_client_t **clientp, const isc_sockaddr_t *localaddr4,
const isc_sockaddr_t *localaddr6) {
isc_result_t result;
client = isc_mem_get(mctx, sizeof(*client));
*client = (dns_client_t){
- .actx = actx, .taskmgr = taskmgr, .timermgr = timermgr, .nm = nm
+ .taskmgr = taskmgr,
+ .timermgr = timermgr,
+ .nm = nm,
};
isc_mutex_init(&client->lock);
+ isc_mutex_init(&client->readylock);
+ isc_condition_init(&client->ready);
+
result = isc_task_create(client->taskmgr, 0, &client->task);
if (result != ISC_R_SUCCESS) {
goto cleanup_lock;
isc_task_detach(&client->task);
+ isc_condition_destroy(&client->ready);
+ isc_mutex_destroy(&client->readylock);
+
isc_mutex_destroy(&client->lock);
client->magic = 0;
UNLOCK(&rctx->lock);
}
-static void
-suspend(isc_task_t *task, isc_event_t *event) {
- isc_appctx_t *actx = event->ev_arg;
-
- UNUSED(task);
-
- isc_app_ctxsuspend(actx);
- isc_event_free(&event);
-}
-
static void
resolve_done(isc_task_t *task, isc_event_t *event) {
resarg_t *resarg = event->ev_arg;
dns_clientresevent_t *rev = (dns_clientresevent_t *)event;
dns_name_t *name = NULL;
dns_client_t *client = resarg->client;
- isc_result_t result;
UNUSED(task);
UNLOCK(&resarg->lock);
/*
- * We may or may not be running. isc__appctx_onrun will
- * fail if we are currently running otherwise we post a
- * action to call isc_app_ctxsuspend when we do start
- * running.
+ * Signal that the entire process is done.
*/
- result = isc_app_ctxonrun(resarg->actx, client->mctx, task,
- suspend, resarg->actx);
- if (result == ISC_R_ALREADYRUNNING) {
- isc_app_ctxsuspend(resarg->actx);
- }
+ LOCK(&client->readylock);
+ client->readydone = true;
+ SIGNAL(&client->ready);
+ UNLOCK(&client->readylock);
} else {
/*
* We have already exited from the loop (due to some
resarg_t *resarg = NULL;
REQUIRE(DNS_CLIENT_VALID(client));
- REQUIRE(client->actx != NULL);
REQUIRE(namelist != NULL && ISC_LIST_EMPTY(*namelist));
resarg = isc_mem_get(client->mctx, sizeof(*resarg));
*resarg = (resarg_t){
- .actx = client->actx,
.client = client,
.result = DNS_R_SERVFAIL,
.namelist = namelist,
}
/*
- * Start internal event loop. It blocks until the entire process
- * is completed.
+ * Block until the entire process is completed.
*/
- result = isc_app_ctxrun(client->actx);
+ LOCK(&client->readylock);
+ if (!client->readydone) {
+ WAIT(&client->ready, &client->readylock);
+ }
+ UNLOCK(&client->readylock);
LOCK(&resarg->lock);
if (result == ISC_R_SUCCESS || result == ISC_R_SUSPEND) {
} dns_clientresevent_t; /* too long? */
isc_result_t
-dns_client_create(isc_mem_t *mctx, isc_appctx_t *actx, isc_taskmgr_t *taskmgr,
- isc_nm_t *nm, isc_timermgr_t *timermgr, unsigned int options,
+dns_client_create(isc_mem_t *mctx, isc_taskmgr_t *taskmgr, isc_nm_t *nm,
+ isc_timermgr_t *timermgr, unsigned int options,
dns_client_t **clientp, const isc_sockaddr_t *localaddr4,
const isc_sockaddr_t *localaddr6);
/*%<
*
*\li 'mctx' is a valid memory context.
*
- *\li 'actx' is a valid application context.
- *
*\li 'taskmgr' is a valid task manager.
*
*\li 'nm' is a valid network manager.