From b1d611019f0cf0bee5f6a6b154cd51c393250b91 Mon Sep 17 00:00:00 2001 From: Ovchinnikov Andrew <63587191+AndrewOvvv@users.noreply.github.com> Date: Wed, 7 Feb 2024 13:43:13 +0300 Subject: [PATCH] fix warnings during building (#567) * make some functions from mdb_iamproxy.c static * fix new line symbol missing * make apply_fmt * fix warnings during building * make apply_fmt * fix issues --------- Co-authored-by: Andrey Ovchinnikov --- sources/frontend.c | 5 +++-- sources/hashmap.c | 1 + sources/instance.c | 1 - sources/logger.c | 6 ++++++ sources/mdb_iamproxy.c | 11 ++++++----- sources/mdb_iamproxy.h | 8 +------- sources/odyssey.h | 1 + sources/router.c | 6 +++++- sources/scram.c | 5 +++-- sources/stat.h | 2 +- 10 files changed, 27 insertions(+), 19 deletions(-) diff --git a/sources/frontend.c b/sources/frontend.c index a1f9432c..72e113dc 100644 --- a/sources/frontend.c +++ b/sources/frontend.c @@ -1561,8 +1561,9 @@ static inline od_frontend_status_t od_frontend_poll_catchup(od_client_t *client, int absent_heartbeat_checks = 0; while (route->last_heartbeat == 0) { machine_sleep(ODYSSEY_CATCHUP_RECHECK_INTERVAL); - if (absent_heartbeat_checks++ > - (timeout * 1000 / ODYSSEY_CATCHUP_RECHECK_INTERVAL)) { + if ((int64_t)absent_heartbeat_checks++ > // add cast to int64_t for correct camparison (int64_t > int and ibt64_t > uint32_t) + (int64_t)(timeout * 1000 / + ODYSSEY_CATCHUP_RECHECK_INTERVAL)) { od_debug(&instance->logger, "catchup", client, NULL, "No heartbeat for route detected\n"); return OD_ECATCHUP_TIMEOUT; diff --git a/sources/hashmap.c b/sources/hashmap.c index 9db6fbba..f250b1fe 100644 --- a/sources/hashmap.c +++ b/sources/hashmap.c @@ -249,6 +249,7 @@ od_hashmap_elt_t *od_hashmap_lock_key(od_hashmap_t *hm, od_hash_t keyhash, int od_hashmap_unlock_key(od_hashmap_t *hm, od_hash_t keyhash, od_hashmap_elt_t *key) { + (void)key; size_t bucket_index = keyhash % hm->size; pthread_mutex_unlock(&hm->buckets[bucket_index]->mu); return 0 /* OK */; diff --git a/sources/instance.c b/sources/instance.c index 02c3355b..95cb6ae0 100644 --- a/sources/instance.c +++ b/sources/instance.c @@ -90,7 +90,6 @@ void od_config_testing(od_instance_t *instance) error: od_router_free(&router); - return NOT_OK_RESPONSE; } static inline void od_bind_version() diff --git a/sources/logger.c b/sources/logger.c index f4a1e2b5..77718ef7 100644 --- a/sources/logger.c +++ b/sources/logger.c @@ -225,6 +225,12 @@ od_logger_format(od_logger_t *logger, od_logger_level_t level, char *context, dst_pos += len; break; } + + // fall throught fix (if client is not defined will write 'none' to log file) + len = od_snprintf(dst_pos, dst_end - dst_pos, + "none"); + dst_pos += len; + break; } /* unixtime */ case 'n': { diff --git a/sources/mdb_iamproxy.c b/sources/mdb_iamproxy.c index b65893d8..9c50f683 100644 --- a/sources/mdb_iamproxy.c +++ b/sources/mdb_iamproxy.c @@ -5,8 +5,9 @@ * Scalable PostgreSQL connection pooler. */ -#include #include +#include +#include #include #include #include @@ -58,7 +59,6 @@ machine_msg_t *mdb_iamproxy_io_read(machine_io_t *io) machine_msg_t *msg; uint64_t body_size = 0; - uint64_t received = 0; /* RECEIVE HEADER */ header = machine_read(io, MDB_IAMPROXY_DEFAULT_HEADER_SIZE, @@ -114,8 +114,10 @@ free_end: return send_result; } -int mdb_iamproxy_authenticate_user(const char *username, const char *token, - od_instance_t *instance, od_client_t *client) +int mdb_iamproxy_authenticate_user( + char *username, + char *token, // remove const because machine_msg_write use as buf - non constant values (but do nothing ith them....) + od_instance_t *instance, od_client_t *client) { int32_t authentication_result = MDB_IAMPROXY_CONN_DENIED; // stores authenticate status for user (default value: CONN_DENIED) @@ -246,7 +248,6 @@ int mdb_iamproxy_authenticate_user(const char *username, const char *token, client->id.id, client->external_id); /*FREE RESOURCES*/ -free_external_user: machine_msg_free(external_user); free_auth_status: machine_msg_free(auth_status); diff --git a/sources/mdb_iamproxy.h b/sources/mdb_iamproxy.h index 00ca3f89..797fbde2 100644 --- a/sources/mdb_iamproxy.h +++ b/sources/mdb_iamproxy.h @@ -1,13 +1,7 @@ #ifndef ODYSSEY_IAMPROXY_H #define ODYSSEY_IAMPROXY_H -/* - * Odyssey. - * - * Scalable PostgreSQL connection pooler. - */ - -int mdb_iamproxy_authenticate_user(const char *username, const char *token, +int mdb_iamproxy_authenticate_user(char *username, char *token, od_instance_t *instance, od_client_t *client); diff --git a/sources/odyssey.h b/sources/odyssey.h index 4e3aaae2..0d8c3c38 100644 --- a/sources/odyssey.h +++ b/sources/odyssey.h @@ -149,4 +149,5 @@ #include "sources/frontend.h" #include "sources/backend.h" +#include "sources/mdb_iamproxy.h" #endif /* ODYSSEY_H */ diff --git a/sources/router.c b/sources/router.c index e969c44b..0c0aa6f4 100644 --- a/sources/router.c +++ b/sources/router.c @@ -27,6 +27,7 @@ void od_router_init(od_router_t *router, od_global_t *global) static inline int od_router_immed_close_server_cb(od_server_t *server, void **argv) { + (void)argv; od_route_t *route = server->route; /* remove server for server pool */ od_pg_server_pool_set(&route->server_pool, server, OD_SERVER_UNDEF); @@ -347,7 +348,8 @@ od_router_status_t od_router_route(od_router_t *router, od_client_t *client) od_router_lock(router); /* match latest version of route rule */ - od_rule_t *rule; + od_rule_t *rule = + NULL; // initialize rule for (line 365) and flag '-Wmaybe-uninitialized' switch (client->type) { case OD_POOL_CLIENT_INTERNAL: rule = od_rules_forward(&router->rules, startup->database.value, @@ -357,6 +359,8 @@ od_router_status_t od_router_route(od_router_t *router, od_client_t *client) rule = od_rules_forward(&router->rules, startup->database.value, startup->user.value, 0); break; + case OD_POOL_CLIENT_UNDEF: // create that case for correct work of '-Wswitch' flag + break; } if (rule == NULL) { diff --git a/sources/scram.c b/sources/scram.c index f2f0129e..361ab675 100644 --- a/sources/scram.c +++ b/sources/scram.c @@ -641,8 +641,9 @@ int od_scram_read_client_final_message(machine_io_t *io, /*channel binding check*/ /* Fetch hash data of server's SSL certificate */ - scram_rc = - machine_tls_cert_hash(io, &cbind_data, &cbind_data_len); + scram_rc = machine_tls_cert_hash( + io, &cbind_data, + (uint32_t *)&cbind_data_len); // TODO: maybe rework of machinarium beacuse it's strange that we use size_t here and uint32_t in machinarium /* should not happen */ if (scram_rc != OK_RESPONSE) { diff --git a/sources/stat.h b/sources/stat.h index c9cb472b..880686fd 100644 --- a/sources/stat.h +++ b/sources/stat.h @@ -149,7 +149,7 @@ static inline void od_stat_update_of(od_atomic_u64_t *prev, { /* todo: this could be made more optimal */ /* prev <= current */ - __atomic_store(prev, current, __ATOMIC_SEQ_CST); + __atomic_store((uint64_t *)prev, (uint64_t *)current, __ATOMIC_SEQ_CST); } static inline void od_stat_update(od_stat_t *dst, od_stat_t *stat)