From 1d930f46634911ea276c15218b044e0f3c9c2a59 Mon Sep 17 00:00:00 2001 From: Marko Kreen Date: Sun, 12 Aug 2007 21:19:12 +0000 Subject: [PATCH] varcache: remove overwrite arg, some logging cleanup --- Makefile | 5 +++++ src/client.c | 2 +- src/objects.c | 16 +++++++-------- src/proto.c | 13 +++++-------- src/server.c | 4 ++-- src/varcache.c | 53 +++++++++++++++----------------------------------- src/varcache.h | 3 +-- 7 files changed, 38 insertions(+), 58 deletions(-) diff --git a/Makefile b/Makefile index d163223..404de94 100644 --- a/Makefile +++ b/Makefile @@ -123,3 +123,8 @@ check: config.mak $(E) " CHECK" $(srcs) $(Q) sparse $(SPARCE_FLAGS) $(srcs) +pgbouncer.pg: + $(CC) -pg $(DEFS) -g -O2 $(CPPFLAGS) $(LDFLAGS) -o $@ $(srcs) $(LIBS) + +pg: pgbouncer.pg + diff --git a/src/client.c b/src/client.c index 0538980..d98cce6 100644 --- a/src/client.c +++ b/src/client.c @@ -111,7 +111,7 @@ static bool decide_startup_pool(PgSocket *client, MBuf *pkt) dbname = val; else if (strcmp(key, "user") == 0) username = val; - else if (varcache_set(&client->vars, key, val, true)) + else if (varcache_set(&client->vars, key, val)) slog_debug(client, "got var: %s=%s", key, val); else { disconnect_client(client, true, "Unknown startup parameter"); diff --git a/src/objects.c b/src/objects.c index 42c33ff..94af97d 100644 --- a/src/objects.c +++ b/src/objects.c @@ -952,10 +952,10 @@ bool use_client_socket(int fd, PgAddr *addr, client->tmp_sk_oldfd = oldfd; client->tmp_sk_linkfd = linkfd; - varcache_set(&client->vars, "client_encoding", client_enc, true); - varcache_set(&client->vars, "standard_conforming_strings", std_string, true); - varcache_set(&client->vars, "datestyle", datestyle, true); - varcache_set(&client->vars, "timezone", timezone, true); + varcache_set(&client->vars, "client_encoding", client_enc); + varcache_set(&client->vars, "standard_conforming_strings", std_string); + varcache_set(&client->vars, "datestyle", datestyle); + varcache_set(&client->vars, "timezone", timezone); return true; } @@ -1009,10 +1009,10 @@ bool use_server_socket(int fd, PgAddr *addr, server->tmp_sk_oldfd = oldfd; server->tmp_sk_linkfd = linkfd; - varcache_set(&server->vars, "client_encoding", client_enc, true); - varcache_set(&server->vars, "standard_conforming_strings", std_string, true); - varcache_set(&server->vars, "datestyle", datestyle, true); - varcache_set(&server->vars, "timezone", timezone, true); + varcache_set(&server->vars, "client_encoding", client_enc); + varcache_set(&server->vars, "standard_conforming_strings", std_string); + varcache_set(&server->vars, "datestyle", datestyle); + varcache_set(&server->vars, "timezone", timezone); return true; } diff --git a/src/proto.c b/src/proto.c index 1da40f5..730458e 100644 --- a/src/proto.c +++ b/src/proto.c @@ -148,12 +148,12 @@ bool add_welcome_parameter(PgSocket *server, return false; } - slog_debug(server, "S: param: %s = %s", key, val); - if (varcache_set(&pool->orig_vars, key, val, true)) { - slog_debug(server, "interesting var: %s=%s", key, val); - varcache_set(&server->vars, key, val, true); + slog_noise(server, "S: param: %s = %s", key, val); + if (varcache_set(&pool->orig_vars, key, val)) { + slog_noise(server, "interesting var: %s=%s", key, val); + varcache_set(&server->vars, key, val); } else { - slog_debug(server, "uninteresting var: %s=%s", key, val); + slog_noise(server, "uninteresting var: %s=%s", key, val); pktbuf_write_ParameterStatus(&msg, key, val); pool->welcome_msg_len += pktbuf_written(&msg); } @@ -181,9 +181,6 @@ bool welcome_client(PgSocket *client) if (!pool->welcome_msg_ready) return false; - varcache_print(&client->vars, "welcome/client"); - varcache_print(&client->pool->orig_vars, "welcome/pool"); - pktbuf_static(&msg, buf, sizeof(buf)); pktbuf_put_bytes(&msg, pool->welcome_msg, pool->welcome_msg_len); diff --git a/src/server.c b/src/server.c index 1e8fd94..24b13d2 100644 --- a/src/server.c +++ b/src/server.c @@ -39,11 +39,11 @@ static void check_parameters(PgSocket *server, MBuf *pkt, unsigned pkt_len) } slog_debug(server, "S: param: %s = %s", key, val); - varcache_set(&server->vars, key, val, true); + varcache_set(&server->vars, key, val); if (client) { slog_debug(client, "setting client var: %s='%s'", key, val); - varcache_set(&client->vars, key, val, true); + varcache_set(&client->vars, key, val); } return; diff --git a/src/varcache.c b/src/varcache.c index 6b7b790..e8aeb07 100644 --- a/src/varcache.c +++ b/src/varcache.c @@ -29,21 +29,19 @@ struct var_lookup { }; static const struct var_lookup lookup [] = { -{"client_encoding", offsetof(VarCache, client_encoding), VAR_ENCODING_LEN }, -{"datestyle", offsetof(VarCache, datestyle), VAR_DATESTYLE_LEN }, -{"timezone", offsetof(VarCache, timezone), VAR_TIMEZONE_LEN }, -{"standard_conforming_strings", offsetof(VarCache, std_strings), VAR_STDSTR_LEN }, -{NULL}, + {"client_encoding", offsetof(VarCache, client_encoding), VAR_ENCODING_LEN }, + {"datestyle", offsetof(VarCache, datestyle), VAR_DATESTYLE_LEN }, + {"timezone", offsetof(VarCache, timezone), VAR_TIMEZONE_LEN }, + {"standard_conforming_strings", offsetof(VarCache, std_strings), VAR_STDSTR_LEN }, + {NULL}, }; -static char *get_value(VarCache *cache, const struct var_lookup *lk) +static inline char *get_value(VarCache *cache, const struct var_lookup *lk) { return (char *)(cache) + lk->offset; } -bool varcache_set(VarCache *cache, - const char *key, const char *value, - bool overwrite) +bool varcache_set(VarCache *cache, const char *key, const char *value) { int vlen; char *pos; @@ -53,16 +51,14 @@ bool varcache_set(VarCache *cache, if (strcasecmp(lk->name, key) != 0) continue; - pos = get_value(cache, lk); - - if (!overwrite && *pos) - break; + vlen = strlen(value); + if (vlen >= lk->len) { + log_warning("varcache_set overflow: %s", key); + return false; + } - vlen = strlcpy(pos, value, lk->len); - if (vlen >= lk->len) - log_warning("varcache_set(%s) overflow", key); - else - log_debug("varcache_set: %s=%s", key, pos); + pos = get_value(cache, lk); + memcpy(pos, value, vlen + 1); return true; } return false; @@ -163,12 +159,8 @@ void varcache_fill_unset(VarCache *src, PgSocket *dst) for (lk = lookup; lk->name; lk++) { srcval = get_value(src, lk); dstval = get_value(&dst->vars, lk); - if (*dstval) - continue; - - /* empty val, copy */ - slog_debug(dst, "varcache_fill_unset: %s = %s", lk->name, srcval); - strlcpy(dstval, srcval, lk->len); + if (!*dstval) + strlcpy(dstval, srcval, lk->len); } } @@ -188,19 +180,6 @@ void varcache_add_params(PktBuf *pkt, VarCache *vars) val = get_value(vars, lk); if (*val) pktbuf_write_ParameterStatus(pkt, lk->name, val); - else - log_error("varcache_add_params: empty param: %s", lk->name); - } -} - -void varcache_print(VarCache *vars, const char *desc) -{ - char *val; - const struct var_lookup *lk; - for (lk = lookup; lk->name; lk++) { - val = get_value(vars, lk); - log_debug("%s: %s='%s'", desc, lk->name, val); } } - diff --git a/src/varcache.h b/src/varcache.h index 0a0c6a6..33b424d 100644 --- a/src/varcache.h +++ b/src/varcache.h @@ -13,10 +13,9 @@ struct VarCache { char std_strings[VAR_STDSTR_LEN]; }; -bool varcache_set(VarCache *cache, const char *key, const char *value, bool overwrite); +bool varcache_set(VarCache *cache, const char *key, const char *value); bool varcache_apply(PgSocket *server, PgSocket *client, bool *changes_p); void varcache_fill_unset(VarCache *src, PgSocket *dst); void varcache_clean(VarCache *cache); void varcache_add_params(PktBuf *pkt, VarCache *vars); -void varcache_print(VarCache *vars, const char *desc); -- 2.40.0