]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
lib/isc/app_api.c: Protect the global is_running bool variable with a mutex
authorOndřej Surý <ondrej@sury.org>
Mon, 5 Aug 2019 07:46:04 +0000 (09:46 +0200)
committerOndřej Surý <ondrej@sury.org>
Tue, 6 Aug 2019 13:03:35 +0000 (15:03 +0200)
lib/isc/app_api.c
lib/isc/unix/app.c

index 425eb5ab92584eb6f53da5143919c515bb76e8c8..4fcd2ec9d594a350bfea56df0a56659c640a0278 100644 (file)
@@ -24,6 +24,7 @@
 static isc_mutex_t createlock;
 static isc_once_t once = ISC_ONCE_INIT;
 static isc_appctxcreatefunc_t appctx_createfunc = NULL;
+static isc_mutex_t runninglock;
 static bool is_running = false;
 
 #define ISCAPI_APPMETHODS_VALID(m) ISC_MAGIC_VALID(m, ISCAPI_APPMETHODS_MAGIC)
@@ -31,6 +32,7 @@ static bool is_running = false;
 static void
 initialize(void) {
        RUNTIME_CHECK(isc_mutex_init(&createlock) == ISC_R_SUCCESS);
+       RUNTIME_CHECK(isc_mutex_init(&runninglock) == ISC_R_SUCCESS);
 }
 
 isc_result_t
@@ -197,9 +199,15 @@ isc_app_run() {
        if (isc_bind9) {
                isc_result_t result;
 
+               RUNTIME_CHECK(isc_once_do(&once, initialize) == ISC_R_SUCCESS);
+
+               LOCK(&runninglock);
                is_running = true;
+               UNLOCK(&runninglock);
                result = isc__app_run();
+               LOCK(&runninglock);
                is_running = false;
+               UNLOCK(&runninglock);
 
                return (result);
        }
@@ -209,7 +217,15 @@ isc_app_run() {
 
 bool
 isc_app_isrunning() {
-       return (is_running);
+       bool running;
+
+       RUNTIME_CHECK(isc_once_do(&once, initialize) == ISC_R_SUCCESS);
+
+       LOCK(&runninglock);
+       running = is_running;
+       UNLOCK(&runninglock);
+
+       return (running);
 }
 
 isc_result_t
index 7e5a0ee0a239d0fcbb47bc753ef6cad1fdccf47b..068e053fde438fa38d4d837081f3e8a0c05edf77 100644 (file)
@@ -101,19 +101,19 @@ typedef struct isc__appctx {
        isc_mem_t               *mctx;
        isc_mutex_t             lock;
        isc_eventlist_t         on_run;
-       bool            shutdown_requested;
-       bool            running;
+       bool                    shutdown_requested;
+       bool                    running;
 
        /*!
         * We assume that 'want_shutdown' can be read and written atomically.
         */
-       bool            want_shutdown;
+       bool                    want_shutdown;
        /*
         * We assume that 'want_reload' can be read and written atomically.
         */
-       bool            want_reload;
+       bool                    want_reload;
 
-       bool            blocked;
+       bool                    blocked;
 
        isc_taskmgr_t           *taskmgr;
        isc_socketmgr_t         *socketmgr;