Commit 43797e57 authored by Ondřej Surý's avatar Ondřej Surý Committed by Ondřej Surý
Browse files

Remove support for external applications to register libisc

The previous versions of BIND 9 exported its internal libraries so that they can
be used by third-party applications more easily.  Certain library functions were
altered from specific BIND-only behavior to more generic behavior when used by
other applications.

This commit removes the function isc_lib_register() that was used by external
applications to enable the functionality.
parent 62971d4a
Pipeline #49821 failed with stages
in 62 minutes and 33 seconds
......@@ -32,7 +32,6 @@
#include <isc/base64.h>
#include <isc/buffer.h>
#include <isc/hex.h>
#include <isc/lib.h>
#include <isc/log.h>
#include <isc/md.h>
#include <isc/mem.h>
......@@ -1748,7 +1747,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);
......
......@@ -25,7 +25,6 @@
#include <isc/buffer.h>
#include <isc/hash.h>
#include <isc/ht.h>
#include <isc/lib.h>
#include <isc/log.h>
#include <isc/mem.h>
#include <isc/netaddr.h>
......
......@@ -17,7 +17,6 @@
#include <isc/commandline.h>
#include <isc/hash.h>
#include <isc/lib.h>
#include <isc/mem.h>
#include <isc/util.h>
......@@ -80,7 +79,6 @@ dyndb_init(isc_mem_t *mctx, const char *name, const char *parameters,
* to initialize libisc/libdns
*/
if (dctx->refvar != &isc_bind9) {
isc_lib_register();
isc_log_setcontext(dctx->lctx);
dns_log_setcontext(dctx->lctx);
isc_hash_set_initializer(dctx->hashinit);
......
......@@ -40,7 +40,7 @@ struct dns_dyndbctx {
dns_zonemgr_t * zmgr;
isc_task_t * task;
isc_timermgr_t *timermgr;
bool * refvar;
const bool * refvar;
};
#define DNS_DYNDBCTX_MAGIC ISC_MAGIC('D', 'd', 'b', 'c')
......
......@@ -41,7 +41,6 @@ libisc_la_HEADERS = \
include/isc/iterated_hash.h \
include/isc/lang.h \
include/isc/lex.h \
include/isc/lib.h \
include/isc/likely.h \
include/isc/list.h \
include/isc/log.h \
......@@ -176,7 +175,6 @@ libisc_la_SOURCES = \
httpd.c \
iterated_hash.c \
lex.c \
lib.c \
log.c \
md.c \
mem.c \
......
......@@ -255,7 +255,7 @@ isc_app_ctxrun(isc_appctx_t *ctx) {
/*
* 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);
}
#endif /* WIN32 */
......@@ -290,53 +290,34 @@ isc_app_ctxrun(isc_appctx_t *ctx) {
}
}
#else /* WIN32 */
if (isc_bind9) {
sigset_t sset;
int sig;
/*
* 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)
{
char strbuf[ISC_STRERRORSIZE];
strerror_r(errno, strbuf, sizeof(strbuf));
isc_error_fatal(__FILE__, __LINE__,
"isc_app_run() sigsetops: %s",
strbuf);
}
sigset_t sset;
int sig;
/*
* 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)
{
char strbuf[ISC_STRERRORSIZE];
strerror_r(errno, strbuf, sizeof(strbuf));
isc_error_fatal(__FILE__, __LINE__,
"isc_app_run() sigsetops: %s", strbuf);
}
if (sigwait(&sset, &sig) == 0) {
switch (sig) {
case SIGINT:
case SIGTERM:
atomic_store_release(
&ctx->want_shutdown, true);
break;
case SIGHUP:
atomic_store_release(&ctx->want_reload,
true);
break;
default:
INSIST(0);
ISC_UNREACHABLE();
}
}
} else {
/*
* External, or BIND9 using multiple contexts:
* wait until woken up.
*/
if (atomic_load_acquire(&ctx->want_shutdown)) {
if (sigwait(&sset, &sig) == 0) {
switch (sig) {
case SIGINT:
case SIGTERM:
atomic_store_release(&ctx->want_shutdown, true);
break;
}
if (!atomic_load_acquire(&ctx->want_reload)) {
LOCK(&ctx->readylock);
WAIT(&ctx->ready, &ctx->readylock);
UNLOCK(&ctx->readylock);
case SIGHUP:
atomic_store_release(&ctx->want_reload, true);
break;
default:
INSIST(0);
ISC_UNREACHABLE();
}
}
#endif /* WIN32 */
......@@ -388,10 +369,10 @@ isc_app_ctxshutdown(isc_appctx_t *ctx) {
#ifdef WIN32
SetEvent(ctx->hEvents[SHUTDOWN_EVENT]);
#else /* WIN32 */
if (isc_bind9 && ctx != &isc_g_appctx) {
if (ctx != &isc_g_appctx) {
/* BIND9 internal, but using multiple contexts */
atomic_store_release(&ctx->want_shutdown, true);
} else if (isc_bind9) {
} else {
/* BIND9 internal, single context */
if (kill(getpid(), SIGTERM) < 0) {
char strbuf[ISC_STRERRORSIZE];
......@@ -401,10 +382,6 @@ isc_app_ctxshutdown(isc_appctx_t *ctx) {
"kill: %s",
strbuf);
}
} else {
/* External, multiple contexts */
atomic_store_release(&ctx->want_shutdown, true);
SIGNAL(&ctx->ready);
}
#endif /* WIN32 */
}
......@@ -428,10 +405,10 @@ isc_app_ctxsuspend(isc_appctx_t *ctx) {
#ifdef WIN32
SetEvent(ctx->hEvents[RELOAD_EVENT]);
#else /* WIN32 */
if (isc_bind9 && ctx != &isc_g_appctx) {
if (ctx != &isc_g_appctx) {
/* BIND9 internal, but using multiple contexts */
atomic_store_release(&ctx->want_reload, true);
} else if (isc_bind9) {
} else {
/* BIND9 internal, single context */
if (kill(getpid(), SIGHUP) < 0) {
char strbuf[ISC_STRERRORSIZE];
......@@ -441,10 +418,6 @@ isc_app_ctxsuspend(isc_appctx_t *ctx) {
"kill: %s",
strbuf);
}
} else {
/* External, multiple contexts */
atomic_store_release(&ctx->want_reload, true);
SIGNAL(&ctx->ready);
}
#endif /* WIN32 */
}
......
......@@ -15,11 +15,4 @@
#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 true
* and remains unchanged for BIND9 and related tools; export library
* clients will run isc_lib_register(), which sets it to false,
* overriding certain BIND9 behaviors.
*/
LIBISC_EXTERNAL_DATA bool isc_bind9 = true;
LIBISC_EXTERNAL_DATA const bool isc_bind9 = true;
......@@ -9,19 +9,10 @@
* information regarding copyright ownership.
*/
#ifndef ISC_BIND9_H
#define ISC_BIND9_H 1
#pragma once
#include <stdbool.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 true at runtime. Export library clients
* will call isc_lib_register(), which will set it to false.
*/
LIBISC_EXTERNAL_DATA extern bool isc_bind9;
#endif /* ISC_BIND9_H */
LIBISC_EXTERNAL_DATA extern const bool isc_bind9;
/*
* 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_LIB_H
#define ISC_LIB_H 1
/*! \file isc/lib.h */
#include <isc/lang.h>
#include <isc/types.h>
ISC_LANG_BEGINDECLS
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 */
/*
* 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 <isc/bind9.h>
#include <isc/lib.h>
/***
*** Functions
***/
void
isc_lib_register(void) {
isc_bind9 = false;
}
......@@ -14,7 +14,6 @@
#include <stddef.h>
#include <stdlib.h>
#include <isc/lib.h>
#include <isc/once.h>
#include <isc/resultclass.h>
#include <isc/rwlock.h>
......
......@@ -324,7 +324,6 @@ isc_lex_setsourceline
isc_lex_setsourcename
isc_lex_setspecials
isc_lex_ungettoken
isc_lib_register
isc_log_categorybyname
isc_log_closefilelogs
isc_log_create
......
......@@ -25,7 +25,6 @@
#include <isc/attributes.h>
#include <isc/buffer.h>
#include <isc/commandline.h>
#include <isc/lib.h>
#include <isc/mem.h>
#include <isc/print.h>
#include <isc/sockaddr.h>
......@@ -1085,7 +1084,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);
......
......@@ -28,7 +28,6 @@
#include <isc/base64.h>
#include <isc/buffer.h>
#include <isc/commandline.h>
#include <isc/lib.h>
#include <isc/mem.h>
#include <isc/print.h>
#include <isc/sockaddr.h>
......@@ -354,7 +353,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);
......
......@@ -26,7 +26,6 @@
#include <isc/attributes.h>
#include <isc/buffer.h>
#include <isc/commandline.h>
#include <isc/lib.h>
#include <isc/mem.h>
#include <isc/print.h>
#include <isc/sockaddr.h>
......@@ -328,7 +327,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);
......
......@@ -26,7 +26,6 @@
#include <isc/base64.h>
#include <isc/buffer.h>
#include <isc/commandline.h>
#include <isc/lib.h>
#include <isc/mem.h>
#include <isc/print.h>
#include <isc/sockaddr.h>
......@@ -172,7 +171,6 @@ main(int argc, char *argv[]) {
usage();
}
isc_lib_register();
result = dns_lib_init();
if (result != ISC_R_SUCCESS) {
fprintf(stderr, "dns_lib_init failed: %u\n", result);
......
......@@ -29,7 +29,6 @@
#include <isc/buffer.h>
#include <isc/commandline.h>
#include <isc/lex.h>
#include <isc/lib.h>
#include <isc/mem.h>
#include <isc/parseint.h>
#include <isc/print.h>
......@@ -238,7 +237,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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment