const char *username = NULL, *dbname = NULL;
const char *key, *val;
bool ok;
+ bool appname_found = false;
while (1) {
ok = mbuf_get_string(&pkt->data, &key);
} else if (strcmp(key, "user") == 0) {
slog_debug(client, "got var: %s=%s", key, val);
username = val;
+ } else if (cf_application_name_add_host &&
+ strcmp(key, "application_name") == 0) {
+ int port = pga_port(&client->remote_addr);
+ static char ipbuf[PGADDR_BUF], buf[1024];
+ const char *ip;
+
+ ip = pga_ntop(&client->remote_addr, ipbuf, sizeof(ipbuf));
+ snprintf(buf, sizeof(buf), "%s (%s:%d)", val, ip, port);
+ slog_debug(client,"using application name %s",buf);
+ varcache_set(&client->vars, key, buf);
+ appname_found = true;
} else if (varcache_set(&client->vars, key, val)) {
slog_debug(client, "got var: %s=%s", key, val);
} else if (strlist_contains(cf_ignore_startup_params, key)) {
if (!dbname || !dbname[0])
dbname = username;
+ /* default application_name to "client at <addr>:<port>" */
+ if (!appname_found && cf_application_name_add_host) {
+ int port = pga_port(&client->remote_addr);
+ static char ipbuf[PGADDR_BUF], buf[1024];
+ const char *ip;
+
+ ip = pga_ntop(&client->remote_addr, ipbuf, sizeof(ipbuf));
+ snprintf(buf, sizeof(buf), "client at %s:%d", ip, port);
+ slog_debug(client,"using default application name %s",buf);
+ varcache_set(&client->vars, key, buf);
+ }
+
/* check if limit allows, don't limit admin db
nb: new incoming conn will be attached to PgSocket, thus
get_active_client_count() counts it */
int cf_log_connections;
int cf_log_disconnections;
int cf_log_pooler_errors;
+int cf_application_name_add_host;
/*
* config file description
CF_ABS("log_connections", CF_INT, cf_log_connections, 0, "1"),
CF_ABS("log_disconnections", CF_INT, cf_log_disconnections, 0, "1"),
CF_ABS("log_pooler_errors", CF_INT, cf_log_pooler_errors, 0, "1"),
+CF_ABS("application_name_add_host", CF_INT, cf_application_name_add_host, 0, "1"),
{NULL}
};