]> granicus.if.org Git - pgbouncer/commitdiff
Let disconnect_server/client() take printf style args.
authorMarko Kreen <markokr@gmail.com>
Fri, 23 Apr 2010 13:50:49 +0000 (13:50 +0000)
committerMarko Kreen <markokr@gmail.com>
Fri, 23 Apr 2010 13:50:49 +0000 (13:50 +0000)
include/objects.h
src/janitor.c
src/objects.c
src/server.c

index 0ab8783f68573944f3b433a27a43e6f98c038341..3e2e6e9b11f1c705f1fe508a73575c8c5496c6b0 100644 (file)
@@ -37,8 +37,8 @@ bool release_server(PgSocket *server)         /* _MUSTCHECK */;
 bool finish_client_login(PgSocket *client)     _MUSTCHECK;
 
 PgSocket * accept_client(int sock, const struct sockaddr_in *addr, bool is_unix) _MUSTCHECK;
-void disconnect_server(PgSocket *server, bool notify, const char *reason);
-void disconnect_client(PgSocket *client, bool notify, const char *reason);
+void disconnect_server(PgSocket *server, bool notify, const char *reason, ...) _PRINTF(3, 4);
+void disconnect_client(PgSocket *client, bool notify, const char *reason, ...) _PRINTF(3, 4);
 
 PgDatabase * add_database(const char *name) _MUSTCHECK;
 PgDatabase *register_auto_database(const char *name);
index 21b6396c4c26b34ea9174995d916146f741d39dd..85321f72f4eb1c2705e154c448ca20bc44839fc3 100644 (file)
@@ -34,7 +34,7 @@ static void close_server_list(StatList *sk_list, const char *reason)
 
        statlist_for_each_safe(item, sk_list, tmp) {
                server = container_of(item, PgSocket, head);
-               disconnect_server(server, true, reason);
+               disconnect_server(server, true, "%s", reason);
        }
 }
 
@@ -45,7 +45,7 @@ static void close_client_list(StatList *sk_list, const char *reason)
 
        statlist_for_each_safe(item, sk_list, tmp) {
                client = container_of(item, PgSocket, head);
-               disconnect_client(client, true, reason);
+               disconnect_client(client, true, "%s", reason);
        }
 }
 
index 1605e7e6a56d6618bc4efc624473dcd7c567fc34..07ad1cbac27f7eb16e398fd516846cc1743b6254 100644 (file)
@@ -677,13 +677,20 @@ bool release_server(PgSocket *server)
 }
 
 /* drop server connection */
-void disconnect_server(PgSocket *server, bool notify, const char *reason)
+void disconnect_server(PgSocket *server, bool notify, const char *reason, ...)
 {
        PgPool *pool = server->pool;
        PgSocket *client = server->link;
        static const uint8_t pkt_term[] = {'X', 0,0,0,4};
        int send_term = 1;
        usec_t now = get_cached_time();
+       char buf[128];
+       va_list ap;
+
+       va_start(ap, reason);
+       vsnprintf(buf, sizeof(buf), reason, ap);
+       va_end(ap);
+       reason = buf;
 
        if (cf_log_disconnections)
                slog_info(server, "closing because: %s (age=%llu)", reason,
@@ -695,7 +702,7 @@ void disconnect_server(PgSocket *server, bool notify, const char *reason)
                if (client) {
                        client->link = NULL;
                        server->link = NULL;
-                       disconnect_client(client, true, reason);
+                       disconnect_client(client, true, "%s", reason);
                }
                break;
        case SV_TESTED:
@@ -731,10 +738,17 @@ void disconnect_server(PgSocket *server, bool notify, const char *reason)
 }
 
 /* drop client connection */
-void disconnect_client(PgSocket *client, bool notify, const char *reason)
+void disconnect_client(PgSocket *client, bool notify, const char *reason, ...)
 {
+       char buf[128];
+       va_list ap;
        usec_t now = get_cached_time();
 
+       va_start(ap, reason);
+       vsnprintf(buf, sizeof(buf), reason, ap);
+       va_end(ap);
+       reason = buf;
+
        if (cf_log_disconnections)
                slog_info(client, "closing because: %s (age=%llu)", reason,
                          (now - client->connect_time) / USEC);
@@ -953,8 +967,7 @@ found:
                /* notify readiness */
                SEND_ReadyForQuery(res, main_client);
                if (!res)
-                       disconnect_client(main_client, true,
-                                         "ReadyForQuery for main_client failed");
+                       disconnect_client(main_client, true, "ReadyForQuery for main_client failed");
                return;
        }
 
index 465ccd371368a23250de9385387d679f7e4eb197..5088f533d29e9479129694db69415bd349a865ad 100644 (file)
@@ -71,7 +71,7 @@ static void kill_pool_logins(PgPool *pool, PktHdr *errpkt)
                if (!client->wait_for_welcome)
                        continue;
 
-               disconnect_client(client, true, msg);
+               disconnect_client(client, true, "%s", msg);
        }
 }
 
@@ -205,8 +205,7 @@ static bool handle_server_work(PgSocket *server, PktHdr *pkt)
                if (state == 'I')
                        ready = 1;
                else if (cf_pool_mode == POOL_STMT) {
-                       disconnect_server(server, true,
-                                         "Long transactions not allowed");
+                       disconnect_server(server, true, "Long transactions not allowed");
                        return false;
                }
                break;