Skip to content

Commit

Permalink
Create a more descriptive process title for connections.
Browse files Browse the repository at this point in the history
This commit introduces the function
`pgagroal_set_connection_proc_title()` that builds a process title
with the form:

      user@host:port/database

using in turn the `pgagroal_set_proc_title` function.
The `pgagroal_set_connection_proc_title` function is used only by the
`worker` process stuff and required to identify the primary server (to
get the hostname and port).

Related to agroal#215.
  • Loading branch information
fluca1978 committed Jun 29, 2022
1 parent 29a0cb5 commit 52a585a
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 6 deletions.
1 change: 0 additions & 1 deletion src/include/pgagroal.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ extern "C" {
#define PGAGROAL_DEFAULT_ADMINS_FILE PGAGROAL_DEFAULT_CONFIGURATION_PATH "pgagroal_admins.conf"
#define PGAGROAL_DEFAULT_SUPERUSER_FILE PGAGROAL_DEFAULT_CONFIGURATION_PATH "pgagroal_superuser.conf"


#define MAX_BUFFER_SIZE 65535
#define DEFAULT_BUFFER_SIZE 65535
#define SECURITY_BUFFER_SIZE 512
Expand Down
14 changes: 14 additions & 0 deletions src/include/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,20 @@ pgagroal_base64_decode(char* encoded, size_t encoded_length, char** raw, int* ra
void
pgagroal_set_proc_title(int argc, char** argv, char* s1, char* s2);

/**
* Sets the process title for a given connection.
*
* Uses `pgagroal_set_proc_title` to build an information string
* with the form
* user@host:port/database
*
* @param argc the number of arguments
* @param argv command line arguments
* @param connection the struct connection pointer for the established connection.
*/
void
pgagroal_set_connection_proc_title(int argc, char** argv, struct connection* connection);

#ifdef DEBUG

/**
Expand Down
28 changes: 24 additions & 4 deletions src/libpgagroal/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <pgagroal.h>
#include <logging.h>
#include <utils.h>
#include <server.h>

/* system */
#include <ev.h>
Expand Down Expand Up @@ -758,10 +759,10 @@ pgagroal_set_proc_title(int argc, char** argv, char* s1, char* s2)
// when the application was started
if (max_process_title_size == 0)
{
for (int i = 0; i < argc; i++)
{
max_process_title_size += strlen(argv[i]) + 1;
}
for (int i = 0; i < argc; i++)
{
max_process_title_size += strlen(argv[i]) + 1;
}
}

// compose the new title
Expand Down Expand Up @@ -791,6 +792,25 @@ pgagroal_set_proc_title(int argc, char** argv, char* s1, char* s2)
#endif
}

void
pgagroal_set_connection_proc_title(int argc, char** argv, struct connection* connection)
{
struct configuration* config;
int primary;
char info[MISC_LENGTH];

config = (struct configuration*)shmem;

pgagroal_get_primary(&primary);

snprintf(info, MISC_LENGTH, "%s@%s:%d",
connection->username,
config->servers[primary].host,
config->servers[primary].port);

pgagroal_set_proc_title(argc, argv, info, connection->database);
}

#ifdef DEBUG

int
Expand Down
2 changes: 1 addition & 1 deletion src/libpgagroal/worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ pgagroal_worker(int client_fd, char* address, char** argv)
pgagroal_prometheus_client_active_add();

pgagroal_pool_status();
pgagroal_set_proc_title(1, argv, config->connections[slot].username, config->connections[slot].database);
pgagroal_set_connection_proc_title(1, argv, &config->connections[slot]);

if (config->pipeline == PIPELINE_PERFORMANCE)
{
Expand Down

0 comments on commit 52a585a

Please sign in to comment.