]> granicus.if.org Git - pgbouncer/commitdiff
varcache: remove overwrite arg, some logging cleanup
authorMarko Kreen <markokr@gmail.com>
Sun, 12 Aug 2007 21:19:12 +0000 (21:19 +0000)
committerMarko Kreen <markokr@gmail.com>
Sun, 12 Aug 2007 21:19:12 +0000 (21:19 +0000)
Makefile
src/client.c
src/objects.c
src/proto.c
src/server.c
src/varcache.c
src/varcache.h

index d163223f2156bb9e2ac800c619e29f4e83796848..404de9449db5100400be896c0f850697c09b75c8 100644 (file)
--- 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
+
index 05389809cb0103c803025e9652922d105841860a..d98cce6841507ba550b9d4d8c0a173ec13949c28 100644 (file)
@@ -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");
index 42c33ffefd926f65623689993b5ed98d1ea996f8..94af97d1d2c2ce41edb82f9c58265d39bc013b9c 100644 (file)
@@ -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;
 }
index 1da40f5006fbc601c0df7403ac3a695641e667dc..730458ef959ae3444ad1a68cf698f93d287fa6ff 100644 (file)
@@ -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);
 
index 1e8fd94692935ea8ec1b71a70dee78aa22f02e16..24b13d288ed61a210311d713b74829f2623863de 100644 (file)
@@ -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;
index 6b7b79061f9805b6794c0d7300880fd5927a3fc1..e8aeb0785f25f660ed875873e5e82b74db64a574 100644 (file)
@@ -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);
        }
 }
 
-
index 0a0c6a646907d29c7d949d69ff1120b84ca914ef..33b424dcf8610f016f46e0e7194e8053b2733812 100644 (file)
@@ -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);