summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorJoerg Jung <jung@cvs.openbsd.org>2020-02-19 20:57:11 +0000
committerJoerg Jung <jung@cvs.openbsd.org>2020-02-19 20:57:11 +0000
commit8618cda76cfa6d396e9463f0fc41fb67395d7c21 (patch)
treebcf70fa17232e7c967ed30b4ba9ba674c2878555 /usr.bin
parent444a76bf65212deb09888c23aaea7d99a9a8a076 (diff)
simplify signal setup and remove block/unblock/is_running/reload
with input from florian ok millert florian
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/dig/dighost.c8
-rw-r--r--usr.bin/dig/lib/isc/include/isc/app.h43
-rw-r--r--usr.bin/dig/lib/isc/include/isc/result.h4
-rw-r--r--usr.bin/dig/lib/isc/unix/app.c137
-rw-r--r--usr.bin/dig/nslookup.c4
5 files changed, 7 insertions, 189 deletions
diff --git a/usr.bin/dig/dighost.c b/usr.bin/dig/dighost.c
index afc2c749059..185bc8d515d 100644
--- a/usr.bin/dig/dighost.c
+++ b/usr.bin/dig/dighost.c
@@ -14,7 +14,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
-/* $Id: dighost.c,v 1.10 2020/02/16 21:11:02 florian Exp $ */
+/* $Id: dighost.c,v 1.11 2020/02/19 20:57:10 jung Exp $ */
/*! \file
* \note
@@ -3792,14 +3792,8 @@ isc_result_t
get_address(char *host, in_port_t myport, isc_sockaddr_t *sockaddr) {
int count;
isc_result_t result;
- isc_boolean_t is_running;
- is_running = isc_app_isrunning();
- if (is_running)
- isc_app_block();
result = get_addresses(host, myport, sockaddr, 1, &count);
- if (is_running)
- isc_app_unblock();
if (result != ISC_R_SUCCESS)
return (result);
diff --git a/usr.bin/dig/lib/isc/include/isc/app.h b/usr.bin/dig/lib/isc/include/isc/app.h
index d403b5c0ea3..3cc6bd9f96d 100644
--- a/usr.bin/dig/lib/isc/include/isc/app.h
+++ b/usr.bin/dig/lib/isc/include/isc/app.h
@@ -14,7 +14,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
-/* $Id: app.h,v 1.5 2020/02/18 18:11:27 florian Exp $ */
+/* $Id: app.h,v 1.6 2020/02/19 20:57:10 jung Exp $ */
#ifndef ISC_APP_H
#define ISC_APP_H 1
@@ -137,17 +137,6 @@ isc_app_run(void);
*
* Returns:
*\li ISC_R_SUCCESS Shutdown has been requested.
- *\li ISC_R_RELOAD Reload has been requested.
- */
-
-isc_boolean_t
-isc_app_isrunning(void);
-/*!<
- * \brief Return if the ISC library application is running.
- *
- * Returns:
- *\li ISC_TRUE App is running.
- *\li ISC_FALSE App is not running.
*/
isc_result_t
@@ -168,36 +157,6 @@ isc_app_shutdown(void);
*\li ISC_R_UNEXPECTED
*/
-void
-isc_app_block(void);
-/*!<
- * \brief Indicate that a blocking operation will be performed.
- *
- * Notes:
- *\li If a blocking operation is in process, a call to isc_app_shutdown()
- * or an external signal will abort the program, rather than allowing
- * clean shutdown. This is primarily useful for reading user input.
- *
- * Requires:
- * \li isc_app_start() has been called.
- * \li No other blocking operations are in progress.
- */
-
-void
-isc_app_unblock(void);
-/*!<
- * \brief Indicate that a blocking operation is complete.
- *
- * Notes:
- * \li When a blocking operation has completed, return the program to a
- * state where a call to isc_app_shutdown() or an external signal will
- * shutdown normally.
- *
- * Requires:
- * \li isc_app_start() has been called.
- * \li isc_app_block() has been called by the same thread.
- */
-
/*%<
* See isc_appctx_create() above.
*/
diff --git a/usr.bin/dig/lib/isc/include/isc/result.h b/usr.bin/dig/lib/isc/include/isc/result.h
index fb60389185f..ae82a68788a 100644
--- a/usr.bin/dig/lib/isc/include/isc/result.h
+++ b/usr.bin/dig/lib/isc/include/isc/result.h
@@ -14,7 +14,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
-/* $Id: result.h,v 1.2 2020/02/13 13:53:01 jsg Exp $ */
+/* $Id: result.h,v 1.3 2020/02/19 20:57:10 jung Exp $ */
#ifndef ISC_RESULT_H
#define ISC_RESULT_H 1
@@ -39,8 +39,6 @@
#define ISC_R_NORESOURCES 13 /*%< not enough free resources */
#define ISC_R_EOF 14 /*%< end of file */
#define ISC_R_BOUND 15 /*%< socket already bound */
-#define ISC_R_RELOAD 16 /*%< reload */
-#define ISC_R_SUSPEND ISC_R_RELOAD /*%< alias of 'reload' */
#define ISC_R_LOCKBUSY 17 /*%< lock busy */
#define ISC_R_EXISTS 18 /*%< already exists */
#define ISC_R_NOSPACE 19 /*%< ran out of space */
diff --git a/usr.bin/dig/lib/isc/unix/app.c b/usr.bin/dig/lib/isc/unix/app.c
index e06046316e2..95b5e1ab81a 100644
--- a/usr.bin/dig/lib/isc/unix/app.c
+++ b/usr.bin/dig/lib/isc/unix/app.c
@@ -55,12 +55,6 @@ typedef struct isc_appctx {
* We assume that 'want_shutdown' can be read and written atomically.
*/
isc_boolean_t want_shutdown;
- /*
- * We assume that 'want_reload' can be read and written atomically.
- */
- isc_boolean_t want_reload;
-
- isc_boolean_t blocked;
isc_taskmgr_t *taskmgr;
isc_socketmgr_t *socketmgr;
@@ -68,41 +62,12 @@ typedef struct isc_appctx {
} isc_appctx_t;
static isc_appctx_t isc_g_appctx;
-static isc_boolean_t is_running = ISC_FALSE;
static isc_result_t isc_app_ctxonrun(isc_appctx_t *ctx, isc_task_t *task,
isc_taskaction_t action, void *arg);
-static void
-reload_action(int arg) {
- UNUSED(arg);
- isc_g_appctx.want_reload = ISC_TRUE;
-}
-
-static isc_result_t
-handle_signal(int sig, void (*handler)(int)) {
- struct sigaction sa;
-
- memset(&sa, 0, sizeof(sa));
- sa.sa_handler = handler;
-
- if (sigfillset(&sa.sa_mask) != 0 ||
- sigaction(sig, &sa, NULL) < 0) {
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- "handle_signal() %d setup: %s", sig,
- strerror(errno));
- return (ISC_R_UNEXPECTED);
- }
-
- return (ISC_R_SUCCESS);
-}
-
static isc_result_t
isc_app_ctxstart(isc_appctx_t *ctx) {
- isc_result_t result;
- int presult;
- sigset_t sset;
-
/*
* Start an ISC library application.
*/
@@ -112,66 +77,14 @@ isc_app_ctxstart(isc_appctx_t *ctx) {
ctx->shutdown_requested = ISC_FALSE;
ctx->running = ISC_FALSE;
ctx->want_shutdown = ISC_FALSE;
- ctx->want_reload = ISC_FALSE;
- ctx->blocked = ISC_FALSE;
-
- /*
- * Always ignore SIGPIPE.
- */
- result = handle_signal(SIGPIPE, SIG_IGN);
- if (result != ISC_R_SUCCESS)
- goto cleanup;
-
- /*
- * On Solaris 2, delivery of a signal whose action is SIG_IGN
- * will not cause sigwait() to return. We may have inherited
- * unexpected actions for SIGHUP, SIGINT, and SIGTERM from our parent
- * process (e.g, Solaris cron). Set an action of SIG_DFL to make
- * sure sigwait() works as expected. Only do this for SIGTERM and
- * SIGINT if we don't have sigwait(), since a different handler is
- * installed above.
- */
- result = handle_signal(SIGHUP, SIG_DFL);
- if (result != ISC_R_SUCCESS)
- goto cleanup;
-
- result = handle_signal(SIGTERM, SIG_DFL);
- if (result != ISC_R_SUCCESS)
- goto cleanup;
- result = handle_signal(SIGINT, SIG_DFL);
- if (result != ISC_R_SUCCESS)
- goto cleanup;
- /*
- * Unblock SIGHUP, SIGINT, SIGTERM.
- *
- * If we're not using threads, we need to make sure that SIGHUP,
- * SIGINT and SIGTERM are not inherited as blocked from the parent
- * process.
- */
- if (sigemptyset(&sset) != 0 ||
- sigaddset(&sset, SIGHUP) != 0 ||
- sigaddset(&sset, SIGINT) != 0 ||
- sigaddset(&sset, SIGTERM) != 0) {
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- "isc_app_start() sigsetops: %s",
- strerror(errno));
- result = ISC_R_UNEXPECTED;
- goto cleanup;
- }
- presult = sigprocmask(SIG_UNBLOCK, &sset, NULL);
- if (presult != 0) {
+ if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
- "isc_app_start() sigprocmask: %s",
+ "isc_app_ctxstart() signal: %s",
strerror(errno));
- result = ISC_R_UNEXPECTED;
- goto cleanup;
+ return ISC_R_UNEXPECTED;
}
-
- return (ISC_R_SUCCESS);
-
- cleanup:
- return (result);
+ return ISC_R_SUCCESS;
}
isc_result_t
@@ -238,19 +151,6 @@ evloop(isc_appctx_t *ctx) {
isc_boolean_t readytasks;
isc_boolean_t call_timer_dispatch = ISC_FALSE;
- /*
- * 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,
- * - there is thus currently no active task, and
- * - there is a timer event
- */
- if (ctx->want_reload) {
- ctx->want_reload = ISC_FALSE;
- return (ISC_R_RELOAD);
- }
-
readytasks = isc_taskmgr_ready(ctx->taskmgr);
if (readytasks) {
tv.tv_sec = 0;
@@ -325,12 +225,6 @@ isc_app_ctxrun(isc_appctx_t *ctx) {
}
- 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);
result = evloop(ctx);
return (result);
@@ -364,30 +258,7 @@ isc_app_ctxshutdown(isc_appctx_t *ctx) {
return (ISC_R_SUCCESS);
}
-isc_boolean_t
-isc_app_isrunning() {
- return (is_running);
-}
-
isc_result_t
isc_app_shutdown(void) {
return (isc_app_ctxshutdown((isc_appctx_t *)&isc_g_appctx));
}
-
-void
-isc_app_block(void) {
- REQUIRE(isc_g_appctx.running);
- REQUIRE(!isc_g_appctx.blocked);
-
- isc_g_appctx.blocked = ISC_TRUE;
-}
-
-void
-isc_app_unblock(void) {
-
- REQUIRE(isc_g_appctx.running);
- REQUIRE(isc_g_appctx.blocked);
-
- isc_g_appctx.blocked = ISC_FALSE;
-
-}
diff --git a/usr.bin/dig/nslookup.c b/usr.bin/dig/nslookup.c
index 5422aa8a08f..84b0543c4c1 100644
--- a/usr.bin/dig/nslookup.c
+++ b/usr.bin/dig/nslookup.c
@@ -725,10 +725,8 @@ do_next_command(char *input) {
setoption(arg);
else if ((strcasecmp(ptr, "server") == 0) ||
(strcasecmp(ptr, "lserver") == 0)) {
- isc_app_block();
set_nameserver(arg);
check_ra = ISC_FALSE;
- isc_app_unblock();
show_settings(ISC_TRUE, ISC_TRUE);
} else if (strcasecmp(ptr, "exit") == 0) {
in_use = ISC_FALSE;
@@ -753,14 +751,12 @@ get_next_command(void) {
buf = malloc(COMMSIZE);
if (buf == NULL)
fatal("memory allocation failure");
- isc_app_block();
if (interactive) {
fputs("> ", stderr);
fflush(stderr);
ptr = fgets(buf, COMMSIZE, stdin);
} else
ptr = fgets(buf, COMMSIZE, stdin);
- isc_app_unblock();
if (ptr == NULL) {
in_use = ISC_FALSE;
} else