From: Aki Tuomi Date: Mon, 26 Nov 2018 16:57:02 +0000 (+0200) Subject: auth: auth-worker-client - Internalize auth_worker_client X-Git-Tag: 2.3.9~1058 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f02b659738aa6f12323147d0bc539bfda11bd2ff;p=thirdparty%2Fdovecot%2Fcore.git auth: auth-worker-client - Internalize auth_worker_client --- diff --git a/src/auth/auth-worker-client.c b/src/auth/auth-worker-client.c index db183eb965..dd5c3753a5 100644 --- a/src/auth/auth-worker-client.c +++ b/src/auth/auth-worker-client.c @@ -46,11 +46,13 @@ struct auth_worker_list_context { bool sending, sent, done; }; -struct auth_worker_client *auth_worker_client; +static struct auth_worker_client *auth_worker_client = NULL; static bool auth_worker_client_error = FALSE; static void auth_worker_input(struct auth_worker_client *client); static int auth_worker_output(struct auth_worker_client *client); +static void auth_worker_client_destroy(struct auth_worker_client **_client); +static void auth_worker_client_unref(struct auth_worker_client **_client); void auth_worker_refresh_proctitle(const char *state) { @@ -824,7 +826,7 @@ auth_worker_client_create(struct auth *auth, return client; } -void auth_worker_client_destroy(struct auth_worker_client **_client) +static void auth_worker_client_destroy(struct auth_worker_client **_client) { struct auth_worker_client *client = *_client; @@ -847,7 +849,7 @@ void auth_worker_client_destroy(struct auth_worker_client **_client) master_service_client_connection_destroyed(master_service); } -void auth_worker_client_unref(struct auth_worker_client **_client) +static void auth_worker_client_unref(struct auth_worker_client **_client) { struct auth_worker_client *client = *_client; @@ -891,3 +893,15 @@ void auth_worker_client_send_shutdown(void) o_stream_nsend_str(auth_worker_client->output, "SHUTDOWN\n"); auth_worker_refresh_proctitle(CLIENT_STATE_STOP); } + +void auth_worker_connections_destroy_all(void) +{ + if (auth_worker_client == NULL) + return; + auth_worker_client_destroy(&auth_worker_client); +} + +bool auth_worker_has_client(void) +{ + return auth_worker_client != NULL; +} diff --git a/src/auth/auth-worker-client.h b/src/auth/auth-worker-client.h index 99ec8e6a14..8c8ea90c34 100644 --- a/src/auth/auth-worker-client.h +++ b/src/auth/auth-worker-client.h @@ -6,18 +6,18 @@ #define AUTH_WORKER_MAX_LINE_LENGTH 8192 struct master_service_connection; -extern struct auth_worker_client *auth_worker_client; struct auth_worker_client * auth_worker_client_create(struct auth *auth, const struct master_service_connection *master_conn); bool auth_worker_auth_request_new(struct auth_worker_client *client, unsigned int id, const char *const *args, struct auth_request **request_r); -void auth_worker_client_destroy(struct auth_worker_client **client); -void auth_worker_client_unref(struct auth_worker_client **client); +bool auth_worker_has_client(void); void auth_worker_client_send_error(void); void auth_worker_client_send_success(void); void auth_worker_client_send_shutdown(void); +void auth_worker_connections_destroy_all(void); + #endif diff --git a/src/auth/main.c b/src/auth/main.c index cc7fb3442c..2dbf9e176b 100644 --- a/src/auth/main.c +++ b/src/auth/main.c @@ -279,9 +279,7 @@ static void main_deinit(void) auth_client_connections_destroy_all(); auth_master_connections_destroy_all(); auth_postfix_connections_destroy_all(); - - if (auth_worker_client != NULL) - auth_worker_client_destroy(&auth_worker_client); + auth_worker_connections_destroy_all(); auth_policy_deinit(); mech_register_deinit(&mech_reg); @@ -308,7 +306,7 @@ static void main_deinit(void) static void worker_connected(struct master_service_connection *conn) { - if (auth_worker_client != NULL) { + if (auth_worker_has_client()) { i_error("Auth workers can handle only a single client"); return; }