From: Kern Sibbald Date: Sun, 14 Oct 2018 14:08:39 +0000 (+0200) Subject: Cleanup some bnet_server calls X-Git-Tag: Release-9.4.0~51 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7726f22c2aa5e2ed2e9c46f39f6fbc37063370f2;p=thirdparty%2Fbacula.git Cleanup some bnet_server calls --- diff --git a/bacula/src/dird/dird.c b/bacula/src/dird/dird.c index 38249f3ad2..f06be79ebf 100644 --- a/bacula/src/dird/dird.c +++ b/bacula/src/dird/dird.c @@ -1,7 +1,7 @@ /* Bacula(R) - The Network Backup Solution - Copyright (C) 2000-2017 Kern Sibbald + Copyright (C) 2000-2018 Kern Sibbald The original author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. @@ -48,8 +48,8 @@ extern bool parse_dir_config(CONFIG *config, const char *configfile, int exit_co /* Imported subroutines */ JCR *wait_for_next_job(char *runjob); void term_scheduler(); -void term_ua_server(); void start_UA_server(dlist *addrs); +void stop_UA_server(); void init_job_server(int max_workers); void term_job_server(); void store_jobtype(LEX *lc, RES_ITEM *item, int index, int pass); @@ -706,7 +706,7 @@ void terminate_dird(int sig) delete config; config = NULL; } - term_ua_server(); + stop_UA_server(); term_msg(); /* terminate message handler */ cleanup_crypto(); diff --git a/bacula/src/dird/ua_server.c b/bacula/src/dird/ua_server.c index f116fbb905..56cfecba4b 100644 --- a/bacula/src/dird/ua_server.c +++ b/bacula/src/dird/ua_server.c @@ -1,7 +1,7 @@ /* Bacula(R) - The Network Backup Solution - Copyright (C) 2000-2015 Kern Sibbald + Copyright (C) 2000-2018 Kern Sibbald The original author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. @@ -36,7 +36,9 @@ static void *handle_UA_client_request(void *arg); /* Global variables */ -static int started = FALSE; +static bool started = false; +static pthread_t server_tid; +static bool server_tid_valid = false; static workq_t ua_workq; struct s_addr_port { @@ -58,16 +60,27 @@ void start_UA_server(dlist *addrs) berrno be; Emsg1(M_ABORT, 0, _("Cannot create UA thread: %s\n"), be.bstrerror(status)); } - started = TRUE; + started = true; return; } +void stop_UA_server() +{ + if (started && server_tid_valid) { + server_tid_valid = false; + bnet_stop_thread_server(server_tid); + } +} + extern "C" void *connect_thread(void *arg) { pthread_detach(pthread_self()); set_jcr_in_tsd(INVALID_JCR); + server_tid = pthread_self(); + server_tid_valid = true; + /* Permit MaxConsoleConnect console connections */ bnet_thread_server((dlist*)arg, director->MaxConsoleConnect, &ua_workq, handle_UA_client_request); return NULL; @@ -216,14 +229,3 @@ void free_ua_context(UAContext *ua) free_bsock(ua->UA_sock); free(ua); } - - -/* - * Called from main Bacula thread - */ -void term_ua_server() -{ - if (!started) { - return; - } -} diff --git a/bacula/src/lib/workq.c b/bacula/src/lib/workq.c index 115db7ebdc..b41bd4a2d1 100644 --- a/bacula/src/lib/workq.c +++ b/bacula/src/lib/workq.c @@ -1,7 +1,7 @@ /* Bacula(R) - The Network Backup Solution - Copyright (C) 2000-2017 Kern Sibbald + Copyright (C) 2000-2018 Kern Sibbald The original author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. @@ -101,7 +101,7 @@ int workq_init(workq_t *wq, int threads, void *(*engine)(void *arg)) return 0; } -/* [B +/* * Destroy a work queue * * Returns: 0 on success diff --git a/bacula/src/stored/stored.c b/bacula/src/stored/stored.c index da71b2c8b3..66430b0b88 100644 --- a/bacula/src/stored/stored.c +++ b/bacula/src/stored/stored.c @@ -1,7 +1,7 @@ /* Bacula(R) - The Network Backup Solution - Copyright (C) 2000-2017 Kern Sibbald + Copyright (C) 2000-2018 Kern Sibbald The original author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. @@ -779,6 +779,7 @@ void terminate_stored(int sig) } } if (server_tid_valid) { + server_tid_valid = false; bnet_stop_thread_server(server_tid); }