Skip to content

Commit

Permalink
Do not use machinarium API while holding lock (#599)
Browse files Browse the repository at this point in the history
  • Loading branch information
reshke authored Mar 22, 2024
1 parent f511a78 commit 4ec78b7
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions sources/router.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down

0 comments on commit 4ec78b7

Please sign in to comment.