From 4ec78b737bab150ffb4dfb183ac2a0be0a2ff3b7 Mon Sep 17 00:00:00 2001 From: reshke Date: Fri, 22 Mar 2024 19:34:42 +0500 Subject: [PATCH] Do not use machinarium API while holding lock (#599) --- sources/router.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/sources/router.c b/sources/router.c index cb0b7c6fd..905ae4ed0 100644 --- a/sources/router.c +++ b/sources/router.c @@ -344,6 +344,17 @@ od_router_status_t od_router_route(od_router_t *router, od_client_t *client) kiwi_be_startup_t *startup = &client->startup; od_instance_t *instance = router->global->instance; + struct sockaddr_storage sa; + int salen; + struct sockaddr *saddr; + int rc; + salen = sizeof(sa); + saddr = (struct sockaddr *)&sa; + rc = machine_getpeername(client->io.io, saddr, &salen); + if (rc == -1) { + return OD_ROUTER_ERROR; + } + /* match route */ assert(startup->database.value_len); assert(startup->user.value_len); @@ -354,23 +365,12 @@ od_router_status_t od_router_route(od_router_t *router, od_client_t *client) od_rule_t *rule = NULL; // initialize rule for (line 365) and flag '-Wmaybe-uninitialized' - struct sockaddr_storage sa; - int salen; - struct sockaddr *saddr; - int rc; switch (client->type) { case OD_POOL_CLIENT_INTERNAL: rule = od_rules_forward(&router->rules, startup->database.value, startup->user.value, NULL, 1); break; case OD_POOL_CLIENT_EXTERNAL: - salen = sizeof(sa); - saddr = (struct sockaddr *)&sa; - rc = machine_getpeername(client->io.io, saddr, &salen); - if (rc == -1) { - od_router_unlock(router); - return OD_ROUTER_ERROR; - } rule = od_rules_forward(&router->rules, startup->database.value, startup->user.value, &sa, 0); break;