Compare commits

...
36 changed files with 820 additions and 3393 deletions
-1
View File
@@ -1578,7 +1578,6 @@ main(int argc, char *argv[]) {
argc--;
argv++;
isc_lib_register();
result = dns_lib_init();
if (result != ISC_R_SUCCESS)
fatal("dns_lib_init failed: %d", result);
+1 -1
View File
@@ -836,7 +836,7 @@ create_managers(void) {
isc_result_totext(result));
return (ISC_R_UNEXPECTED);
}
isc__socketmgr_maxudp(named_g_socketmgr, maxudp);
isc_socketmgr_maxudp(named_g_socketmgr, maxudp);
result = isc_socketmgr_getmaxsockets(named_g_socketmgr, &socks);
if (result == ISC_R_SUCCESS) {
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
+1 -1
View File
@@ -7890,7 +7890,7 @@ load_configuration(const char *filename, named_server_t *server,
"less than 128 UDP sockets available after "
"applying 'reserved-sockets' and 'maxsockets'");
}
isc__socketmgr_setreserved(named_g_socketmgr, reserved);
isc_socketmgr_setreserved(named_g_socketmgr, reserved);
#ifdef HAVE_GEOIP
/*
+2 -5
View File
@@ -76,11 +76,8 @@ dyndb_init(isc_mem_t *mctx, const char *name, const char *parameters,
* access to named's global namespace, in which case we need
* to initialize libisc/libdns
*/
if (dctx->refvar != &isc_bind9) {
isc_lib_register();
isc_log_setcontext(dctx->lctx);
dns_log_setcontext(dctx->lctx);
}
isc_log_setcontext(dctx->lctx);
dns_log_setcontext(dctx->lctx);
isc_hash_set_initializer(dctx->hashinit);
-1
View File
@@ -433,7 +433,6 @@ dns_dyndb_createctx(isc_mem_t *mctx, const void *hashinit, isc_log_t *lctx,
dctx->timermgr = tmgr;
dctx->hashinit = hashinit;
dctx->lctx = lctx;
dctx->refvar = &isc_bind9;
isc_mem_attach(mctx, &dctx->mctx);
dctx->magic = DNS_DYNDBCTX_MAGIC;
+7 -6
View File
@@ -102,19 +102,20 @@ mem_alloc(size_t size FLARG) {
void *ptr;
INSIST(dst__memory_pool != NULL);
ptr = isc__mem_allocate(dst__memory_pool, size FLARG_PASS);
ptr = _isc_mem_allocate(dst__memory_pool, size FLARG_PASS);
return (ptr);
#else
INSIST(dst__memory_pool != NULL);
return (isc__mem_allocate(dst__memory_pool, size FLARG_PASS));
return (_isc_mem_allocate(dst__memory_pool, size FLARG_PASS));
#endif
}
static void
mem_free(void *ptr FLARG) {
INSIST(dst__memory_pool != NULL);
if (ptr != NULL)
isc__mem_free(dst__memory_pool, ptr FLARG_PASS);
if (ptr != NULL) {
_isc_mem_free(dst__memory_pool, ptr FLARG_PASS);
}
}
static void *
@@ -123,11 +124,11 @@ mem_realloc(void *ptr, size_t size FLARG) {
void *rptr;
INSIST(dst__memory_pool != NULL);
rptr = isc__mem_reallocate(dst__memory_pool, ptr, size FLARG_PASS);
rptr = _isc_mem_reallocate(dst__memory_pool, ptr, size FLARG_PASS);
return (rptr);
#else
INSIST(dst__memory_pool != NULL);
return (isc__mem_reallocate(dst__memory_pool, ptr, size FLARG_PASS));
return (_isc_mem_reallocate(dst__memory_pool, ptr, size FLARG_PASS));
#endif
}
+10 -13
View File
@@ -119,15 +119,13 @@ dns_view_create(isc_mem_t *mctx, dns_rdataclass_t rdclass,
goto cleanup_name;
view->zonetable = NULL;
if (isc_bind9) {
result = dns_zt_create(mctx, rdclass, &view->zonetable);
if (result != ISC_R_SUCCESS) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
"dns_zt_create() failed: %s",
isc_result_totext(result));
result = ISC_R_UNEXPECTED;
goto cleanup_mutex;
}
result = dns_zt_create(mctx, rdclass, &view->zonetable);
if (result != ISC_R_SUCCESS) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
"dns_zt_create() failed: %s",
isc_result_totext(result));
result = ISC_R_UNEXPECTED;
goto cleanup_mutex;
}
view->secroots_priv = NULL;
view->ntatable_priv = NULL;
@@ -262,10 +260,9 @@ dns_view_create(isc_mem_t *mctx, dns_rdataclass_t rdclass,
if (result != ISC_R_SUCCESS)
goto cleanup_dynkeys;
if (isc_bind9) {
result = dns_order_create(view->mctx, &view->order);
if (result != ISC_R_SUCCESS)
goto cleanup_new_zone_lock;
result = dns_order_create(view->mctx, &view->order);
if (result != ISC_R_SUCCESS) {
goto cleanup_new_zone_lock;
}
result = dns_peerlist_new(view->mctx, &view->peers);
-1
View File
@@ -218,7 +218,6 @@ irs_context_create(irs_context_t **contextp) {
irs_dnsconf_dnskeylist_t *trustedkeys;
irs_dnsconf_dnskey_t *trustedkey;
isc_lib_register();
result = dns_lib_init();
if (result != ISC_R_SUCCESS)
return (result);
+2 -2
View File
@@ -50,7 +50,7 @@ WIN32OBJS = win32/condition.@O@ win32/dir.@O@ win32/errno.@O@ \
# Alphabetically
OBJS = @ISC_EXTRA_OBJS@ @ISC_PK11_O@ @ISC_PK11_RESULT_O@ \
aes.@O@ assertions.@O@ backtrace.@O@ base32.@O@ base64.@O@ \
bind9.@O@ buffer.@O@ bufferlist.@O@ \
buffer.@O@ bufferlist.@O@ \
commandline.@O@ counter.@O@ crc64.@O@ error.@O@ entropy.@O@ \
event.@O@ hash.@O@ ht.@O@ heap.@O@ hex.@O@ hmacmd5.@O@ \
hmacsha.@O@ httpd.@O@ iterated_hash.@O@ \
@@ -68,7 +68,7 @@ SYMTBLOBJS = backtrace-emptytbl.@O@
# Alphabetically
SRCS = @ISC_EXTRA_SRCS@ @ISC_PK11_C@ @ISC_PK11_RESULT_C@ \
aes.c assertions.c backtrace.c base32.c base64.c bind9.c \
aes.c assertions.c backtrace.c base32.c base64.c \
buffer.c bufferlist.c commandline.c counter.c crc64.c \
entropy.c error.c event.c hash.c ht.c heap.c hex.c hmacmd5.c \
hmacsha.c httpd.c iterated_hash.c \
-252
View File
@@ -1,252 +0,0 @@
/*
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* See the COPYRIGHT file distributed with this work for additional
* information regarding copyright ownership.
*/
#include <config.h>
#include <unistd.h>
#include <isc/app.h>
#include <isc/magic.h>
#include <isc/mutex.h>
#include <isc/once.h>
#include <isc/util.h>
static isc_mutex_t createlock;
static isc_once_t once = ISC_ONCE_INIT;
static isc_appctxcreatefunc_t appctx_createfunc = NULL;
static isc_boolean_t is_running = ISC_FALSE;
#define ISCAPI_APPMETHODS_VALID(m) ISC_MAGIC_VALID(m, ISCAPI_APPMETHODS_MAGIC)
static void
initialize(void) {
RUNTIME_CHECK(isc_mutex_init(&createlock) == ISC_R_SUCCESS);
}
isc_result_t
isc_app_register(isc_appctxcreatefunc_t createfunc) {
isc_result_t result = ISC_R_SUCCESS;
RUNTIME_CHECK(isc_once_do(&once, initialize) == ISC_R_SUCCESS);
LOCK(&createlock);
if (appctx_createfunc == NULL)
appctx_createfunc = createfunc;
else
result = ISC_R_EXISTS;
UNLOCK(&createlock);
return (result);
}
isc_result_t
isc_appctx_create(isc_mem_t *mctx, isc_appctx_t **ctxp) {
isc_result_t result;
if (isc_bind9)
return (isc__appctx_create(mctx, ctxp));
LOCK(&createlock);
REQUIRE(appctx_createfunc != NULL);
result = (*appctx_createfunc)(mctx, ctxp);
UNLOCK(&createlock);
return (result);
}
void
isc_appctx_destroy(isc_appctx_t **ctxp) {
REQUIRE(ctxp != NULL && ISCAPI_APPCTX_VALID(*ctxp));
if (isc_bind9)
isc__appctx_destroy(ctxp);
else
(*ctxp)->methods->ctxdestroy(ctxp);
ENSURE(*ctxp == NULL);
}
isc_result_t
isc_app_ctxstart(isc_appctx_t *ctx) {
REQUIRE(ISCAPI_APPCTX_VALID(ctx));
if (isc_bind9)
return (isc__app_ctxstart(ctx));
return (ctx->methods->ctxstart(ctx));
}
isc_result_t
isc_app_ctxrun(isc_appctx_t *ctx) {
REQUIRE(ISCAPI_APPCTX_VALID(ctx));
if (isc_bind9)
return (isc__app_ctxrun(ctx));
return (ctx->methods->ctxrun(ctx));
}
isc_result_t
isc_app_ctxonrun(isc_appctx_t *ctx, isc_mem_t *mctx,
isc_task_t *task, isc_taskaction_t action,
void *arg)
{
REQUIRE(ISCAPI_APPCTX_VALID(ctx));
if (isc_bind9)
return (isc__app_ctxonrun(ctx, mctx, task, action, arg));
return (ctx->methods->ctxonrun(ctx, mctx, task, action, arg));
}
isc_result_t
isc_app_ctxsuspend(isc_appctx_t *ctx) {
REQUIRE(ISCAPI_APPCTX_VALID(ctx));
if (isc_bind9)
return (isc__app_ctxsuspend(ctx));
return (ctx->methods->ctxsuspend(ctx));
}
isc_result_t
isc_app_ctxshutdown(isc_appctx_t *ctx) {
REQUIRE(ISCAPI_APPCTX_VALID(ctx));
if (isc_bind9)
return (isc__app_ctxshutdown(ctx));
return (ctx->methods->ctxshutdown(ctx));
}
void
isc_app_ctxfinish(isc_appctx_t *ctx) {
REQUIRE(ISCAPI_APPCTX_VALID(ctx));
if (isc_bind9)
isc__app_ctxfinish(ctx);
ctx->methods->ctxfinish(ctx);
}
void
isc_appctx_settaskmgr(isc_appctx_t *ctx, isc_taskmgr_t *taskmgr) {
REQUIRE(ISCAPI_APPCTX_VALID(ctx));
REQUIRE(taskmgr != NULL);
if (isc_bind9)
isc__appctx_settaskmgr(ctx, taskmgr);
ctx->methods->settaskmgr(ctx, taskmgr);
}
void
isc_appctx_setsocketmgr(isc_appctx_t *ctx, isc_socketmgr_t *socketmgr) {
REQUIRE(ISCAPI_APPCTX_VALID(ctx));
REQUIRE(socketmgr != NULL);
if (isc_bind9)
isc__appctx_setsocketmgr(ctx, socketmgr);
ctx->methods->setsocketmgr(ctx, socketmgr);
}
void
isc_appctx_settimermgr(isc_appctx_t *ctx, isc_timermgr_t *timermgr) {
REQUIRE(ISCAPI_APPCTX_VALID(ctx));
REQUIRE(timermgr != NULL);
if (isc_bind9)
isc__appctx_settimermgr(ctx, timermgr);
ctx->methods->settimermgr(ctx, timermgr);
}
isc_result_t
isc_app_start(void) {
if (isc_bind9)
return (isc__app_start());
return (ISC_R_NOTIMPLEMENTED);
}
isc_result_t
isc_app_onrun(isc_mem_t *mctx, isc_task_t *task,
isc_taskaction_t action, void *arg)
{
if (isc_bind9)
return (isc__app_onrun(mctx, task, action, arg));
return (ISC_R_NOTIMPLEMENTED);
}
isc_result_t
isc_app_run() {
if (isc_bind9) {
isc_result_t result;
is_running = ISC_TRUE;
result = isc__app_run();
is_running = ISC_FALSE;
return (result);
}
return (ISC_R_NOTIMPLEMENTED);
}
isc_boolean_t
isc_app_isrunning() {
return (is_running);
}
isc_result_t
isc_app_shutdown(void) {
if (isc_bind9)
return (isc__app_shutdown());
return (ISC_R_NOTIMPLEMENTED);
}
isc_result_t
isc_app_reload(void) {
if (isc_bind9)
return (isc__app_reload());
return (ISC_R_NOTIMPLEMENTED);
}
void
isc_app_finish(void) {
if (!isc_bind9)
return;
isc__app_finish();
}
void
isc_app_block(void) {
if (!isc_bind9)
return;
isc__app_block();
}
void
isc_app_unblock(void) {
if (!isc_bind9)
return;
isc__app_unblock();
}
-25
View File
@@ -1,25 +0,0 @@
/*
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* See the COPYRIGHT file distributed with this work for additional
* information regarding copyright ownership.
*/
/*! \file */
#include <config.h>
#include <isc/bind9.h>
/*
* This determines whether we are using the libisc/libdns libraries
* in BIND9 or in some other application. It is initialized to ISC_TRUE
* and remains unchanged for BIND9 and related tools; export library
* clients will run isc_lib_register(), which sets it to ISC_FALSE,
* overriding certain BIND9 behaviors.
*/
LIBISC_EXTERNAL_DATA isc_boolean_t isc_bind9 = ISC_TRUE;
+5 -52
View File
@@ -92,29 +92,6 @@ typedef isc_event_t isc_appevent_t;
#define ISC_APPEVENT_SHUTDOWN (ISC_EVENTCLASS_APP + 1)
#define ISC_APPEVENT_LASTEVENT (ISC_EVENTCLASS_APP + 65535)
/*%
* app module methods. Only app driver implementations use this structure.
* Other clients should use the top-level interfaces (i.e., isc_app_xxx
* functions). magic must be ISCAPI_APPMETHODS_MAGIC.
*/
typedef struct isc_appmethods {
void (*ctxdestroy)(isc_appctx_t **ctxp);
isc_result_t (*ctxstart)(isc_appctx_t *ctx);
isc_result_t (*ctxrun)(isc_appctx_t *ctx);
isc_result_t (*ctxsuspend)(isc_appctx_t *ctx);
isc_result_t (*ctxshutdown)(isc_appctx_t *ctx);
void (*ctxfinish)(isc_appctx_t *ctx);
void (*settaskmgr)(isc_appctx_t *ctx,
isc_taskmgr_t *timermgr);
void (*setsocketmgr)(isc_appctx_t *ctx,
isc_socketmgr_t *timermgr);
void (*settimermgr)(isc_appctx_t *ctx,
isc_timermgr_t *timermgr);
isc_result_t (*ctxonrun)(isc_appctx_t *ctx, isc_mem_t *mctx,
isc_task_t *task, isc_taskaction_t action,
void *arg);
} isc_appmethods_t;
/*%
* This structure is actually just the common prefix of an application context
* implementation's version of an isc_appctx_t.
@@ -124,18 +101,17 @@ typedef struct isc_appmethods {
* of the isc_app_ routines to work. app implementations must maintain
* all app context invariants.
*/
struct isc_appctx {
unsigned int impmagic;
unsigned int magic;
isc_appmethods_t *methods;
};
struct isc_appctx;
#define ISCAPI_APPCTX_MAGIC ISC_MAGIC('A','a','p','c')
#define ISCAPI_APPCTX_VALID(c) ((c) != NULL && \
(c)->magic == ISCAPI_APPCTX_MAGIC)
isc_appctx_magic(c) == ISCAPI_APPCTX_MAGIC)
ISC_LANG_BEGINDECLS
unsigned int
isc_appctx_magic(isc_appctx_t *ctx);
isc_result_t
isc_app_ctxstart(isc_appctx_t *ctx);
@@ -355,29 +331,6 @@ isc_appctx_settimermgr(isc_appctx_t *ctx, isc_timermgr_t *timermgr);
*\li 'timermgr' is a valid timer manager.
*/
/*%<
* See isc_appctx_create() above.
*/
typedef isc_result_t
(*isc_appctxcreatefunc_t)(isc_mem_t *mctx, isc_appctx_t **ctxp);
isc_result_t
isc_app_register(isc_appctxcreatefunc_t createfunc);
/*%<
* Register a new application implementation and add it to the list of
* supported implementations. This function must be called when a different
* event library is used than the one contained in the ISC library.
*/
isc_result_t
isc__app_register(void);
/*%<
* A short cut function that specifies the application module in the ISC
* library for isc_app_register(). An application that uses the ISC library
* usually do not have to care about this function: it would call
* isc_lib_register(), which internally calls this function.
*/
ISC_LANG_ENDDECLS
#endif /* ISC_APP_H */
-27
View File
@@ -1,27 +0,0 @@
/*
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* See the COPYRIGHT file distributed with this work for additional
* information regarding copyright ownership.
*/
#ifndef ISC_BIND9_H
#define ISC_BIND9_H 1
#include <isc/boolean.h>
#include <isc/platform.h>
/*
* This determines whether we are using the libisc/libdns libraries
* in BIND9 or in some other application. For BIND9 (named and related
* tools) it must be set to ISC_TRUE at runtime. Export library clients
* will call isc_lib_register(), which will set it to ISC_FALSE.
*/
LIBISC_EXTERNAL_DATA extern isc_boolean_t isc_bind9;
#endif /* ISC_BIND9_H */
-9
View File
@@ -29,15 +29,6 @@ isc_lib_initmsgcat(void);
* has not already been initialized.
*/
void
isc_lib_register(void);
/*!<
* \brief Register the ISC library implementations for some base services
* such as memory or event management and handling socket or timer events.
* An external application that wants to use the ISC library must call this
* function very early in main().
*/
ISC_LANG_ENDDECLS
#endif /* ISC_LIB_H */
+21 -118
View File
@@ -136,21 +136,6 @@ LIBISC_EXTERNAL_DATA extern unsigned int isc_mem_defaultflags;
#define ISC_MEMFLAG_DEFAULT ISC_MEMFLAG_INTERNAL|ISC_MEMFLAG_FILL
#endif
/*%<
* We use either isc___mem (three underscores) or isc__mem (two) depending on
* whether it's for BIND9's internal purpose (with -DBIND9) or generic export
* library.
*/
#define ISCMEMFUNC(sfx) isc__mem_ ## sfx
#define ISCMEMPOOLFUNC(sfx) isc__mempool_ ## sfx
#define isc_mem_get(c, s) ISCMEMFUNC(get)((c), (s) _ISC_MEM_FILELINE)
#define isc_mem_allocate(c, s) ISCMEMFUNC(allocate)((c), (s) _ISC_MEM_FILELINE)
#define isc_mem_reallocate(c, p, s) ISCMEMFUNC(reallocate)((c), (p), (s) _ISC_MEM_FILELINE)
#define isc_mem_strdup(c, p) ISCMEMFUNC(strdup)((c), (p) _ISC_MEM_FILELINE)
#define isc_mempool_get(c) ISCMEMPOOLFUNC(get)((c) _ISC_MEM_FILELINE)
/*%
* isc_mem_putanddetach() is a convenience function for use where you
* have a structure with an attached memory context.
@@ -180,44 +165,6 @@ LIBISC_EXTERNAL_DATA extern unsigned int isc_mem_defaultflags;
* \endcode
*/
/*% memory and memory pool methods */
typedef struct isc_memmethods {
void (*attach)(isc_mem_t *source, isc_mem_t **targetp);
void (*detach)(isc_mem_t **mctxp);
void (*destroy)(isc_mem_t **mctxp);
void *(*memget)(isc_mem_t *mctx, size_t size _ISC_MEM_FLARG);
void (*memput)(isc_mem_t *mctx, void *ptr, size_t size _ISC_MEM_FLARG);
void (*memputanddetach)(isc_mem_t **mctxp, void *ptr,
size_t size _ISC_MEM_FLARG);
void *(*memallocate)(isc_mem_t *mctx, size_t size _ISC_MEM_FLARG);
void *(*memreallocate)(isc_mem_t *mctx, void *ptr,
size_t size _ISC_MEM_FLARG);
char *(*memstrdup)(isc_mem_t *mctx, const char *s _ISC_MEM_FLARG);
void (*memfree)(isc_mem_t *mctx, void *ptr _ISC_MEM_FLARG);
void (*setdestroycheck)(isc_mem_t *mctx, isc_boolean_t flag);
void (*setwater)(isc_mem_t *ctx, isc_mem_water_t water,
void *water_arg, size_t hiwater, size_t lowater);
void (*waterack)(isc_mem_t *ctx, int flag);
size_t (*inuse)(isc_mem_t *mctx);
size_t (*maxinuse)(isc_mem_t *mctx);
size_t (*total)(isc_mem_t *mctx);
isc_boolean_t (*isovermem)(isc_mem_t *mctx);
isc_result_t (*mpcreate)(isc_mem_t *mctx, size_t size,
isc_mempool_t **mpctxp);
} isc_memmethods_t;
typedef struct isc_mempoolmethods {
void (*destroy)(isc_mempool_t **mpctxp);
void *(*get)(isc_mempool_t *mpctx _ISC_MEM_FLARG);
void (*put)(isc_mempool_t *mpctx, void *mem _ISC_MEM_FLARG);
unsigned int (*getallocated)(isc_mempool_t *mpctx);
void (*setmaxalloc)(isc_mempool_t *mpctx, unsigned int limit);
void (*setfreemax)(isc_mempool_t *mpctx, unsigned int limit);
void (*setname)(isc_mempool_t *mpctx, const char *name);
void (*associatelock)(isc_mempool_t *mpctx, isc_mutex_t *lock);
void (*setfillcount)(isc_mempool_t *mpctx, unsigned int limit);
} isc_mempoolmethods_t;
/*%
* This structure is actually just the common prefix of a memory context
* implementation's version of an isc_mem_t.
@@ -227,11 +174,7 @@ typedef struct isc_mempoolmethods {
* isc_mem_ routines to work. mctx implementations must maintain all mctx
* invariants.
*/
struct isc_mem {
unsigned int impmagic;
unsigned int magic;
isc_memmethods_t *methods;
};
struct isc_mem;
#define ISCAPI_MCTX_MAGIC ISC_MAGIC('A','m','c','x')
#define ISCAPI_MCTX_VALID(m) ((m) != NULL && \
@@ -241,37 +184,12 @@ struct isc_mem {
* This is the common prefix of a memory pool context. The same note as
* that for the mem structure applies.
*/
struct isc_mempool {
unsigned int impmagic;
unsigned int magic;
isc_mempoolmethods_t *methods;
};
struct isc_mempool;
#define ISCAPI_MPOOL_MAGIC ISC_MAGIC('A','m','p','l')
#define ISCAPI_MPOOL_VALID(mp) ((mp) != NULL && \
(mp)->magic == ISCAPI_MPOOL_MAGIC)
#define isc_mem_put(c, p, s) \
do { \
ISCMEMFUNC(put)((c), (p), (s) _ISC_MEM_FILELINE); \
(p) = NULL; \
} while (0)
#define isc_mem_putanddetach(c, p, s) \
do { \
ISCMEMFUNC(putanddetach)((c), (p), (s) _ISC_MEM_FILELINE); \
(p) = NULL; \
} while (0)
#define isc_mem_free(c, p) \
do { \
ISCMEMFUNC(free)((c), (p) _ISC_MEM_FILELINE); \
(p) = NULL; \
} while (0)
#define isc_mempool_put(c, p) \
do { \
ISCMEMPOOLFUNC(put)((c), (p) _ISC_MEM_FILELINE); \
(p) = NULL; \
} while (0)
/*@{*/
isc_result_t
isc_mem_create(size_t max_size, size_t target_size,
@@ -682,51 +600,36 @@ isc_mempool_setfillcount(isc_mempool_t *mpctx, unsigned int limit);
/*
* Pseudo-private functions for use via macros. Do not call directly.
*/
#define isc_mem_get(...) _isc_mem_get(__VA_ARGS__ _ISC_MEM_FILELINE)
void *
ISCMEMFUNC(get)(isc_mem_t *, size_t _ISC_MEM_FLARG);
_isc_mem_get(isc_mem_t *mctx, size_t size _ISC_MEM_FLARG);
#define isc_mem_putanddetach(...) _isc_mem_putanddetach(__VA_ARGS__ _ISC_MEM_FILELINE)
void
ISCMEMFUNC(putanddetach)(isc_mem_t **, void *, size_t _ISC_MEM_FLARG);
_isc_mem_putanddetach(isc_mem_t **ctxp, void *ptr, size_t size _ISC_MEM_FLARG);
#define isc_mem_put(...) _isc_mem_put(__VA_ARGS__ _ISC_MEM_FILELINE)
void
ISCMEMFUNC(put)(isc_mem_t *, void *, size_t _ISC_MEM_FLARG);
_isc_mem_put(isc_mem_t *mctx, void *ptr, size_t size _ISC_MEM_FLARG);
#define isc_mem_allocate(...) _isc_mem_allocate(__VA_ARGS__ _ISC_MEM_FILELINE)
void *
ISCMEMFUNC(allocate)(isc_mem_t *, size_t _ISC_MEM_FLARG);
_isc_mem_allocate(isc_mem_t *mctx, size_t size _ISC_MEM_FLARG);
#define isc_mem_reallocate(...) _isc_mem_reallocate(__VA_ARGS__ _ISC_MEM_FILELINE)
void *
ISCMEMFUNC(reallocate)(isc_mem_t *, void *, size_t _ISC_MEM_FLARG);
_isc_mem_reallocate(isc_mem_t *mctx, void *ptr, size_t size _ISC_MEM_FLARG);
#define isc_mem_free(...) _isc_mem_free(__VA_ARGS__ _ISC_MEM_FILELINE)
void
ISCMEMFUNC(free)(isc_mem_t *, void * _ISC_MEM_FLARG);
_isc_mem_free(isc_mem_t *mctx, void *ptr _ISC_MEM_FLARG);
#define isc_mem_strdup(...) _isc_mem_strdup(__VA_ARGS__ _ISC_MEM_FILELINE)
char *
ISCMEMFUNC(strdup)(isc_mem_t *, const char *_ISC_MEM_FLARG);
_isc_mem_strdup(isc_mem_t *mctx, const char *s _ISC_MEM_FLARG);
#define isc_mempool_get(...) _isc_mempool_get(__VA_ARGS__ _ISC_MEM_FILELINE)
void *
ISCMEMPOOLFUNC(get)(isc_mempool_t * _ISC_MEM_FLARG);
_isc_mempool_get(isc_mempool_t *mpctx _ISC_MEM_FLARG);
#define isc_mempool_put(...) _isc_mempool_put(__VA_ARGS__ _ISC_MEM_FILELINE)
void
ISCMEMPOOLFUNC(put)(isc_mempool_t *, void * _ISC_MEM_FLARG);
/*%<
* See isc_mem_create2() above.
*/
typedef isc_result_t
(*isc_memcreatefunc_t)(size_t init_max_size, size_t target_size,
isc_mem_t **ctxp, unsigned int flags);
isc_result_t
isc_mem_register(isc_memcreatefunc_t createfunc);
/*%<
* Register a new memory management implementation and add it to the list of
* supported implementations. This function must be called when a different
* memory management library is used than the one contained in the ISC library.
*/
isc_result_t
isc__mem_register(void);
/*%<
* A short cut function that specifies the memory management module in the ISC
* library for isc_mem_register(). An application that uses the ISC library
* usually do not have to care about this function: it would call
* isc_lib_register(), which internally calls this function.
*/
_isc_mempool_put(isc_mempool_t *mpctx, void *mem _ISC_MEM_FLARG);
void
isc__mem_printactive(isc_mem_t *mctx, FILE *file);
isc_mem_printactive(isc_mem_t *mctx, FILE *file);
/*%<
* For internal use by the isc module and its unit tests, these functions
* print lists of active memory blocks for a single memory context or for
+12 -161
View File
@@ -59,55 +59,6 @@
#include <isc/types.h>
#include <isc/xml.h>
#ifdef WIN32
/* from the old namespace.h */
#define isc_socket_create isc__socket_create
#define isc_socket_dup isc__socket_dup
#define isc_socket_attach isc__socket_attach
#define isc_socket_detach isc__socket_detach
#define isc_socketmgr_create isc__socketmgr_create
#define isc_socketmgr_create2 isc__socketmgr_create2
#define isc_socketmgr_destroy isc__socketmgr_destroy
#define isc_socket_open isc__socket_open
#define isc_socket_close isc__socket_close
#define isc_socket_recvv isc__socket_recvv
#define isc_socket_recv isc__socket_recv
#define isc_socket_recv2 isc__socket_recv2
#define isc_socket_send isc__socket_send
#define isc_socket_sendto isc__socket_sendto
#define isc_socket_sendv isc__socket_sendv
#define isc_socket_sendtov isc__socket_sendtov
#define isc_socket_sendtov2 isc__socket_sendtov2
#define isc_socket_sendto2 isc__socket_sendto2
#define isc_socket_cleanunix isc__socket_cleanunix
#define isc_socket_permunix isc__socket_permunix
#define isc_socket_bind isc__socket_bind
#define isc_socket_filter isc__socket_filter
#define isc_socket_listen isc__socket_listen
#define isc_socket_accept isc__socket_accept
#define isc_socket_connect isc__socket_connect
#define isc_socket_getfd isc__socket_getfd
#define isc_socket_getname isc__socket_getname
#define isc_socket_gettag isc__socket_gettag
#define isc_socket_getpeername isc__socket_getpeername
#define isc_socket_getsockname isc__socket_getsockname
#define isc_socket_cancel isc__socket_cancel
#define isc_socket_gettype isc__socket_gettype
#define isc_socket_isbound isc__socket_isbound
#define isc_socket_ipv6only isc__socket_ipv6only
#define isc_socket_setname isc__socket_setname
#define isc_socketmgr_getmaxsockets isc__socketmgr_getmaxsockets
#define isc_socketmgr_setstats isc__socketmgr_setstats
#define isc_socketmgr_setreserved isc__socketmgr_setreserved
#define isc__socketmgr_maxudp isc___socketmgr_maxudp
#define isc_socket_fdwatchcreate isc__socket_fdwatchcreate
#define isc_socket_fdwatchpoke isc__socket_fdwatchpoke
#define isc_socket_dscp isc__socket_dscp
#endif
ISC_LANG_BEGINDECLS
/***
@@ -330,100 +281,23 @@ typedef enum {
#define ISC_SOCKFDWATCH_WRITE 0x00000002 /*%< watch for writable */
/*@}*/
/*% Socket and socket manager methods */
typedef struct isc_socketmgrmethods {
void (*destroy)(isc_socketmgr_t **managerp);
isc_result_t (*socketcreate)(isc_socketmgr_t *manager, int pf,
isc_sockettype_t type,
isc_socket_t **socketp);
isc_result_t (*fdwatchcreate)(isc_socketmgr_t *manager, int fd,
int flags,
isc_sockfdwatch_t callback,
void *cbarg, isc_task_t *task,
isc_socket_t **socketp);
} isc_socketmgrmethods_t;
typedef struct isc_socketmethods {
void (*attach)(isc_socket_t *socket,
isc_socket_t **socketp);
void (*detach)(isc_socket_t **socketp);
isc_result_t (*bind)(isc_socket_t *sock,
const isc_sockaddr_t *sockaddr,
unsigned int options);
isc_result_t (*sendto)(isc_socket_t *sock, isc_region_t *region,
isc_task_t *task, isc_taskaction_t action,
void *arg,
const isc_sockaddr_t *address,
struct in6_pktinfo *pktinfo);
isc_result_t (*sendto2)(isc_socket_t *sock, isc_region_t *region,
isc_task_t *task,
const isc_sockaddr_t *address,
struct in6_pktinfo *pktinfo,
isc_socketevent_t *event,
unsigned int flags);
isc_result_t (*connect)(isc_socket_t *sock,
const isc_sockaddr_t *addr,
isc_task_t *task, isc_taskaction_t action,
void *arg);
isc_result_t (*recv)(isc_socket_t *sock, isc_region_t *region,
unsigned int minimum, isc_task_t *task,
isc_taskaction_t action, void *arg);
isc_result_t (*recv2)(isc_socket_t *sock, isc_region_t *region,
unsigned int minimum, isc_task_t *task,
isc_socketevent_t *event, unsigned int flags);
void (*cancel)(isc_socket_t *sock, isc_task_t *task,
unsigned int how);
isc_result_t (*getsockname)(isc_socket_t *sock,
isc_sockaddr_t *addressp);
isc_sockettype_t (*gettype)(isc_socket_t *sock);
void (*ipv6only)(isc_socket_t *sock, isc_boolean_t yes);
isc_result_t (*fdwatchpoke)(isc_socket_t *sock, int flags);
isc_result_t (*dup)(isc_socket_t *socket,
isc_socket_t **socketp);
int (*getfd)(isc_socket_t *socket);
void (*dscp)(isc_socket_t *socket, isc_dscp_t dscp);
} isc_socketmethods_t;
/*%
* This structure is actually just the common prefix of a socket manager
* object implementation's version of an isc_socketmgr_t.
* \brief
* Direct use of this structure by clients is forbidden. socket implementations
* may change the structure. 'magic' must be ISCAPI_SOCKETMGR_MAGIC for any
* of the isc_socket_ routines to work. socket implementations must maintain
* all socket invariants.
* In effect, this definition is used only for non-BIND9 version ("export")
* of the library, and the export version does not work for win32. So, to avoid
* the definition conflict with win32/socket.c, we enable this definition only
* for non-Win32 (i.e. Unix) platforms.
*/
#ifndef WIN32
struct isc_socketmgr {
unsigned int impmagic;
unsigned int magic;
isc_socketmgrmethods_t *methods;
};
#endif
struct isc_socketmgr;
#define ISCAPI_SOCKETMGR_MAGIC ISC_MAGIC('A','s','m','g')
#define ISCAPI_SOCKETMGR_VALID(m) ((m) != NULL && \
(m)->magic == ISCAPI_SOCKETMGR_MAGIC)
isc_socketmgr_magic(m) == ISCAPI_SOCKETMGR_MAGIC)
/*%
* This is the common prefix of a socket object. The same note as
* that for the socketmgr structure applies.
*/
#ifndef WIN32
struct isc_socket {
unsigned int impmagic;
unsigned int magic;
isc_socketmethods_t *methods;
};
#endif
unsigned int
isc_socketmgr_magic(isc_socketmgr_t *manager);
struct isc_socket;
#define ISCAPI_SOCKET_MAGIC ISC_MAGIC('A','s','c','t')
#define ISCAPI_SOCKET_VALID(s) ((s) != NULL && \
(s)->magic == ISCAPI_SOCKET_MAGIC)
isc_socket_magic(s) == ISCAPI_SOCKET_MAGIC)
unsigned int
isc_socket_magic(isc_socket_t *sock);
/***
*** Socket and Socket Manager Functions
@@ -1228,13 +1102,13 @@ int isc_socket_getfd(isc_socket_t *socket);
*/
void
isc__socketmgr_setreserved(isc_socketmgr_t *mgr, isc_uint32_t);
isc_socketmgr_setreserved(isc_socketmgr_t *mgr, isc_uint32_t);
/*%<
* Temporary. For use by named only.
*/
void
isc__socketmgr_maxudp(isc_socketmgr_t *mgr, int maxudp);
isc_socketmgr_maxudp(isc_socketmgr_t *mgr, int maxudp);
/*%<
* Test interface. Drop UDP packet > 'maxudp'.
*/
@@ -1255,29 +1129,6 @@ isc_socketmgr_renderjson(isc_socketmgr_t *mgr, json_object *stats);
*/
#endif /* HAVE_JSON */
/*%<
* See isc_socketmgr_create() above.
*/
typedef isc_result_t
(*isc_socketmgrcreatefunc_t)(isc_mem_t *mctx, isc_socketmgr_t **managerp);
isc_result_t
isc_socket_register(isc_socketmgrcreatefunc_t createfunc);
/*%<
* Register a new socket I/O implementation and add it to the list of
* supported implementations. This function must be called when a different
* event library is used than the one contained in the ISC library.
*/
isc_result_t
isc__socket_register(void);
/*%<
* A short cut function that specifies the socket I/O module in the ISC
* library for isc_socket_register(). An application that uses the ISC library
* usually do not have to care about this function: it would call
* isc_lib_register(), which internally calls this function.
*/
ISC_LANG_ENDDECLS
#endif /* ISC_SOCKET_H */
+14 -25
View File
@@ -145,29 +145,27 @@ typedef struct isc_taskmethods {
* of the isc_task_ routines to work. task implementations must maintain
* all task invariants.
*/
struct isc_taskmgr {
unsigned int impmagic;
unsigned int magic;
isc_taskmgrmethods_t *methods;
};
struct isc_taskmgr;
#define ISCAPI_TASKMGR_MAGIC ISC_MAGIC('A','t','m','g')
#define ISCAPI_TASKMGR_VALID(m) ((m) != NULL && \
(m)->magic == ISCAPI_TASKMGR_MAGIC)
isc_taskmgr_magic(m) == ISCAPI_TASKMGR_MAGIC)
unsigned int
isc_taskmgr_magic(isc_taskmgr_t *manager);
/*%
* This is the common prefix of a task object. The same note as
* that for the taskmgr structure applies.
*/
struct isc_task {
unsigned int impmagic;
unsigned int magic;
isc_taskmethods_t *methods;
};
struct isc_task;
#define ISCAPI_TASK_MAGIC ISC_MAGIC('A','t','s','t')
#define ISCAPI_TASK_VALID(s) ((s) != NULL && \
(s)->magic == ISCAPI_TASK_MAGIC)
isc_task_magic(s) == ISCAPI_TASK_MAGIC)
unsigned int
isc_task_magic(isc_task_t *task);
isc_result_t
isc_task_create(isc_taskmgr_t *manager, unsigned int quantum,
@@ -811,31 +809,22 @@ isc_task_register(isc_taskmgrcreatefunc_t createfunc);
* event library is used than the one contained in the ISC library.
*/
isc_result_t
isc__task_register(void);
/*%<
* A short cut function that specifies the task management module in the ISC
* library for isc_task_register(). An application that uses the ISC library
* usually do not have to care about this function: it would call
* isc_lib_register(), which internally calls this function.
*/
/*%<
* These functions allow unit tests to manipulate the processing
* of the task queue. They are not intended as part of the public API.
*/
#if defined(ISC_PLATFORM_USETHREADS)
void
isc__taskmgr_pause(isc_taskmgr_t *taskmgr);
isc_taskmgr_pause(isc_taskmgr_t *taskmgr);
void
isc__taskmgr_resume(isc_taskmgr_t *taskmgr);
isc_taskmgr_resume(isc_taskmgr_t *taskmgr);
#else
isc_boolean_t
isc__taskmgr_ready(isc_taskmgr_t *taskmgr);
isc_taskmgr_ready(isc_taskmgr_t *taskmgr);
isc_result_t
isc__taskmgr_dispatch(isc_taskmgr_t *taskmgr);
isc_taskmgr_dispatch(isc_taskmgr_t *taskmgr);
#endif /* !ISC_PLATFORM_USETHREADS */
ISC_LANG_ENDDECLS
+2 -34
View File
@@ -129,12 +129,7 @@ typedef struct {
* of the isc_timer_ routines to work. timer implementations must maintain
* all timer invariants.
*/
struct isc_timermgr {
unsigned int impmagic;
unsigned int magic;
isc_timermgrmethods_t *methods;
};
struct isc_timermgr;
#define ISCAPI_TIMERMGR_MAGIC ISC_MAGIC('A','t','m','g')
#define ISCAPI_TIMERMGR_VALID(m) ((m) != NULL && \
(m)->magic == ISCAPI_TIMERMGR_MAGIC)
@@ -143,11 +138,7 @@ struct isc_timermgr {
* This is the common prefix of a timer object. The same note as
* that for the timermgr structure applies.
*/
struct isc_timer {
unsigned int impmagic;
unsigned int magic;
isc_timermethods_t *methods;
};
struct isc_timer;
#define ISCAPI_TIMER_MAGIC ISC_MAGIC('A','t','m','r')
#define ISCAPI_TIMER_VALID(s) ((s) != NULL && \
@@ -396,29 +387,6 @@ isc_timermgr_destroy(isc_timermgr_t **managerp);
void isc_timermgr_poke(isc_timermgr_t *m);
/*%<
* See isc_timermgr_create() above.
*/
typedef isc_result_t
(*isc_timermgrcreatefunc_t)(isc_mem_t *mctx, isc_timermgr_t **managerp);
isc_result_t
isc__timer_register(void);
/*%<
* Register a new timer management implementation and add it to the list of
* supported implementations. This function must be called when a different
* event library is used than the one contained in the ISC library.
*/
isc_result_t
isc_timer_register(isc_timermgrcreatefunc_t createfunc);
/*%<
* A short cut function that specifies the timer management module in the ISC
* library for isc_timer_register(). An application that uses the ISC library
* usually do not have to care about this function: it would call
* isc_lib_register(), which internally calls this function.
*/
ISC_LANG_ENDDECLS
#endif /* ISC_TIMER_H */
-2
View File
@@ -12,8 +12,6 @@
#ifndef ISC_TYPES_H
#define ISC_TYPES_H 1
#include <isc/bind9.h>
/*! \file isc/types.h
* \brief
* OS-specific types, from the OS-specific include directories.
-19
View File
@@ -76,22 +76,3 @@ isc_lib_initmsgcat(void) {
abort();
}
}
static isc_once_t register_once = ISC_ONCE_INIT;
static void
do_register(void) {
isc_bind9 = ISC_FALSE;
RUNTIME_CHECK(isc__mem_register() == ISC_R_SUCCESS);
RUNTIME_CHECK(isc__app_register() == ISC_R_SUCCESS);
RUNTIME_CHECK(isc__task_register() == ISC_R_SUCCESS);
RUNTIME_CHECK(isc__socket_register() == ISC_R_SUCCESS);
RUNTIME_CHECK(isc__timer_register() == ISC_R_SUCCESS);
}
void
isc_lib_register(void) {
RUNTIME_CHECK(isc_once_do(&register_once, do_register)
== ISC_R_SUCCESS);
}
+118 -644
View File
File diff suppressed because it is too large Load Diff
-397
View File
@@ -1,397 +0,0 @@
/*
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* See the COPYRIGHT file distributed with this work for additional
* information regarding copyright ownership.
*/
#include <config.h>
#include <isc/app.h>
#include <isc/magic.h>
#include <isc/mutex.h>
#include <isc/once.h>
#include <isc/socket.h>
#include <isc/util.h>
static isc_mutex_t createlock;
static isc_once_t once = ISC_ONCE_INIT;
static isc_socketmgrcreatefunc_t socketmgr_createfunc = NULL;
static void
initialize(void) {
RUNTIME_CHECK(isc_mutex_init(&createlock) == ISC_R_SUCCESS);
}
isc_result_t
isc_socket_register(isc_socketmgrcreatefunc_t createfunc) {
isc_result_t result = ISC_R_SUCCESS;
RUNTIME_CHECK(isc_once_do(&once, initialize) == ISC_R_SUCCESS);
LOCK(&createlock);
if (socketmgr_createfunc == NULL)
socketmgr_createfunc = createfunc;
else
result = ISC_R_EXISTS;
UNLOCK(&createlock);
return (result);
}
isc_result_t
isc_socketmgr_createinctx(isc_mem_t *mctx, isc_appctx_t *actx,
isc_socketmgr_t **managerp)
{
isc_result_t result;
LOCK(&createlock);
REQUIRE(socketmgr_createfunc != NULL);
result = (*socketmgr_createfunc)(mctx, managerp);
UNLOCK(&createlock);
if (result == ISC_R_SUCCESS)
isc_appctx_setsocketmgr(actx, *managerp);
return (result);
}
isc_result_t
isc_socketmgr_create(isc_mem_t *mctx, isc_socketmgr_t **managerp) {
isc_result_t result;
if (isc_bind9)
return (isc__socketmgr_create(mctx, managerp));
LOCK(&createlock);
REQUIRE(socketmgr_createfunc != NULL);
result = (*socketmgr_createfunc)(mctx, managerp);
UNLOCK(&createlock);
return (result);
}
void
isc_socketmgr_destroy(isc_socketmgr_t **managerp) {
REQUIRE(managerp != NULL && ISCAPI_SOCKETMGR_VALID(*managerp));
if (isc_bind9)
isc__socketmgr_destroy(managerp);
else
(*managerp)->methods->destroy(managerp);
ENSURE(*managerp == NULL);
}
isc_result_t
isc_socket_create(isc_socketmgr_t *manager, int pf, isc_sockettype_t type,
isc_socket_t **socketp)
{
REQUIRE(ISCAPI_SOCKETMGR_VALID(manager));
if (isc_bind9)
return (isc__socket_create(manager, pf, type, socketp));
return (manager->methods->socketcreate(manager, pf, type, socketp));
}
void
isc_socket_attach(isc_socket_t *sock, isc_socket_t **socketp) {
REQUIRE(ISCAPI_SOCKET_VALID(sock));
REQUIRE(socketp != NULL && *socketp == NULL);
if (isc_bind9)
isc__socket_attach(sock, socketp);
else
sock->methods->attach(sock, socketp);
ENSURE(*socketp == sock);
}
void
isc_socket_detach(isc_socket_t **socketp) {
REQUIRE(socketp != NULL && ISCAPI_SOCKET_VALID(*socketp));
if (isc_bind9)
isc__socket_detach(socketp);
else
(*socketp)->methods->detach(socketp);
ENSURE(*socketp == NULL);
}
isc_result_t
isc_socket_bind(isc_socket_t *sock, const isc_sockaddr_t *sockaddr,
unsigned int options)
{
REQUIRE(ISCAPI_SOCKET_VALID(sock));
if (isc_bind9)
return (isc__socket_bind(sock, sockaddr, options));
return (sock->methods->bind(sock, sockaddr, options));
}
isc_result_t
isc_socket_sendto(isc_socket_t *sock, isc_region_t *region, isc_task_t *task,
isc_taskaction_t action, void *arg,
const isc_sockaddr_t *address, struct in6_pktinfo *pktinfo)
{
REQUIRE(ISCAPI_SOCKET_VALID(sock));
if (isc_bind9)
return (isc__socket_sendto(sock, region, task,
action, arg, address, pktinfo));
return (sock->methods->sendto(sock, region, task, action, arg, address,
pktinfo));
}
isc_result_t
isc_socket_connect(isc_socket_t *sock, const isc_sockaddr_t *addr,
isc_task_t *task, isc_taskaction_t action, void *arg)
{
REQUIRE(ISCAPI_SOCKET_VALID(sock));
if (isc_bind9)
return (isc__socket_connect(sock, addr, task, action, arg));
return (sock->methods->connect(sock, addr, task, action, arg));
}
isc_result_t
isc_socket_recv(isc_socket_t *sock, isc_region_t *region, unsigned int minimum,
isc_task_t *task, isc_taskaction_t action, void *arg)
{
REQUIRE(ISCAPI_SOCKET_VALID(sock));
if (isc_bind9)
return (isc__socket_recv(sock, region, minimum,
task, action, arg));
return (sock->methods->recv(sock, region, minimum, task, action, arg));
}
void
isc_socket_cancel(isc_socket_t *sock, isc_task_t *task, unsigned int how) {
REQUIRE(ISCAPI_SOCKET_VALID(sock));
if (isc_bind9)
isc__socket_cancel(sock, task, how);
else
sock->methods->cancel(sock, task, how);
}
isc_result_t
isc_socket_getsockname(isc_socket_t *sock, isc_sockaddr_t *addressp) {
REQUIRE(ISCAPI_SOCKET_VALID(sock));
if (isc_bind9)
return (isc__socket_getsockname(sock, addressp));
return (sock->methods->getsockname(sock, addressp));
}
void
isc_socket_ipv6only(isc_socket_t *sock, isc_boolean_t yes) {
REQUIRE(ISCAPI_SOCKET_VALID(sock));
if (isc_bind9)
isc__socket_ipv6only(sock, yes);
else
sock->methods->ipv6only(sock, yes);
}
void
isc_socket_dscp(isc_socket_t *sock, isc_dscp_t dscp) {
REQUIRE(ISCAPI_SOCKET_VALID(sock));
sock->methods->dscp(sock, dscp);
}
isc_sockettype_t
isc_socket_gettype(isc_socket_t *sock) {
REQUIRE(ISCAPI_SOCKET_VALID(sock));
if (isc_bind9)
return (isc__socket_gettype(sock));
return (sock->methods->gettype(sock));
}
void
isc_socket_setname(isc_socket_t *sock, const char *name, void *tag) {
REQUIRE(ISCAPI_SOCKET_VALID(sock));
UNUSED(sock); /* in case REQUIRE() is empty */
UNUSED(name);
UNUSED(tag);
}
isc_result_t
isc_socket_fdwatchcreate(isc_socketmgr_t *manager, int fd, int flags,
isc_sockfdwatch_t callback, void *cbarg,
isc_task_t *task, isc_socket_t **socketp)
{
REQUIRE(ISCAPI_SOCKETMGR_VALID(manager));
if (isc_bind9)
return (isc__socket_fdwatchcreate(manager, fd, flags,
callback, cbarg,
task, socketp));
return (manager->methods->fdwatchcreate(manager, fd, flags,
callback, cbarg, task,
socketp));
}
isc_result_t
isc_socket_fdwatchpoke(isc_socket_t *sock, int flags)
{
REQUIRE(ISCAPI_SOCKET_VALID(sock));
if (isc_bind9)
return (isc__socket_fdwatchpoke(sock, flags));
return (sock->methods->fdwatchpoke(sock, flags));
}
isc_result_t
isc_socket_dup(isc_socket_t *sock, isc_socket_t **socketp) {
REQUIRE(ISCAPI_SOCKET_VALID(sock));
REQUIRE(socketp != NULL && *socketp == NULL);
if (isc_bind9)
return (isc__socket_dup(sock, socketp));
return (sock->methods->dup(sock, socketp));
}
int
isc_socket_getfd(isc_socket_t *sock) {
REQUIRE(ISCAPI_SOCKET_VALID(sock));
if (isc_bind9)
return (isc__socket_getfd(sock));
return (sock->methods->getfd(sock));
}
isc_result_t
isc_socket_open(isc_socket_t *sock) {
return (isc__socket_open(sock));
}
isc_result_t
isc_socket_close(isc_socket_t *sock) {
return (isc__socket_close(sock));
}
isc_result_t
isc_socketmgr_create2(isc_mem_t *mctx, isc_socketmgr_t **managerp,
unsigned int maxsocks)
{
return (isc__socketmgr_create2(mctx, managerp, maxsocks));
}
isc_result_t
isc_socket_recvv(isc_socket_t *sock, isc_bufferlist_t *buflist,
unsigned int minimum, isc_task_t *task,
isc_taskaction_t action, void *arg)
{
return (isc__socket_recvv(sock, buflist, minimum, task, action, arg));
}
isc_result_t
isc_socket_recv2(isc_socket_t *sock, isc_region_t *region,
unsigned int minimum, isc_task_t *task,
isc_socketevent_t *event, unsigned int flags)
{
return (isc__socket_recv2(sock, region, minimum, task, event, flags));
}
isc_result_t
isc_socket_send(isc_socket_t *sock, isc_region_t *region,
isc_task_t *task, isc_taskaction_t action, void *arg)
{
return (isc__socket_send(sock, region, task, action, arg));
}
isc_result_t
isc_socket_sendv(isc_socket_t *sock, isc_bufferlist_t *buflist,
isc_task_t *task, isc_taskaction_t action, void *arg)
{
return (isc__socket_sendv(sock, buflist, task, action, arg));
}
isc_result_t
isc_socket_sendtov(isc_socket_t *sock, isc_bufferlist_t *buflist,
isc_task_t *task, isc_taskaction_t action, void *arg,
const isc_sockaddr_t *address, struct in6_pktinfo *pktinfo)
{
return (isc__socket_sendtov(sock, buflist, task, action, arg,
address, pktinfo));
}
isc_result_t
isc_socket_sendtov2(isc_socket_t *sock, isc_bufferlist_t *buflist,
isc_task_t *task, isc_taskaction_t action, void *arg,
const isc_sockaddr_t *address, struct in6_pktinfo *pktinfo,
unsigned int flags)
{
return (isc__socket_sendtov2(sock, buflist, task, action, arg,
address, pktinfo, flags));
}
isc_result_t
isc_socket_sendto2(isc_socket_t *sock, isc_region_t *region,
isc_task_t *task,
const isc_sockaddr_t *address, struct in6_pktinfo *pktinfo,
isc_socketevent_t *event, unsigned int flags)
{
return (isc__socket_sendto2(sock, region, task, address, pktinfo,
event, flags));
}
void
isc_socket_cleanunix(const isc_sockaddr_t *sockaddr, isc_boolean_t active) {
isc__socket_cleanunix(sockaddr, active);
}
isc_result_t
isc_socket_permunix(const isc_sockaddr_t *sockaddr, isc_uint32_t perm,
isc_uint32_t owner, isc_uint32_t group)
{
return (isc__socket_permunix(sockaddr, perm, owner, group));
}
isc_result_t
isc_socket_filter(isc_socket_t *sock, const char *filter) {
return (isc__socket_filter(sock, filter));
}
isc_result_t
isc_socket_listen(isc_socket_t *sock, unsigned int backlog) {
return (isc__socket_listen(sock, backlog));
}
isc_result_t
isc_socket_accept(isc_socket_t *sock, isc_task_t *task,
isc_taskaction_t action, void *arg)
{
return (isc__socket_accept(sock, task, action, arg));
}
isc_result_t
isc_socket_getpeername(isc_socket_t *sock, isc_sockaddr_t *addressp) {
return (isc__socket_getpeername(sock, addressp));
}
+143 -561
View File
File diff suppressed because it is too large Load Diff
+3 -3
View File
@@ -273,7 +273,7 @@ ATF_TC_BODY(isc_mem_noflags, tc) {
isc_mem_debugging = 0;
ptr = isc_mem_get(mctx2, 2048);
ATF_CHECK(ptr != NULL);
isc__mem_printactive(mctx2, f);
isc_mem_printactive(mctx2, f);
isc_mem_put(mctx2, ptr, 2048);
isc_mem_destroy(&mctx2);
isc_stdio_close(f);
@@ -324,7 +324,7 @@ ATF_TC_BODY(isc_mem_recordflag, tc) {
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
ptr = isc_mem_get(mctx2, 2048);
ATF_CHECK(ptr != NULL);
isc__mem_printactive(mctx2, f);
isc_mem_printactive(mctx2, f);
isc_mem_put(mctx2, ptr, 2048);
isc_mem_destroy(&mctx2);
isc_stdio_close(f);
@@ -375,7 +375,7 @@ ATF_TC_BODY(isc_mem_traceflag, tc) {
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
ptr = isc_mem_get(mctx2, 2048);
ATF_CHECK(ptr != NULL);
isc__mem_printactive(mctx2, f);
isc_mem_printactive(mctx2, f);
isc_mem_put(mctx2, ptr, 2048);
isc_mem_destroy(&mctx2);
isc_stdio_close(f);
+10 -10
View File
@@ -140,8 +140,8 @@ ATF_TC_BODY(all_events, tc) {
while ((a == 0 || b == 0) && i++ < 5000) {
#ifndef ISC_PLATFORM_USETHREADS
while (isc__taskmgr_ready(taskmgr))
isc__taskmgr_dispatch(taskmgr);
while (isc_taskmgr_ready(taskmgr))
isc_taskmgr_dispatch(taskmgr);
#endif
isc_test_nap(1000);
}
@@ -181,7 +181,7 @@ ATF_TC_BODY(privileged_events, tc) {
* Pause the task manager so we can fill up the work queue
* without things happening while we do it.
*/
isc__taskmgr_pause(taskmgr);
isc_taskmgr_pause(taskmgr);
#endif
result = isc_task_create(taskmgr, 0, &task1);
@@ -241,14 +241,14 @@ ATF_TC_BODY(privileged_events, tc) {
ATF_CHECK_EQ(isc_taskmgr_mode(taskmgr), isc_taskmgrmode_privileged);
#ifdef ISC_PLATFORM_USETHREADS
isc__taskmgr_resume(taskmgr);
isc_taskmgr_resume(taskmgr);
#endif
/* We're waiting for *all* variables to be set */
while ((a == 0 || b == 0 || c == 0 || d == 0 || e == 0) && i++ < 5000) {
#ifndef ISC_PLATFORM_USETHREADS
while (isc__taskmgr_ready(taskmgr))
isc__taskmgr_dispatch(taskmgr);
while (isc_taskmgr_ready(taskmgr))
isc_taskmgr_dispatch(taskmgr);
#endif
isc_test_nap(1000);
}
@@ -310,7 +310,7 @@ ATF_TC_BODY(privilege_drop, tc) {
* Pause the task manager so we can fill up the work queue
* without things happening while we do it.
*/
isc__taskmgr_pause(taskmgr);
isc_taskmgr_pause(taskmgr);
#endif
result = isc_task_create(taskmgr, 0, &task1);
@@ -370,15 +370,15 @@ ATF_TC_BODY(privilege_drop, tc) {
ATF_CHECK_EQ(isc_taskmgr_mode(taskmgr), isc_taskmgrmode_privileged);
#ifdef ISC_PLATFORM_USETHREADS
isc__taskmgr_resume(taskmgr);
isc_taskmgr_resume(taskmgr);
#endif
/* We're waiting for all variables to be set. */
while ((a == -1 || b == -1 || c == -1 || d == -1 || e == -1) &&
i++ < 5000) {
#ifndef ISC_PLATFORM_USETHREADS
while (isc__taskmgr_ready(taskmgr))
isc__taskmgr_dispatch(taskmgr);
while (isc_taskmgr_ready(taskmgr))
isc_taskmgr_dispatch(taskmgr);
#endif
isc_test_nap(1000);
}
+100 -307
View File
@@ -34,16 +34,9 @@
#include <openssl/err.h>
#endif
/* See task.c about the following definition: */
#ifdef ISC_PLATFORM_USETHREADS
#define USE_TIMER_THREAD
#else
#define USE_SHARED_MANAGER
#endif /* ISC_PLATFORM_USETHREADS */
#ifndef USE_TIMER_THREAD
#ifndef ISC_PLATFORM_USETHREADS
#include "timer_p.h"
#endif /* USE_TIMER_THREAD */
#endif /* ISC_PLATFORM_USETHREADS */
#ifdef ISC_TIMER_TRACE
#define XTRACE(s) fprintf(stderr, "%s\n", (s))
@@ -65,13 +58,14 @@
#define TIMER_MAGIC ISC_MAGIC('T', 'I', 'M', 'R')
#define VALID_TIMER(t) ISC_MAGIC_VALID(t, TIMER_MAGIC)
typedef struct isc__timer isc__timer_t;
typedef struct isc__timermgr isc__timermgr_t;
typedef struct isc_timer isc_timer_t;
typedef struct isc_timermgr isc_timermgr_t;
struct isc__timer {
struct isc_timer {
unsigned int impmagic;
unsigned int magic;
/*! Not locked. */
isc_timer_t common;
isc__timermgr_t * manager;
isc_timermgr_t * manager;
isc_mutex_t lock;
/*! Locked by timer lock. */
unsigned int references;
@@ -85,104 +79,49 @@ struct isc__timer {
void * arg;
unsigned int index;
isc_time_t due;
LINK(isc__timer_t) link;
LINK(isc_timer_t) link;
};
#define TIMER_MANAGER_MAGIC ISC_MAGIC('T', 'I', 'M', 'M')
#define VALID_MANAGER(m) ISC_MAGIC_VALID(m, TIMER_MANAGER_MAGIC)
struct isc__timermgr {
struct isc_timermgr {
unsigned int impmagic;
unsigned int magic;
/* Not locked. */
isc_timermgr_t common;
isc_mem_t * mctx;
isc_mutex_t lock;
/* Locked by manager lock. */
isc_boolean_t done;
LIST(isc__timer_t) timers;
LIST(isc_timer_t) timers;
unsigned int nscheduled;
isc_time_t due;
#ifdef USE_TIMER_THREAD
#ifdef ISC_PLATFORM_USETHREADS
isc_condition_t wakeup;
isc_thread_t thread;
#endif /* USE_TIMER_THREAD */
#ifdef USE_SHARED_MANAGER
#else
unsigned int refs;
#endif /* USE_SHARED_MANAGER */
#endif /* !ISC_PLATFORM_USETHREADS */
isc_heap_t * heap;
};
/*%
* The following are intended for internal use (indicated by "isc__"
* prefix) but are not declared as static, allowing direct access from
* unit tests etc.
*/
isc_result_t
isc__timer_create(isc_timermgr_t *manager, isc_timertype_t type,
const isc_time_t *expires, const isc_interval_t *interval,
isc_task_t *task, isc_taskaction_t action, void *arg,
isc_timer_t **timerp);
isc_result_t
isc__timer_reset(isc_timer_t *timer, isc_timertype_t type,
const isc_time_t *expires, const isc_interval_t *interval,
isc_boolean_t purge);
isc_timertype_t
isc_timer_gettype(isc_timer_t *timer);
isc_result_t
isc__timer_touch(isc_timer_t *timer);
void
isc__timer_attach(isc_timer_t *timer0, isc_timer_t **timerp);
void
isc__timer_detach(isc_timer_t **timerp);
isc_result_t
isc__timermgr_create(isc_mem_t *mctx, isc_timermgr_t **managerp);
void
isc_timermgr_poke(isc_timermgr_t *manager0);
void
isc__timermgr_destroy(isc_timermgr_t **managerp);
static struct isc__timermethods {
isc_timermethods_t methods;
/*%
* The following are defined just for avoiding unused static functions.
*/
void *gettype;
} timermethods = {
{
isc__timer_attach,
isc__timer_detach,
isc__timer_reset,
isc__timer_touch
},
(void *)isc_timer_gettype
};
static struct isc__timermgrmethods {
isc_timermgrmethods_t methods;
void *poke; /* see above */
} timermgrmethods = {
{
isc__timermgr_destroy,
isc__timer_create
},
(void *)isc_timermgr_poke
};
#ifdef USE_SHARED_MANAGER
#ifndef ISC_PLATFORM_USETHREADS
/*!
* If the manager is supposed to be shared, there can be only one.
*/
static isc__timermgr_t *timermgr = NULL;
#endif /* USE_SHARED_MANAGER */
static isc_timermgr_t *timermgr = NULL;
#endif /* ISC_PLATFORM_USETHREADS */
static inline isc_result_t
schedule(isc__timer_t *timer, isc_time_t *now, isc_boolean_t signal_ok) {
schedule(isc_timer_t *timer, isc_time_t *now, isc_boolean_t signal_ok) {
isc_result_t result;
isc__timermgr_t *manager;
isc_timermgr_t *manager;
isc_time_t due;
int cmp;
#ifdef USE_TIMER_THREAD
#ifdef ISC_PLATFORM_USETHREADS
isc_boolean_t timedwait;
#endif
@@ -192,13 +131,13 @@ schedule(isc__timer_t *timer, isc_time_t *now, isc_boolean_t signal_ok) {
REQUIRE(timer->type != isc_timertype_inactive);
#ifndef USE_TIMER_THREAD
#ifndef ISC_PLATFORM_USETHREADS
UNUSED(signal_ok);
#endif /* USE_TIMER_THREAD */
#endif /* ISC_PLATFORM_USETHREADS */
manager = timer->manager;
#ifdef USE_TIMER_THREAD
#ifdef ISC_PLATFORM_USETHREADS
/*!
* If the manager was timed wait, we may need to signal the
* manager to force a wakeup.
@@ -268,7 +207,7 @@ schedule(isc__timer_t *timer, isc_time_t *now, isc_boolean_t signal_ok) {
* the current "next" timer. We do this either by waking up the
* run thread, or explicitly setting the value in the manager.
*/
#ifdef USE_TIMER_THREAD
#ifdef ISC_PLATFORM_USETHREADS
/*
* This is a temporary (probably) hack to fix a bug on tru64 5.1
@@ -301,21 +240,21 @@ schedule(isc__timer_t *timer, isc_time_t *now, isc_boolean_t signal_ok) {
"signal (schedule)"));
SIGNAL(&manager->wakeup);
}
#else /* USE_TIMER_THREAD */
#else /* ISC_PLATFORM_USETHREADS */
if (timer->index == 1 &&
isc_time_compare(&timer->due, &manager->due) < 0)
manager->due = timer->due;
#endif /* USE_TIMER_THREAD */
#endif /* ISC_PLATFORM_USETHREADS */
return (ISC_R_SUCCESS);
}
static inline void
deschedule(isc__timer_t *timer) {
#ifdef USE_TIMER_THREAD
deschedule(isc_timer_t *timer) {
#ifdef ISC_PLATFORM_USETHREADS
isc_boolean_t need_wakeup = ISC_FALSE;
#endif
isc__timermgr_t *manager;
isc_timermgr_t *manager;
/*
* The caller must ensure locking.
@@ -323,7 +262,7 @@ deschedule(isc__timer_t *timer) {
manager = timer->manager;
if (timer->index > 0) {
#ifdef USE_TIMER_THREAD
#ifdef ISC_PLATFORM_USETHREADS
if (timer->index == 1)
need_wakeup = ISC_TRUE;
#endif
@@ -331,20 +270,20 @@ deschedule(isc__timer_t *timer) {
timer->index = 0;
INSIST(manager->nscheduled > 0);
manager->nscheduled--;
#ifdef USE_TIMER_THREAD
#ifdef ISC_PLATFORM_USETHREADS
if (need_wakeup) {
XTRACE(isc_msgcat_get(isc_msgcat, ISC_MSGSET_TIMER,
ISC_MSG_SIGNALDESCHED,
"signal (deschedule)"));
SIGNAL(&manager->wakeup);
}
#endif /* USE_TIMER_THREAD */
#endif /* ISC_PLATFORM_USETHREADS */
}
}
static void
destroy(isc__timer_t *timer) {
isc__timermgr_t *manager = timer->manager;
destroy(isc_timer_t *timer) {
isc_timermgr_t *manager = timer->manager;
/*
* The caller must ensure it is safe to destroy the timer.
@@ -364,19 +303,18 @@ destroy(isc__timer_t *timer) {
isc_task_detach(&timer->task);
DESTROYLOCK(&timer->lock);
timer->common.impmagic = 0;
timer->common.magic = 0;
timer->impmagic = 0;
timer->magic = 0;
isc_mem_put(manager->mctx, timer, sizeof(*timer));
}
isc_result_t
isc__timer_create(isc_timermgr_t *manager0, isc_timertype_t type,
isc_timer_create(isc_timermgr_t *manager, isc_timertype_t type,
const isc_time_t *expires, const isc_interval_t *interval,
isc_task_t *task, isc_taskaction_t action, void *arg,
isc_timer_t **timerp)
{
isc__timermgr_t *manager = (isc__timermgr_t *)manager0;
isc__timer_t *timer;
isc_timer_t *timer;
isc_result_t result;
isc_time_t now;
@@ -457,9 +395,8 @@ isc__timer_create(isc_timermgr_t *manager0, isc_timertype_t type,
return (result);
}
ISC_LINK_INIT(timer, link);
timer->common.impmagic = TIMER_MAGIC;
timer->common.magic = ISCAPI_TIMER_MAGIC;
timer->common.methods = (isc_timermethods_t *)&timermethods;
timer->impmagic = TIMER_MAGIC;
timer->magic = ISCAPI_TIMER_MAGIC;
LOCK(&manager->lock);
@@ -478,8 +415,8 @@ isc__timer_create(isc_timermgr_t *manager0, isc_timertype_t type,
UNLOCK(&manager->lock);
if (result != ISC_R_SUCCESS) {
timer->common.impmagic = 0;
timer->common.magic = 0;
timer->impmagic = 0;
timer->magic = 0;
DESTROYLOCK(&timer->lock);
isc_task_detach(&timer->task);
isc_mem_put(manager->mctx, timer, sizeof(*timer));
@@ -492,13 +429,12 @@ isc__timer_create(isc_timermgr_t *manager0, isc_timertype_t type,
}
isc_result_t
isc__timer_reset(isc_timer_t *timer0, isc_timertype_t type,
isc_timer_reset(isc_timer_t *timer, isc_timertype_t type,
const isc_time_t *expires, const isc_interval_t *interval,
isc_boolean_t purge)
{
isc__timer_t *timer = (isc__timer_t *)timer0;
isc_time_t now;
isc__timermgr_t *manager;
isc_timermgr_t *manager;
isc_result_t result;
/*
@@ -568,8 +504,7 @@ isc__timer_reset(isc_timer_t *timer0, isc_timertype_t type,
}
isc_timertype_t
isc_timer_gettype(isc_timer_t *timer0) {
isc__timer_t *timer = (isc__timer_t *)timer0;
isc_timer_gettype(isc_timer_t *timer) {
isc_timertype_t t;
REQUIRE(VALID_TIMER(timer));
@@ -582,8 +517,7 @@ isc_timer_gettype(isc_timer_t *timer0) {
}
isc_result_t
isc__timer_touch(isc_timer_t *timer0) {
isc__timer_t *timer = (isc__timer_t *)timer0;
isc_timer_touch(isc_timer_t *timer) {
isc_result_t result;
isc_time_t now;
@@ -613,9 +547,7 @@ isc__timer_touch(isc_timer_t *timer0) {
}
void
isc__timer_attach(isc_timer_t *timer0, isc_timer_t **timerp) {
isc__timer_t *timer = (isc__timer_t *)timer0;
isc_timer_attach(isc_timer_t *timer, isc_timer_t **timerp) {
/*
* Attach *timerp to timer.
*/
@@ -631,8 +563,8 @@ isc__timer_attach(isc_timer_t *timer0, isc_timer_t **timerp) {
}
void
isc__timer_detach(isc_timer_t **timerp) {
isc__timer_t *timer;
isc_timer_detach(isc_timer_t **timerp) {
isc_timer_t *timer;
isc_boolean_t free_timer = ISC_FALSE;
/*
@@ -640,7 +572,7 @@ isc__timer_detach(isc_timer_t **timerp) {
*/
REQUIRE(timerp != NULL);
timer = (isc__timer_t *)*timerp;
timer = (isc_timer_t *)*timerp;
REQUIRE(VALID_TIMER(timer));
LOCK(&timer->lock);
@@ -657,11 +589,11 @@ isc__timer_detach(isc_timer_t **timerp) {
}
static void
dispatch(isc__timermgr_t *manager, isc_time_t *now) {
dispatch(isc_timermgr_t *manager, isc_time_t *now) {
isc_boolean_t done = ISC_FALSE, post_event, need_schedule;
isc_timerevent_t *event;
isc_eventtype_t type = 0;
isc__timer_t *timer;
isc_timer_t *timer;
isc_result_t result;
isc_boolean_t idle;
@@ -775,13 +707,13 @@ dispatch(isc__timermgr_t *manager, isc_time_t *now) {
}
}
#ifdef USE_TIMER_THREAD
#ifdef ISC_PLATFORM_USETHREADS
static isc_threadresult_t
#ifdef _WIN32 /* XXXDCL */
WINAPI
#endif
run(void *uap) {
isc__timermgr_t *manager = uap;
isc_timermgr_t *manager = uap;
isc_time_t now;
isc_result_t result;
@@ -820,11 +752,11 @@ run(void *uap) {
return ((isc_threadresult_t)0);
}
#endif /* USE_TIMER_THREAD */
#endif /* ISC_PLATFORM_USETHREADS */
static isc_boolean_t
sooner(void *v1, void *v2) {
isc__timer_t *t1, *t2;
isc_timer_t *t1, *t2;
t1 = v1;
t2 = v2;
@@ -838,7 +770,7 @@ sooner(void *v1, void *v2) {
static void
set_index(void *what, unsigned int index) {
isc__timer_t *timer;
isc_timer_t *timer;
timer = what;
REQUIRE(VALID_TIMER(timer));
@@ -847,8 +779,8 @@ set_index(void *what, unsigned int index) {
}
isc_result_t
isc__timermgr_create(isc_mem_t *mctx, isc_timermgr_t **managerp) {
isc__timermgr_t *manager;
isc_timermgr_create(isc_mem_t *mctx, isc_timermgr_t **managerp) {
isc_timermgr_t *manager;
isc_result_t result;
/*
@@ -857,21 +789,20 @@ isc__timermgr_create(isc_mem_t *mctx, isc_timermgr_t **managerp) {
REQUIRE(managerp != NULL && *managerp == NULL);
#ifdef USE_SHARED_MANAGER
#ifndef ISC_PLATFORM_USETHREADS
if (timermgr != NULL) {
timermgr->refs++;
*managerp = (isc_timermgr_t *)timermgr;
return (ISC_R_SUCCESS);
}
#endif /* USE_SHARED_MANAGER */
#endif /* ISC_PLATFORM_USETHREADS */
manager = isc_mem_get(mctx, sizeof(*manager));
if (manager == NULL)
return (ISC_R_NOMEMORY);
manager->common.impmagic = TIMER_MANAGER_MAGIC;
manager->common.magic = ISCAPI_TIMERMGR_MAGIC;
manager->common.methods = (isc_timermgrmethods_t *)&timermgrmethods;
manager->impmagic = TIMER_MANAGER_MAGIC;
manager->magic = ISCAPI_TIMERMGR_MAGIC;
manager->mctx = NULL;
manager->done = ISC_FALSE;
INIT_LIST(manager->timers);
@@ -891,7 +822,7 @@ isc__timermgr_create(isc_mem_t *mctx, isc_timermgr_t **managerp) {
return (result);
}
isc_mem_attach(mctx, &manager->mctx);
#ifdef USE_TIMER_THREAD
#ifdef ISC_PLATFORM_USETHREADS
if (isc_condition_init(&manager->wakeup) != ISC_R_SUCCESS) {
isc_mem_detach(&manager->mctx);
DESTROYLOCK(&manager->lock);
@@ -918,10 +849,10 @@ isc__timermgr_create(isc_mem_t *mctx, isc_timermgr_t **managerp) {
}
isc_thread_setname(manager->thread, "isc-timer");
#endif
#ifdef USE_SHARED_MANAGER
#ifndef ISC_PLATFORM_USETHREADS
manager->refs = 1;
timermgr = manager;
#endif /* USE_SHARED_MANAGER */
#endif /* ISC_PLATFORM_USETHREADS */
*managerp = (isc_timermgr_t *)manager;
@@ -929,21 +860,19 @@ isc__timermgr_create(isc_mem_t *mctx, isc_timermgr_t **managerp) {
}
void
isc_timermgr_poke(isc_timermgr_t *manager0) {
#ifdef USE_TIMER_THREAD
isc__timermgr_t *manager = (isc__timermgr_t *)manager0;
isc_timermgr_poke(isc_timermgr_t *manager) {
#ifdef ISC_PLATFORM_USETHREADS
REQUIRE(VALID_MANAGER(manager));
SIGNAL(&manager->wakeup);
#else
UNUSED(manager0);
UNUSED(manager);
#endif
}
void
isc__timermgr_destroy(isc_timermgr_t **managerp) {
isc__timermgr_t *manager;
isc_timermgr_destroy(isc_timermgr_t **managerp) {
isc_timermgr_t *manager;
isc_mem_t *mctx;
/*
@@ -951,12 +880,12 @@ isc__timermgr_destroy(isc_timermgr_t **managerp) {
*/
REQUIRE(managerp != NULL);
manager = (isc__timermgr_t *)*managerp;
manager = (isc_timermgr_t *)*managerp;
REQUIRE(VALID_MANAGER(manager));
LOCK(&manager->lock);
#ifdef USE_SHARED_MANAGER
#ifndef ISC_PLATFORM_USETHREADS
manager->refs--;
if (manager->refs > 0) {
UNLOCK(&manager->lock);
@@ -964,24 +893,21 @@ isc__timermgr_destroy(isc_timermgr_t **managerp) {
return;
}
timermgr = NULL;
#endif /* USE_SHARED_MANAGER */
#ifndef USE_TIMER_THREAD
isc__timermgr_dispatch((isc_timermgr_t *)manager);
isc_timermgr_dispatch((isc_timermgr_t *)manager);
#endif
REQUIRE(EMPTY(manager->timers));
manager->done = ISC_TRUE;
#ifdef USE_TIMER_THREAD
#ifdef ISC_PLATFORM_USETHREADS
XTRACE(isc_msgcat_get(isc_msgcat, ISC_MSGSET_TIMER,
ISC_MSG_SIGNALDESTROY, "signal (destroy)"));
SIGNAL(&manager->wakeup);
#endif /* USE_TIMER_THREAD */
#endif /* ISC_PLATFORM_USETHREADS */
UNLOCK(&manager->lock);
#ifdef USE_TIMER_THREAD
#ifdef ISC_PLATFORM_USETHREADS
/*
* Wait for thread to exit.
*/
@@ -990,89 +916,56 @@ isc__timermgr_destroy(isc_timermgr_t **managerp) {
"isc_thread_join() %s",
isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL,
ISC_MSG_FAILED, "failed"));
#endif /* USE_TIMER_THREAD */
#endif /* ISC_PLATFORM_USETHREADS */
/*
* Clean up.
*/
#ifdef USE_TIMER_THREAD
#ifdef ISC_PLATFORM_USETHREADS
(void)isc_condition_destroy(&manager->wakeup);
#endif /* USE_TIMER_THREAD */
#endif /* ISC_PLATFORM_USETHREADS */
DESTROYLOCK(&manager->lock);
isc_heap_destroy(&manager->heap);
manager->common.impmagic = 0;
manager->common.magic = 0;
manager->impmagic = 0;
manager->magic = 0;
mctx = manager->mctx;
isc_mem_put(mctx, manager, sizeof(*manager));
isc_mem_detach(&mctx);
*managerp = NULL;
#ifdef USE_SHARED_MANAGER
#ifndef ISC_PLATFORM_USETHREADS
timermgr = NULL;
#endif
}
#ifndef USE_TIMER_THREAD
#ifndef ISC_PLATFORM_USETHREADS
isc_result_t
isc__timermgr_nextevent(isc_timermgr_t *manager0, isc_time_t *when) {
isc__timermgr_t *manager = (isc__timermgr_t *)manager0;
#ifdef USE_SHARED_MANAGER
if (manager == NULL)
isc_timermgr_nextevent(isc_timermgr_t *manager, isc_time_t *when) {
if (manager == NULL) {
manager = timermgr;
#endif
if (manager == NULL || manager->nscheduled == 0)
}
if (manager == NULL || manager->nscheduled == 0) {
return (ISC_R_NOTFOUND);
}
*when = manager->due;
return (ISC_R_SUCCESS);
}
void
isc__timermgr_dispatch(isc_timermgr_t *manager0) {
isc__timermgr_t *manager = (isc__timermgr_t *)manager0;
isc_timermgr_dispatch(isc_timermgr_t *manager) {
isc_time_t now;
#ifdef USE_SHARED_MANAGER
if (manager == NULL)
if (manager == NULL) {
manager = timermgr;
#endif
if (manager == NULL)
}
if (manager == NULL) {
return;
}
TIME_NOW(&now);
dispatch(manager, &now);
}
#endif /* USE_TIMER_THREAD */
isc_result_t
isc__timer_register(void) {
return (isc_timer_register(isc__timermgr_create));
}
static isc_mutex_t createlock;
static isc_once_t once = ISC_ONCE_INIT;
static isc_timermgrcreatefunc_t timermgr_createfunc = NULL;
static void
initialize(void) {
RUNTIME_CHECK(isc_mutex_init(&createlock) == ISC_R_SUCCESS);
}
isc_result_t
isc_timer_register(isc_timermgrcreatefunc_t createfunc) {
isc_result_t result = ISC_R_SUCCESS;
RUNTIME_CHECK(isc_once_do(&once, initialize) == ISC_R_SUCCESS);
LOCK(&createlock);
if (timermgr_createfunc == NULL)
timermgr_createfunc = createfunc;
else
result = ISC_R_EXISTS;
UNLOCK(&createlock);
return (result);
}
#endif /* ISC_PLATFORM_USETHREADS */
isc_result_t
isc_timermgr_createinctx(isc_mem_t *mctx, isc_appctx_t *actx,
@@ -1080,110 +973,10 @@ isc_timermgr_createinctx(isc_mem_t *mctx, isc_appctx_t *actx,
{
isc_result_t result;
LOCK(&createlock);
REQUIRE(timermgr_createfunc != NULL);
result = (*timermgr_createfunc)(mctx, managerp);
UNLOCK(&createlock);
if (result == ISC_R_SUCCESS)
result = isc_timermgr_create(mctx, managerp);
if (result == ISC_R_SUCCESS) {
isc_appctx_settimermgr(actx, *managerp);
}
return (result);
}
isc_result_t
isc_timermgr_create(isc_mem_t *mctx, isc_timermgr_t **managerp) {
isc_result_t result;
if (isc_bind9)
return (isc__timermgr_create(mctx, managerp));
LOCK(&createlock);
REQUIRE(timermgr_createfunc != NULL);
result = (*timermgr_createfunc)(mctx, managerp);
UNLOCK(&createlock);
return (result);
}
void
isc_timermgr_destroy(isc_timermgr_t **managerp) {
REQUIRE(*managerp != NULL && ISCAPI_TIMERMGR_VALID(*managerp));
if (isc_bind9)
isc__timermgr_destroy(managerp);
else
(*managerp)->methods->destroy(managerp);
ENSURE(*managerp == NULL);
}
isc_result_t
isc_timer_create(isc_timermgr_t *manager, isc_timertype_t type,
const isc_time_t *expires, const isc_interval_t *interval,
isc_task_t *task, isc_taskaction_t action, void *arg,
isc_timer_t **timerp)
{
REQUIRE(ISCAPI_TIMERMGR_VALID(manager));
if (isc_bind9)
return (isc__timer_create(manager, type, expires, interval,
task, action, arg, timerp));
return (manager->methods->timercreate(manager, type, expires,
interval, task, action, arg,
timerp));
}
void
isc_timer_attach(isc_timer_t *timer, isc_timer_t **timerp) {
REQUIRE(ISCAPI_TIMER_VALID(timer));
REQUIRE(timerp != NULL && *timerp == NULL);
if (isc_bind9)
isc__timer_attach(timer, timerp);
else
timer->methods->attach(timer, timerp);
ENSURE(*timerp == timer);
}
void
isc_timer_detach(isc_timer_t **timerp) {
REQUIRE(timerp != NULL && ISCAPI_TIMER_VALID(*timerp));
if (isc_bind9)
isc__timer_detach(timerp);
else
(*timerp)->methods->detach(timerp);
ENSURE(*timerp == NULL);
}
isc_result_t
isc_timer_reset(isc_timer_t *timer, isc_timertype_t type,
const isc_time_t *expires, const isc_interval_t *interval,
isc_boolean_t purge)
{
REQUIRE(ISCAPI_TIMER_VALID(timer));
if (isc_bind9)
return (isc__timer_reset(timer, type, expires,
interval, purge));
return (timer->methods->reset(timer, type, expires, interval, purge));
}
isc_result_t
isc_timer_touch(isc_timer_t *timer) {
REQUIRE(ISCAPI_TIMER_VALID(timer));
if (isc_bind9)
return (isc__timer_touch(timer));
return (timer->methods->touch(timer));
}
+2 -2
View File
@@ -15,9 +15,9 @@
/*! \file */
isc_result_t
isc__timermgr_nextevent(isc_timermgr_t *timermgr, isc_time_t *when);
isc_timermgr_nextevent(isc_timermgr_t *timermgr, isc_time_t *when);
void
isc__timermgr_dispatch(isc_timermgr_t *timermgr);
isc_timermgr_dispatch(isc_timermgr_t *timermgr);
#endif /* ISC_TIMER_P_H */
+167 -278
View File
@@ -59,33 +59,7 @@
static pthread_t blockedthread;
#endif /* ISC_PLATFORM_USETHREADS */
/*%
* The following are intended for internal use (indicated by "isc__"
* prefix) but are not declared as static, allowing direct access from
* unit tests etc.
*/
isc_result_t isc__app_start(void);
isc_result_t isc__app_ctxstart(isc_appctx_t *ctx);
isc_result_t isc__app_onrun(isc_mem_t *mctx, isc_task_t *task,
isc_taskaction_t action, void *arg);
isc_result_t isc__app_ctxrun(isc_appctx_t *ctx);
isc_result_t isc__app_run(void);
isc_result_t isc__app_ctxshutdown(isc_appctx_t *ctx);
isc_result_t isc__app_shutdown(void);
isc_result_t isc__app_reload(void);
isc_result_t isc__app_ctxsuspend(isc_appctx_t *ctx);
void isc__app_ctxfinish(isc_appctx_t *ctx);
void isc__app_finish(void);
void isc__app_block(void);
void isc__app_unblock(void);
isc_result_t isc__appctx_create(isc_mem_t *mctx, isc_appctx_t **ctxp);
void isc__appctx_destroy(isc_appctx_t **ctxp);
void isc__appctx_settaskmgr(isc_appctx_t *ctx, isc_taskmgr_t *taskmgr);
void isc__appctx_setsocketmgr(isc_appctx_t *ctx, isc_socketmgr_t *socketmgr);
void isc__appctx_settimermgr(isc_appctx_t *ctx, isc_timermgr_t *timermgr);
isc_result_t isc__app_ctxonrun(isc_appctx_t *ctx, isc_mem_t *mctx,
isc_task_t *task, isc_taskaction_t action,
void *arg);
static isc_boolean_t is_running = ISC_FALSE;
/*
* The application context of this module. This implementation actually
@@ -94,8 +68,9 @@ isc_result_t isc__app_ctxonrun(isc_appctx_t *ctx, isc_mem_t *mctx,
#define APPCTX_MAGIC ISC_MAGIC('A', 'p', 'c', 'x')
#define VALID_APPCTX(c) ISC_MAGIC_VALID(c, APPCTX_MAGIC)
typedef struct isc__appctx {
isc_appctx_t common;
typedef struct isc_appctx {
unsigned int impmagic;
unsigned int magic;
isc_mem_t *mctx;
isc_mutex_t lock;
isc_eventlist_t on_run;
@@ -120,38 +95,9 @@ typedef struct isc__appctx {
isc_mutex_t readylock;
isc_condition_t ready;
#endif /* ISC_PLATFORM_USETHREADS */
} isc__appctx_t;
} isc_appctx_t;
static isc__appctx_t isc_g_appctx;
static struct {
isc_appmethods_t methods;
/*%
* The following are defined just for avoiding unused static functions.
*/
void *run, *shutdown, *start, *reload, *finish, *block, *unblock;
} appmethods = {
{
isc__appctx_destroy,
isc__app_ctxstart,
isc__app_ctxrun,
isc__app_ctxsuspend,
isc__app_ctxshutdown,
isc__app_ctxfinish,
isc__appctx_settaskmgr,
isc__appctx_setsocketmgr,
isc__appctx_settimermgr,
isc__app_ctxonrun
},
(void *)isc__app_run,
(void *)isc__app_shutdown,
(void *)isc__app_start,
(void *)isc__app_reload,
(void *)isc__app_finish,
(void *)isc__app_block,
(void *)isc__app_unblock
};
static isc_appctx_t isc_g_appctx;
#ifdef HAVE_LINUXTHREADS
/*!
@@ -204,8 +150,7 @@ handle_signal(int sig, void (*handler)(int)) {
}
isc_result_t
isc__app_ctxstart(isc_appctx_t *ctx0) {
isc__appctx_t *ctx = (isc__appctx_t *)ctx0;
isc_app_ctxstart(isc_appctx_t *ctx) {
isc_result_t result;
int presult;
sigset_t sset;
@@ -376,29 +321,27 @@ isc__app_ctxstart(isc_appctx_t *ctx0) {
}
isc_result_t
isc__app_start(void) {
isc_g_appctx.common.impmagic = APPCTX_MAGIC;
isc_g_appctx.common.magic = ISCAPI_APPCTX_MAGIC;
isc_g_appctx.common.methods = &appmethods.methods;
isc_app_start(void) {
isc_g_appctx.impmagic = APPCTX_MAGIC;
isc_g_appctx.magic = ISCAPI_APPCTX_MAGIC;
isc_g_appctx.mctx = NULL;
/* The remaining members will be initialized in ctxstart() */
return (isc__app_ctxstart((isc_appctx_t *)&isc_g_appctx));
return (isc_app_ctxstart((isc_appctx_t *)&isc_g_appctx));
}
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)
{
return (isc__app_ctxonrun((isc_appctx_t *)&isc_g_appctx, mctx,
return (isc_app_ctxonrun((isc_appctx_t *)&isc_g_appctx, mctx,
task, action, arg));
}
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__appctx_t *ctx = (isc__appctx_t *)ctx0;
isc_event_t *event;
isc_task_t *cloned_task = NULL;
isc_result_t result;
@@ -438,7 +381,7 @@ isc__app_ctxonrun(isc_appctx_t *ctx0, isc_mem_t *mctx, isc_task_t *task,
* Event loop for nonthreaded programs.
*/
static isc_result_t
evloop(isc__appctx_t *ctx) {
evloop(isc_appctx_t *ctx) {
isc_result_t result;
while (!ctx->want_shutdown) {
@@ -452,8 +395,8 @@ evloop(isc__appctx_t *ctx) {
/*
* Check the reload (or suspend) case first for exiting the
* loop as fast as possible in case:
* - the direct call to isc__taskmgr_dispatch() in
* isc__app_ctxrun() completes all the tasks so far,
* - the direct call to isc_taskmgr_dispatch() in
* isc_app_ctxrun() completes all the tasks so far,
* - there is thus currently no active task, and
* - there is a timer event
*/
@@ -462,14 +405,14 @@ evloop(isc__appctx_t *ctx) {
return (ISC_R_RELOAD);
}
readytasks = isc__taskmgr_ready(ctx->taskmgr);
readytasks = isc_taskmgr_ready(ctx->taskmgr);
if (readytasks) {
tv.tv_sec = 0;
tv.tv_usec = 0;
tvp = &tv;
call_timer_dispatch = ISC_TRUE;
} else {
result = isc__timermgr_nextevent(ctx->timermgr, &when);
result = isc_timermgr_nextevent(ctx->timermgr, &when);
if (result != ISC_R_SUCCESS)
tvp = NULL;
else {
@@ -486,11 +429,11 @@ evloop(isc__appctx_t *ctx) {
}
swait = NULL;
n = isc__socketmgr_waitevents(ctx->socketmgr, tvp, &swait);
n = isc_socketmgr_waitevents(ctx->socketmgr, tvp, &swait);
if (n == 0 || call_timer_dispatch) {
/*
* We call isc__timermgr_dispatch() only when
* We call isc_timermgr_dispatch() only when
* necessary, in order to reduce overhead. If the
* select() call indicates a timeout, we need the
* dispatch. Even if not, if we set the 0-timeout
@@ -503,11 +446,11 @@ evloop(isc__appctx_t *ctx) {
* call, since this loop only runs in the non-thread
* mode.
*/
isc__timermgr_dispatch(ctx->timermgr);
isc_timermgr_dispatch(ctx->timermgr);
}
if (n > 0)
(void)isc__socketmgr_dispatch(ctx->socketmgr, swait);
(void)isc__taskmgr_dispatch(ctx->taskmgr);
(void)isc_socketmgr_dispatch(ctx->socketmgr, swait);
(void)isc_taskmgr_dispatch(ctx->taskmgr);
}
return (ISC_R_SUCCESS);
}
@@ -535,7 +478,7 @@ static isc_boolean_t in_recursive_evloop = ISC_FALSE;
static isc_boolean_t signalled = ISC_FALSE;
isc_result_t
isc__nothread_wait_hack(isc_condition_t *cp, isc_mutex_t *mp) {
isc_nothread_wait_hack(isc_condition_t *cp, isc_mutex_t *mp) {
isc_result_t result;
UNUSED(cp);
@@ -561,7 +504,7 @@ isc__nothread_wait_hack(isc_condition_t *cp, isc_mutex_t *mp) {
}
isc_result_t
isc__nothread_signal_hack(isc_condition_t *cp) {
isc_nothread_signal_hack(isc_condition_t *cp) {
UNUSED(cp);
@@ -574,8 +517,7 @@ isc__nothread_signal_hack(isc_condition_t *cp) {
#endif /* ISC_PLATFORM_USETHREADS */
isc_result_t
isc__app_ctxrun(isc_appctx_t *ctx0) {
isc__appctx_t *ctx = (isc__appctx_t *)ctx0;
isc_app_ctxrun(isc_appctx_t *ctx) {
int result;
isc_event_t *event, *next_event;
isc_task_t *task;
@@ -616,13 +558,13 @@ isc__app_ctxrun(isc_appctx_t *ctx0) {
UNLOCK(&ctx->lock);
#ifndef ISC_PLATFORM_USETHREADS
if (isc_bind9 && ctx == &isc_g_appctx) {
if (ctx == &isc_g_appctx) {
result = handle_signal(SIGHUP, reload_action);
if (result != ISC_R_SUCCESS)
return (ISC_R_SUCCESS);
}
(void) isc__taskmgr_dispatch(ctx->taskmgr);
(void) isc_taskmgr_dispatch(ctx->taskmgr);
result = evloop(ctx);
return (result);
#else /* ISC_PLATFORM_USETHREADS */
@@ -630,8 +572,9 @@ isc__app_ctxrun(isc_appctx_t *ctx0) {
* BIND9 internal tools using multiple contexts do not
* rely on signal.
*/
if (isc_bind9 && ctx != &isc_g_appctx)
if (ctx != &isc_g_appctx) {
return (ISC_R_SUCCESS);
}
/*
* There is no danger if isc_app_shutdown() is called before we
@@ -641,98 +584,68 @@ isc__app_ctxrun(isc_appctx_t *ctx0) {
*/
while (!ctx->want_shutdown) {
#ifdef HAVE_SIGWAIT
if (isc_bind9) {
/*
* BIND9 internal; single context:
* Wait for SIGHUP, SIGINT, or SIGTERM.
*/
if (sigemptyset(&sset) != 0 ||
sigaddset(&sset, SIGHUP) != 0 ||
sigaddset(&sset, SIGINT) != 0 ||
sigaddset(&sset, SIGTERM) != 0) {
isc__strerror(errno, strbuf, sizeof(strbuf));
UNEXPECTED_ERROR(__FILE__, __LINE__,
"isc_app_run() sigsetops: %s",
strbuf);
return (ISC_R_UNEXPECTED);
}
/*
* BIND9 internal; single context:
* Wait for SIGHUP, SIGINT, or SIGTERM.
*/
if (sigemptyset(&sset) != 0 ||
sigaddset(&sset, SIGHUP) != 0 ||
sigaddset(&sset, SIGINT) != 0 ||
sigaddset(&sset, SIGTERM) != 0)
{
isc__strerror(errno, strbuf, sizeof(strbuf));
UNEXPECTED_ERROR(__FILE__, __LINE__,
"isc_app_run() sigsetops: %s",
strbuf);
return (ISC_R_UNEXPECTED);
}
#ifndef HAVE_UNIXWARE_SIGWAIT
result = sigwait(&sset, &sig);
if (result == 0) {
if (sig == SIGINT || sig == SIGTERM)
ctx->want_shutdown = ISC_TRUE;
else if (sig == SIGHUP)
ctx->want_reload = ISC_TRUE;
}
result = sigwait(&sset, &sig);
if (result == 0) {
if (sig == SIGINT || sig == SIGTERM)
ctx->want_shutdown = ISC_TRUE;
else if (sig == SIGHUP)
ctx->want_reload = ISC_TRUE;
}
#else /* Using UnixWare sigwait semantics. */
sig = sigwait(&sset);
if (sig >= 0) {
if (sig == SIGINT || sig == SIGTERM)
ctx->want_shutdown = ISC_TRUE;
else if (sig == SIGHUP)
ctx->want_reload = ISC_TRUE;
}
sig = sigwait(&sset);
if (sig >= 0) {
if (sig == SIGINT || sig == SIGTERM)
ctx->want_shutdown = ISC_TRUE;
else if (sig == SIGHUP)
ctx->want_reload = ISC_TRUE;
}
#endif /* HAVE_UNIXWARE_SIGWAIT */
} 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);
}
#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) {
isc__strerror(errno, strbuf, sizeof(strbuf));
UNEXPECTED_ERROR(__FILE__, __LINE__,
"isc_app_run() sigsetops: %s",
strbuf);
return (ISC_R_UNEXPECTED);
}
#ifdef HAVE_GPERFTOOLS_PROFILER
if (sigaddset(&sset, SIGALRM) != 0) {
isc__strerror(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);
/*
* 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) {
isc__strerror(errno, strbuf, sizeof(strbuf));
UNEXPECTED_ERROR(__FILE__, __LINE__,
"isc_app_run() sigsetops: %s",
strbuf);
return (ISC_R_UNEXPECTED);
}
#ifdef HAVE_GPERFTOOLS_PROFILER
if (sigaddset(&sset, SIGALRM) != 0) {
isc__strerror(errno, strbuf, sizeof(strbuf));
UNEXPECTED_ERROR(__FILE__, __LINE__,
"isc_app_run() sigsetops: %s",
strbuf);
return (ISC_R_UNEXPECTED);
}
#endif
(void)sigsuspend(&sset);
#endif /* HAVE_SIGWAIT */
if (ctx->want_reload) {
@@ -749,13 +662,7 @@ isc__app_ctxrun(isc_appctx_t *ctx0) {
}
isc_result_t
isc__app_run(void) {
return (isc__app_ctxrun((isc_appctx_t *)&isc_g_appctx));
}
isc_result_t
isc__app_ctxshutdown(isc_appctx_t *ctx0) {
isc__appctx_t *ctx = (isc__appctx_t *)ctx0;
isc_app_ctxshutdown(isc_appctx_t *ctx) {
isc_boolean_t want_kill = ISC_TRUE;
#ifdef ISC_PLATFORM_USETHREADS
char strbuf[ISC_STRERRORSIZE];
@@ -775,49 +682,38 @@ isc__app_ctxshutdown(isc_appctx_t *ctx0) {
UNLOCK(&ctx->lock);
if (want_kill) {
if (isc_bind9 && ctx != &isc_g_appctx)
if (ctx != &isc_g_appctx) {
/* BIND9 internal, but using multiple contexts */
ctx->want_shutdown = ISC_TRUE;
else {
} else {
#ifndef ISC_PLATFORM_USETHREADS
ctx->want_shutdown = ISC_TRUE;
#else /* ISC_PLATFORM_USETHREADS */
#ifdef HAVE_LINUXTHREADS
if (isc_bind9) {
/* BIND9 internal, single context */
int result;
/* BIND9 internal, single context */
int result;
result = pthread_kill(main_thread, SIGTERM);
if (result != 0) {
isc__strerror(result,
strbuf, sizeof(strbuf));
UNEXPECTED_ERROR(__FILE__, __LINE__,
"isc_app_shutdown() "
"pthread_kill: %s",
strbuf);
return (ISC_R_UNEXPECTED);
}
result = pthread_kill(main_thread, SIGTERM);
if (result != 0) {
isc__strerror(result,
strbuf, sizeof(strbuf));
UNEXPECTED_ERROR(__FILE__, __LINE__,
"isc_app_shutdown() "
"pthread_kill: %s",
strbuf);
return (ISC_R_UNEXPECTED);
}
#else
if (isc_bind9) {
/* BIND9 internal, single context */
if (kill(getpid(), SIGTERM) < 0) {
isc__strerror(errno,
strbuf, sizeof(strbuf));
UNEXPECTED_ERROR(__FILE__, __LINE__,
"isc_app_shutdown() "
"kill: %s", strbuf);
return (ISC_R_UNEXPECTED);
}
/* BIND9 internal, single context */
if (kill(getpid(), SIGTERM) < 0) {
isc__strerror(errno,
strbuf, sizeof(strbuf));
UNEXPECTED_ERROR(__FILE__, __LINE__,
"isc_app_shutdown() "
"kill: %s", strbuf);
return (ISC_R_UNEXPECTED);
}
#endif /* HAVE_LINUXTHREADS */
else {
/* External, multiple contexts */
LOCK(&ctx->readylock);
ctx->want_shutdown = ISC_TRUE;
UNLOCK(&ctx->readylock);
SIGNAL(&ctx->ready);
}
#endif /* ISC_PLATFORM_USETHREADS */
}
}
@@ -826,13 +722,12 @@ isc__app_ctxshutdown(isc_appctx_t *ctx0) {
}
isc_result_t
isc__app_shutdown(void) {
return (isc__app_ctxshutdown((isc_appctx_t *)&isc_g_appctx));
isc_app_shutdown(void) {
return (isc_app_ctxshutdown((isc_appctx_t *)&isc_g_appctx));
}
isc_result_t
isc__app_ctxsuspend(isc_appctx_t *ctx0) {
isc__appctx_t *ctx = (isc__appctx_t *)ctx0;
isc_app_ctxsuspend(isc_appctx_t *ctx) {
isc_boolean_t want_kill = ISC_TRUE;
#ifdef ISC_PLATFORM_USETHREADS
char strbuf[ISC_STRERRORSIZE];
@@ -853,49 +748,38 @@ isc__app_ctxsuspend(isc_appctx_t *ctx0) {
UNLOCK(&ctx->lock);
if (want_kill) {
if (isc_bind9 && ctx != &isc_g_appctx)
if (ctx != &isc_g_appctx) {
/* BIND9 internal, but using multiple contexts */
ctx->want_reload = ISC_TRUE;
else {
} else {
#ifndef ISC_PLATFORM_USETHREADS
ctx->want_reload = ISC_TRUE;
#else /* ISC_PLATFORM_USETHREADS */
#ifdef HAVE_LINUXTHREADS
if (isc_bind9) {
/* BIND9 internal, single context */
int result;
/* BIND9 internal, single context */
int result;
result = pthread_kill(main_thread, SIGHUP);
if (result != 0) {
isc__strerror(result,
strbuf, sizeof(strbuf));
UNEXPECTED_ERROR(__FILE__, __LINE__,
"isc_app_reload() "
"pthread_kill: %s",
strbuf);
return (ISC_R_UNEXPECTED);
}
result = pthread_kill(main_thread, SIGHUP);
if (result != 0) {
isc__strerror(result,
strbuf, sizeof(strbuf));
UNEXPECTED_ERROR(__FILE__, __LINE__,
"isc_app_reload() "
"pthread_kill: %s",
strbuf);
return (ISC_R_UNEXPECTED);
}
#else
if (isc_bind9) {
/* BIND9 internal, single context */
if (kill(getpid(), SIGHUP) < 0) {
isc__strerror(errno,
strbuf, sizeof(strbuf));
UNEXPECTED_ERROR(__FILE__, __LINE__,
"isc_app_reload() "
"kill: %s", strbuf);
return (ISC_R_UNEXPECTED);
}
/* BIND9 internal, single context */
if (kill(getpid(), SIGHUP) < 0) {
isc__strerror(errno,
strbuf, sizeof(strbuf));
UNEXPECTED_ERROR(__FILE__, __LINE__,
"isc_app_reload() "
"kill: %s", strbuf);
return (ISC_R_UNEXPECTED);
}
#endif /* HAVE_LINUXTHREADS */
else {
/* External, multiple contexts */
LOCK(&ctx->readylock);
ctx->want_reload = ISC_TRUE;
UNLOCK(&ctx->readylock);
SIGNAL(&ctx->ready);
}
#endif /* ISC_PLATFORM_USETHREADS */
}
}
@@ -904,26 +788,24 @@ isc__app_ctxsuspend(isc_appctx_t *ctx0) {
}
isc_result_t
isc__app_reload(void) {
return (isc__app_ctxsuspend((isc_appctx_t *)&isc_g_appctx));
isc_app_reload(void) {
return (isc_app_ctxsuspend((isc_appctx_t *)&isc_g_appctx));
}
void
isc__app_ctxfinish(isc_appctx_t *ctx0) {
isc__appctx_t *ctx = (isc__appctx_t *)ctx0;
isc_app_ctxfinish(isc_appctx_t *ctx) {
REQUIRE(VALID_APPCTX(ctx));
DESTROYLOCK(&ctx->lock);
}
void
isc__app_finish(void) {
isc__app_ctxfinish((isc_appctx_t *)&isc_g_appctx);
isc_app_finish(void) {
isc_app_ctxfinish((isc_appctx_t *)&isc_g_appctx);
}
void
isc__app_block(void) {
isc_app_block(void) {
#ifdef ISC_PLATFORM_USETHREADS
sigset_t sset;
#endif /* ISC_PLATFORM_USETHREADS */
@@ -941,7 +823,7 @@ isc__app_block(void) {
}
void
isc__app_unblock(void) {
isc_app_unblock(void) {
#ifdef ISC_PLATFORM_USETHREADS
sigset_t sset;
#endif /* ISC_PLATFORM_USETHREADS */
@@ -961,9 +843,14 @@ isc__app_unblock(void) {
#endif /* ISC_PLATFORM_USETHREADS */
}
unsigned int
isc_appctx_magic(isc_appctx_t *ctx) {
return (ctx->magic);
}
isc_result_t
isc__appctx_create(isc_mem_t *mctx, isc_appctx_t **ctxp) {
isc__appctx_t *ctx;
isc_appctx_create(isc_mem_t *mctx, isc_appctx_t **ctxp) {
isc_appctx_t *ctx;
REQUIRE(mctx != NULL);
REQUIRE(ctxp != NULL && *ctxp == NULL);
@@ -972,9 +859,8 @@ isc__appctx_create(isc_mem_t *mctx, isc_appctx_t **ctxp) {
if (ctx == NULL)
return (ISC_R_NOMEMORY);
ctx->common.impmagic = APPCTX_MAGIC;
ctx->common.magic = ISCAPI_APPCTX_MAGIC;
ctx->common.methods = &appmethods.methods;
ctx->impmagic = APPCTX_MAGIC;
ctx->magic = ISCAPI_APPCTX_MAGIC;
ctx->mctx = NULL;
isc_mem_attach(mctx, &ctx->mctx);
@@ -989,11 +875,11 @@ isc__appctx_create(isc_mem_t *mctx, isc_appctx_t **ctxp) {
}
void
isc__appctx_destroy(isc_appctx_t **ctxp) {
isc__appctx_t *ctx;
isc_appctx_destroy(isc_appctx_t **ctxp) {
isc_appctx_t *ctx;
REQUIRE(ctxp != NULL);
ctx = (isc__appctx_t *)*ctxp;
ctx = (isc_appctx_t *)*ctxp;
REQUIRE(VALID_APPCTX(ctx));
isc_mem_putanddetach(&ctx->mctx, ctx, sizeof(*ctx));
@@ -1002,35 +888,38 @@ isc__appctx_destroy(isc_appctx_t **ctxp) {
}
void
isc__appctx_settaskmgr(isc_appctx_t *ctx0, isc_taskmgr_t *taskmgr) {
isc__appctx_t *ctx = (isc__appctx_t *)ctx0;
isc_appctx_settaskmgr(isc_appctx_t *ctx, isc_taskmgr_t *taskmgr) {
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;
isc_appctx_setsocketmgr(isc_appctx_t *ctx, isc_socketmgr_t *socketmgr) {
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;
isc_appctx_settimermgr(isc_appctx_t *ctx, isc_timermgr_t *timermgr) {
REQUIRE(VALID_APPCTX(ctx));
ctx->timermgr = timermgr;
}
isc_result_t
isc__app_register(void) {
return (isc_app_register(isc__appctx_create));
isc_boolean_t
isc_app_isrunning() {
return (is_running);
}
#include "../app_api.c"
isc_result_t
isc_app_run() {
isc_result_t result;
is_running = ISC_TRUE;
result = isc_app_ctxrun((isc_appctx_t *)&isc_g_appctx);
is_running = ISC_FALSE;
return (result);
}
+200 -421
View File
File diff suppressed because it is too large Load Diff
-7
View File
@@ -87,7 +87,6 @@ isc__socket_permunix
isc__socket_recv
isc__socket_recv2
isc__socket_recvv
isc__socket_register
isc__socket_send
isc__socket_sendto
isc__socket_sendto2
@@ -123,7 +122,6 @@ isc_app_ctxsuspend
isc_app_finish
isc_app_isrunning
isc_app_onrun
isc_app_register
isc_app_reload
isc_app_run
isc_app_shutdown
@@ -351,7 +349,6 @@ isc_lfsr_generate32
isc_lfsr_init
isc_lfsr_skip
isc_lib_initmsgcat
isc_lib_register
isc_log_categorybyname
isc_log_closefilelogs
isc_log_create
@@ -404,7 +401,6 @@ isc_mem_isovermem
isc_mem_maxinuse
isc_mem_printallactive
isc_mem_references
isc_mem_register
@IF NOTYET
isc_mem_renderjson
@END NOTYET
@@ -649,7 +645,6 @@ isc_task_privilege
isc_task_purge
isc_task_purgeevent
isc_task_purgerange
isc_task_register
isc_task_send
isc_task_sendanddetach
isc_task_setname
@@ -705,7 +700,6 @@ isc_timer_attach
isc_timer_create
isc_timer_detach
isc_timer_gettype
isc_timer_register
isc_timer_reset
isc_timer_touch
isc_timermgr_create
@@ -783,7 +777,6 @@ EXPORTS
isc__backtrace_nsymbols DATA
isc__backtrace_symtable DATA
isc_bind9 DATA
isc_commandline_argument DATA
isc_commandline_errprint DATA
isc_commandline_index DATA
-1
View File
@@ -1057,7 +1057,6 @@ main(int argc, char *argv[]) {
argv += isc_commandline_index;
/* Common set up */
isc_lib_register();
result = dns_lib_init();
if (result != ISC_R_SUCCESS) {
fprintf(stderr, "dns_lib_init failed: %u\n", result);
-1
View File
@@ -361,7 +361,6 @@ main(int argc, char *argv[]) {
altserveraddr = cp + 1;
}
isc_lib_register();
result = dns_lib_init();
if (result != ISC_R_SUCCESS) {
fprintf(stderr, "dns_lib_init failed: %u\n", result);
-1
View File
@@ -321,7 +321,6 @@ main(int argc, char *argv[]) {
query_array[i].xid = NULL;
}
isc_lib_register();
result = dns_lib_init();
if (result != ISC_R_SUCCESS) {
fprintf(stderr, "dns_lib_init failed: %u\n", result);
-1
View File
@@ -173,7 +173,6 @@ main(int argc, char *argv[]) {
if (argc < 2)
usage();
isc_lib_register();
result = dns_lib_init();
if (result != ISC_R_SUCCESS) {
fprintf(stderr, "dns_lib_init failed: %u\n", result);
-1
View File
@@ -235,7 +235,6 @@ main(int argc, char *argv[]) {
ISC_LIST_INIT(usedbuffers);
ISC_LIST_INIT(usedrdatalists);
ISC_LIST_INIT(prereqlist);
isc_lib_register();
result = dns_lib_init();
if (result != ISC_R_SUCCESS) {
fprintf(stderr, "dns_lib_init failed: %u\n", result);
-3
View File
@@ -3479,7 +3479,6 @@
./lib/isc/backtrace.c C 2009,2013,2014,2015,2016,2018
./lib/isc/base32.c C 2008,2009,2013,2014,2015,2016,2018
./lib/isc/base64.c C 1998,1999,2000,2001,2003,2004,2005,2007,2009,2013,2014,2015,2016,2018
./lib/isc/bind9.c C 2013,2016,2018
./lib/isc/buffer.c C 1998,1999,2000,2001,2002,2004,2005,2006,2007,2008,2012,2014,2015,2016,2017,2018
./lib/isc/bufferlist.c C 1999,2000,2001,2004,2005,2007,2016,2018
./lib/isc/commandline.c C.PORTION 1999,2000,2001,2004,2005,2007,2008,2014,2015,2016,2018
@@ -3510,7 +3509,6 @@
./lib/isc/include/isc/backtrace.h C 2009,2016,2018
./lib/isc/include/isc/base32.h C 2008,2014,2016,2018
./lib/isc/include/isc/base64.h C 1999,2000,2001,2004,2005,2006,2007,2016,2018
./lib/isc/include/isc/bind9.h C 2009,2013,2016,2018
./lib/isc/include/isc/boolean.h C 1998,1999,2000,2001,2004,2005,2006,2007,2016,2018
./lib/isc/include/isc/buffer.h C 1998,1999,2000,2001,2002,2004,2005,2006,2007,2008,2010,2012,2014,2016,2017,2018
./lib/isc/include/isc/bufferlist.h C 1999,2000,2001,2004,2005,2006,2007,2016,2018
@@ -3670,7 +3668,6 @@
./lib/isc/sha1.c C 2000,2001,2003,2004,2005,2007,2009,2011,2012,2014,2016,2017,2018
./lib/isc/sha2.c C 2005,2006,2007,2009,2011,2012,2014,2016,2017,2018
./lib/isc/sockaddr.c C 1999,2000,2001,2002,2003,2004,2005,2006,2007,2010,2011,2012,2014,2015,2016,2017,2018
./lib/isc/socket_api.c C 2009,2011,2012,2013,2014,2015,2016,2018
./lib/isc/sparc64/Makefile.in MAKE 2007,2012,2016,2018
./lib/isc/sparc64/include/Makefile.in MAKE 2007,2012,2016,2018
./lib/isc/sparc64/include/isc/Makefile.in MAKE 2007,2012,2015,2016,2018