int array_size;
int ch;
int optindex;
- bool verbose = false;
+ char * frmt;
+ bool verbose = false;
+ bool all = false;
static struct option long_options[] = {
{"debug", no_argument, NULL, 'd'},
{NULL, 0, NULL, 0}
};
- while ((ch = getopt_long(argc, argv, "hdv", long_options, &optindex)) != -1) {
+ while ((ch = getopt_long(argc, argv, "hdva", long_options, &optindex)) != -1) {
switch (ch) {
case 'd':
pcp_enable_debug();
verbose = true;
break;
+ case 'a':
+ all = true;
+ break;
+
case 'h':
case '?':
default:
argc -= optind;
argv += optind;
- if (argc != 6)
+ if (verbose)
+ {
+ if (all)
+ frmt = "Database : %s\n"
+ "Username : %s\n"
+ "Start time : %s\n"
+ "Creation time: %s\n"
+ "Major : %d\n"
+ "Minor : %d\n"
+ "Counter : %d\n"
+ "Backend PID : %d\n"
+ "Connected : %d\n"
+ "PID : %d\n"
+ "Backend ID : %d\n";
+ else
+ frmt = "Database : %s\n"
+ "Username : %s\n"
+ "Start time : %s\n"
+ "Creation time: %s\n"
+ "Major : %d\n"
+ "Minor : %d\n"
+ "Counter : %d\n"
+ "Backend PID : %d\n"
+ "Connected : %d\n";
+ }
+ else
+ {
+ if (all)
+ frmt = "%s %s %s %s %d %d %d %d %d %d %d\n";
+ else
+ frmt = "%s %s %s %s %d %d %d %d %d\n";
+ }
+
+ if (!(argc == 5 || argc == 6))
{
errorcode = INVALERR;
pcp_errorstr(errorcode);
myexit(errorcode);
}
strcpy(pass, argv[4]);
+
+ if (argc == 6) {
- processID = atoi(argv[5]);
- if (processID < 0)
- {
- errorcode = INVALERR;
- pcp_errorstr(errorcode);
- myexit(errorcode);
+ processID = atoi(argv[5]);
+ if (processID < 0)
+ {
+ errorcode = INVALERR;
+ pcp_errorstr(errorcode);
+ myexit(errorcode);
+ }
+ }
+ else {
+ processID = 0;
}
pcp_set_timeout(timeout);
myexit(errorcode);
} else {
int i;
- char strcreatetime[128];
- char strstarttime[128];
- strftime(strstarttime, 128, "%Y-%m-%d %H:%M:%S", localtime(&process_info->start_time));
+ char strcreatetime[128];
+ char strstarttime[128];
+
for (i = 0; i < array_size; i++)
{
- if (process_info->connection_info[i].database[0] == '\0')
+ if ((!all) && (process_info[i].connection_info->database[0] == '\0'))
continue;
-
- strftime(strcreatetime, 128, "%Y-%m-%d %H:%M:%S", localtime(&process_info->connection_info[i].create_time));
- if (verbose)
- {
- printf("Database : %s\nUsername : %s\nStart time : %s\nCreation time: %s\nMajor : %d\nMinor : %d\nCounter : %d\nPID : %d\nConnected : %d\n",
- process_info->connection_info[i].database,
- process_info->connection_info[i].user,
- strstarttime,
- strcreatetime,
- process_info->connection_info[i].major,
- process_info->connection_info[i].minor,
- process_info->connection_info[i].counter,
- process_info->connection_info[i].pid,
- process_info->connection_info[i].connected);
- } else {
- printf("%s %s %s %s %d %d %d %d %d\n",
- process_info->connection_info[i].database,
- process_info->connection_info[i].user,
- strstarttime,
- strcreatetime,
- process_info->connection_info[i].major,
- process_info->connection_info[i].minor,
- process_info->connection_info[i].counter,
- process_info->connection_info[i].pid,
- process_info->connection_info[i].connected);
- }
+
+ *strcreatetime = *strstarttime = '\0';
+
+ if (process_info[i].start_time)
+ strftime(strstarttime, 128, "%Y-%m-%d %H:%M:%S", localtime(&process_info[i].start_time));
+ if (process_info[i].connection_info->create_time)
+ strftime(strcreatetime, 128, "%Y-%m-%d %H:%M:%S", localtime(&process_info[i].connection_info->create_time));
+
+ printf(frmt,
+ process_info[i].connection_info->database,
+ process_info[i].connection_info->user,
+ strstarttime,
+ strcreatetime,
+ process_info[i].connection_info->major,
+ process_info[i].connection_info->minor,
+ process_info[i].connection_info->counter,
+ process_info[i].connection_info->pid,
+ process_info[i].connection_info->connected,
+ process_info[i].pid,
+ process_info[i].connection_info->backend_id);
}
+ free(process_info->connection_info);
free(process_info);
}
usage(void)
{
fprintf(stderr, "pcp_proc_info - display a pgpool-II child process' information\n\n");
- fprintf(stderr, "Usage: pcp_proc_info [-d] timeout hostname port# username password PID\n");
+ fprintf(stderr, "Usage: pcp_proc_info [-d] timeout hostname port# username password [PID]\n");
fprintf(stderr, " -d, --debug : enable debug message (optional)\n");
fprintf(stderr, " timeout : connection timeout value in seconds. command exits on timeout\n");
fprintf(stderr, " hostname : pgpool-II hostname\n");
fprintf(stderr, " port# : PCP port number\n");
fprintf(stderr, " username : username for PCP authentication\n");
fprintf(stderr, " password : password for PCP authentication\n");
- fprintf(stderr, " PID : PID of a child process to get information for\n\n");
+ fprintf(stderr, " PID : if given, PID of the only child process to get information for\n\n");
fprintf(stderr, "Usage: pcp_proc_info [options]\n");
- fprintf(stderr, " Options available are:\n");
+ fprintf(stderr, " Options available are:\n");
fprintf(stderr, " -h, --help : print this help\n");
fprintf(stderr, " -v, --verbose : display one line per information with a header\n");
+ fprintf(stderr, " -a, --all : display all child processes and their available connection slots.\n");
}
static void
{
int proc_id;
int wsize;
-
- ProcessInfo *pi = NULL;
+ int num_proc = pool_config->num_init_children;
+ int i;
proc_id = atoi(buf);
- pi = pool_get_process_info(proc_id);
- if (pi == NULL)
+ if ((proc_id != 0) && (pool_get_process_info(proc_id) == NULL))
{
char code[] = "InvalidProcessID";
/* Finally, indicate that all data is sent */
char fin_code[] = "CommandComplete";
- snprintf(con_info_size, sizeof(con_info_size), "%d", pool_config->max_pool*NUM_BACKENDS);
+ POOL_REPORT_POOLS *pools = get_pools(&num_proc);
+
+ if (proc_id == 0)
+ {
+ snprintf(con_info_size, sizeof(con_info_size), "%d", num_proc);
+ }
+ else
+ {
+ snprintf(con_info_size, sizeof(con_info_size), "%d", pool_config->max_pool * NUM_BACKENDS);
+ }
pcp_write(frontend, "p", 1);
wsize = htonl(sizeof(arr_code) +
if (pcp_flush(frontend) < 0)
{
pool_error("pcp_child: pcp_flush() failed. reason: %s", strerror(errno));
+ free(pools);
exit(1);
}
/* Second, send process information for all connection_info */
- for (i = 0; i < pool_config->max_pool; i++)
+ for (i=0; i<num_proc; i++)
{
- int j;
-
- for (j=0;j<NUM_BACKENDS;j++)
+ char code[] = "ProcessInfo";
+ char proc_pid[16];
+ char proc_start_time[20];
+ char proc_create_time[20];
+ char majorversion[5];
+ char minorversion[5];
+ char pool_counter[16];
+ char backend_id[16];
+ char backend_pid[16];
+ char connected[2];
+
+ if (proc_id != 0 && proc_id != pools[i].pool_pid) continue;
+
+ snprintf(proc_pid, sizeof(proc_pid), "%d", pools[i].pool_pid);
+ snprintf(proc_start_time, sizeof(proc_start_time), "%ld", pools[i].start_time);
+ snprintf(proc_create_time, sizeof(proc_create_time), "%ld", pools[i].create_time);
+ snprintf(majorversion, sizeof(majorversion), "%d", pools[i].pool_majorversion);
+ snprintf(minorversion, sizeof(minorversion), "%d", pools[i].pool_minorversion);
+ snprintf(pool_counter, sizeof(pool_counter), "%d", pools[i].pool_counter);
+ snprintf(backend_id, sizeof(backend_pid), "%d", pools[i].backend_id);
+ snprintf(backend_pid, sizeof(backend_pid), "%d", pools[i].pool_backendpid);
+ snprintf(connected, sizeof(connected), "%d", pools[i].pool_connected);
+
+ pcp_write(frontend, "p", 1);
+ wsize = htonl( sizeof(code) +
+ strlen(proc_pid)+1 +
+ strlen(pools[i].database)+1 +
+ strlen(pools[i].username)+1 +
+ strlen(proc_start_time)+1 +
+ strlen(proc_create_time)+1 +
+ strlen(majorversion)+1 +
+ strlen(minorversion)+1 +
+ strlen(pool_counter)+1 +
+ strlen(backend_id)+1 +
+ strlen(backend_pid)+1 +
+ strlen(connected)+1 +
+ sizeof(int));
+ pcp_write(frontend, &wsize, sizeof(int));
+ pcp_write(frontend, code, sizeof(code));
+ pcp_write(frontend, proc_pid, strlen(proc_pid)+1);
+ pcp_write(frontend, pools[i].database, strlen(pools[i].database)+1);
+ pcp_write(frontend, pools[i].username, strlen(pools[i].username)+1);
+ pcp_write(frontend, proc_start_time, strlen(proc_start_time)+1);
+ pcp_write(frontend, proc_create_time, strlen(proc_create_time)+1);
+ pcp_write(frontend, majorversion, strlen(majorversion)+1);
+ pcp_write(frontend, minorversion, strlen(minorversion)+1);
+ pcp_write(frontend, pool_counter, strlen(pool_counter)+1);
+ pcp_write(frontend, backend_id, strlen(backend_id)+1);
+ pcp_write(frontend, backend_pid, strlen(backend_pid)+1);
+ pcp_write(frontend, connected, strlen(connected)+1);
+ if (pcp_flush(frontend) < 0)
{
- char code[] = "ProcessInfo";
- char proc_start_time[20];
- char proc_create_time[20];
- char majorversion[5];
- char minorversion[5];
- char pool_counter[16];
- char backend_pid[16];
- char connected[2];
-
- ConnectionInfo *connection_info;
-
- connection_info = pool_coninfo_pid(proc_id, i, j);
-
- snprintf(proc_start_time, sizeof(proc_start_time), "%ld", pi->start_time);
- snprintf(proc_create_time, sizeof(proc_create_time), "%ld", connection_info->create_time);
- snprintf(majorversion, sizeof(majorversion), "%d", connection_info->major);
- snprintf(minorversion, sizeof(minorversion), "%d", connection_info->minor);
- snprintf(pool_counter, sizeof(pool_counter), "%d", connection_info->counter);
- snprintf(backend_pid, sizeof(backend_pid), "%d", ntohl(connection_info->pid));
- snprintf(connected, sizeof(connected), "%d", connection_info->connected);
-
- pcp_write(frontend, "p", 1);
- wsize = htonl(sizeof(code) +
- strlen(connection_info->database)+1 +
- strlen(connection_info->user)+1 +
- strlen(proc_start_time)+1 +
- strlen(proc_create_time)+1 +
- strlen(majorversion)+1 +
- strlen(minorversion)+1 +
- strlen(pool_counter)+1 +
- strlen(backend_pid)+1 +
- strlen(connected)+1 +
- sizeof(int));
- pcp_write(frontend, &wsize, sizeof(int));
- pcp_write(frontend, code, sizeof(code));
- pcp_write(frontend, connection_info->database, strlen(connection_info->database)+1);
- pcp_write(frontend, connection_info->user, strlen(connection_info->user)+1);
- pcp_write(frontend, proc_start_time, strlen(proc_start_time)+1);
- pcp_write(frontend, proc_create_time, strlen(proc_create_time)+1);
- pcp_write(frontend, majorversion, strlen(majorversion)+1);
- pcp_write(frontend, minorversion, strlen(minorversion)+1);
- pcp_write(frontend, pool_counter, strlen(pool_counter)+1);
- pcp_write(frontend, backend_pid, strlen(backend_pid)+1);
- pcp_write(frontend, connected, strlen(connected)+1);
- if (pcp_flush(frontend) < 0)
- {
- pool_error("pcp_child: pcp_flush() failed. reason: %s", strerror(errno));
- exit(1);
- }
+ pool_error("pcp_child: pcp_flush() failed. reason: %s", strerror(errno));
+ free(pools);
+ exit(1);
}
}
if (pcp_flush(frontend) < 0)
{
pool_error("pcp_child: pcp_flush() failed. reason: %s", strerror(errno));
+ free(pools);
exit(1);
}
pool_debug("pcp_child: retrieved process information from shared memory");
+ free(pools);
}
break;
}
);
for (child = 0; child < pool_config->num_init_children; child++)
- {
+ {
proc_id = process_info[child].pid;
- pi = pool_get_process_info(proc_id);
+ pi = pool_get_process_info(proc_id);
- for (pool = 0; pool < pool_config->max_pool; pool++)
- {
+ for (pool = 0; pool < pool_config->max_pool; pool++)
+ {
for (backend_id = 0; backend_id < NUM_BACKENDS; backend_id++)
{
- poolBE = pool*MAX_NUM_BACKENDS+backend_id;
- snprintf(pools[lines].pool_pid, POOLCONFIG_MAXCOUNTLEN, "%d", proc_id);
- strftime(pools[lines].start_time, POOLCONFIG_MAXDATELEN, "%Y-%m-%d %H:%M:%S", localtime(&pi->start_time));
- snprintf(pools[lines].pool_id, POOLCONFIG_MAXCOUNTLEN, "%d", pool);
- snprintf(pools[lines].backend_id, POOLCONFIG_MAXCOUNTLEN, "%d", backend_id);
- if (strlen(pi->connection_info[poolBE].database) == 0)
- {
- strncpy(pools[lines].database, "", POOLCONFIG_MAXIDENTLEN);
- strncpy(pools[lines].username, "", POOLCONFIG_MAXIDENTLEN);
- strncpy(pools[lines].create_time, "", POOLCONFIG_MAXDATELEN);
- strncpy(pools[lines].pool_majorversion, "", POOLCONFIG_MAXCOUNTLEN);
- strncpy(pools[lines].pool_minorversion, "", POOLCONFIG_MAXCOUNTLEN);
- strncpy(pools[lines].pool_counter, "", POOLCONFIG_MAXCOUNTLEN);
- strncpy(pools[lines].pool_backendpid, "", POOLCONFIG_MAXCOUNTLEN);
- strncpy(pools[lines].pool_connected, "", POOLCONFIG_MAXCOUNTLEN);
- }
- else
- {
- strncpy(pools[lines].database, pi->connection_info[poolBE].database, POOLCONFIG_MAXIDENTLEN);
- strncpy(pools[lines].username, pi->connection_info[poolBE].user, POOLCONFIG_MAXIDENTLEN);
- strftime(pools[lines].create_time, POOLCONFIG_MAXDATELEN, "%Y-%m-%d %H:%M:%S", localtime(&pi->connection_info[poolBE].create_time));
- snprintf(pools[lines].pool_majorversion, POOLCONFIG_MAXCOUNTLEN, "%d", pi->connection_info[poolBE].major);
- snprintf(pools[lines].pool_minorversion, POOLCONFIG_MAXCOUNTLEN, "%d", pi->connection_info[poolBE].minor);
- snprintf(pools[lines].pool_counter, POOLCONFIG_MAXCOUNTLEN, "%d", pi->connection_info[poolBE].counter);
- snprintf(pools[lines].pool_backendpid, POOLCONFIG_MAXCOUNTLEN, "%d", ntohl(pi->connection_info[poolBE].pid));
- snprintf(pools[lines].pool_connected, POOLCONFIG_MAXCOUNTLEN, "%d", pi->connection_info[poolBE].connected);
- }
- lines++;
- }
- }
+ poolBE = pool*MAX_NUM_BACKENDS+backend_id;
+ pools[lines].pool_pid = proc_id;
+ pools[lines].start_time = pi->start_time;
+ pools[lines].pool_id = pool;
+ pools[lines].backend_id = backend_id;
+ if (strlen(pi->connection_info[poolBE].database) == 0)
+ {
+ strncpy(pools[lines].database, "", POOLCONFIG_MAXIDENTLEN);
+ strncpy(pools[lines].username, "", POOLCONFIG_MAXIDENTLEN);
+ pools[lines].create_time = 0;
+ pools[lines].pool_majorversion = 0;
+ pools[lines].pool_minorversion = 0;
+ }
+ else
+ {
+ strncpy(pools[lines].database, pi->connection_info[poolBE].database, POOLCONFIG_MAXIDENTLEN);
+ strncpy(pools[lines].username, pi->connection_info[poolBE].user, POOLCONFIG_MAXIDENTLEN);
+ pools[lines].create_time = pi->connection_info[poolBE].create_time;
+ pools[lines].pool_majorversion = pi->connection_info[poolBE].major;
+ pools[lines].pool_minorversion = pi->connection_info[poolBE].minor;
+ }
+ pools[lines].pool_counter = pi->connection_info[poolBE].counter;
+ pools[lines].pool_backendpid = ntohl(pi->connection_info[poolBE].pid);
+ pools[lines].pool_connected = pi->connection_info[poolBE].connected;
+ lines++;
+ }
+ }
}
*nrows = lines;
return pools;
- }
+}
void pools_reporting(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend)
- {
+{
static short num_fields = 12;
static char *field_names[] = {"pool_pid", "start_time", "pool_id", "backend_id", "database", "username", "create_time",
"majorversion", "minorversion", "pool_counter", "pool_backendpid", "pool_connected"};
short s;
int len;
- int i;
+ int i;
static unsigned char nullmap[2] = {0xff, 0xff};
int nbytes = (num_fields + 7)/8;
int nrows;
int size;
int hsize;
+ char proc_pid[16];
+ char pool_id[16];
+ char proc_start_time[20];
+ char proc_create_time[20];
+ char majorversion[5];
+ char minorversion[5];
+ char pool_counter[16];
+ char backend_id[16];
+ char backend_pid[16];
+ char connected[2];
POOL_REPORT_POOLS *pools = get_pools(&nrows);
send_row_description(frontend, backend, num_fields, field_names);
- if (MAJOR(backend) == PROTO_MAJOR_V2)
- {
- /* ascii row */
- for (i=0;i<nrows;i++)
- {
- pool_write(frontend, "D", 1);
- pool_write_and_flush(frontend, nullmap, nbytes);
-
- size = strlen(pools[i].pool_pid);
- hsize = htonl(size+4);
- pool_write(frontend, &hsize, sizeof(hsize));
- pool_write(frontend, pools[i].pool_pid, size);
-
- size = strlen(pools[i].start_time);
- hsize = htonl(size+4);
- pool_write(frontend, &hsize, sizeof(hsize));
- pool_write(frontend, pools[i].start_time, size);
-
- size = strlen(pools[i].pool_id);
- hsize = htonl(size+4);
- pool_write(frontend, &hsize, sizeof(hsize));
- pool_write(frontend, pools[i].pool_id, size);
-
- size = strlen(pools[i].backend_id);
- hsize = htonl(size+4);
- pool_write(frontend, &hsize, sizeof(hsize));
- pool_write(frontend, pools[i].backend_id, size);
-
- size = strlen(pools[i].database);
- hsize = htonl(size+4);
- pool_write(frontend, &hsize, sizeof(hsize));
- pool_write(frontend, pools[i].database, size);
-
- size = strlen(pools[i].username);
- hsize = htonl(size+4);
- pool_write(frontend, &hsize, sizeof(hsize));
- pool_write(frontend, pools[i].username, size);
-
- size = strlen(pools[i].create_time);
- hsize = htonl(size+4);
- pool_write(frontend, &hsize, sizeof(hsize));
- pool_write(frontend, pools[i].create_time, size);
-
- size = strlen(pools[i].pool_majorversion);
- hsize = htonl(size+4);
- pool_write(frontend, &hsize, sizeof(hsize));
- pool_write(frontend, pools[i].pool_majorversion, size);
-
- size = strlen(pools[i].pool_minorversion);
- hsize = htonl(size+4);
- pool_write(frontend, &hsize, sizeof(hsize));
- pool_write(frontend, pools[i].pool_minorversion, size);
-
- size = strlen(pools[i].pool_counter);
- hsize = htonl(size+4);
- pool_write(frontend, &hsize, sizeof(hsize));
- pool_write(frontend, pools[i].pool_counter, size);
-
- size = strlen(pools[i].pool_backendpid);
- hsize = htonl(size+4);
- pool_write(frontend, &hsize, sizeof(hsize));
- pool_write(frontend, pools[i].pool_backendpid, size);
+ if (MAJOR(backend) == PROTO_MAJOR_V2) hsize = 4;
+ else hsize = 0;
- size = strlen(pools[i].pool_connected);
- hsize = htonl(size+4);
- pool_write(frontend, &hsize, sizeof(hsize));
- pool_write(frontend, pools[i].pool_connected, size);
- }
- }
- else
- {
- /* data row */
+ /* ascii row */
for (i=0;i<nrows;i++)
{
- pool_write(frontend, "D", 1);
- len = 6; /* int32 + int16; */
- len += 4 + strlen(pools[i].pool_pid); /* int32 + data */
- len += 4 + strlen(pools[i].start_time); /* int32 + data */
- len += 4 + strlen(pools[i].pool_id); /* int32 + data */
- len += 4 + strlen(pools[i].backend_id); /* int32 + data */
- len += 4 + strlen(pools[i].database); /* int32 + data */
- len += 4 + strlen(pools[i].username); /* int32 + data */
- len += 4 + strlen(pools[i].create_time); /* int32 + data */
- len += 4 + strlen(pools[i].pool_majorversion); /* int32 + data */
- len += 4 + strlen(pools[i].pool_minorversion); /* int32 + data */
- len += 4 + strlen(pools[i].pool_counter); /* int32 + data */
- len += 4 + strlen(pools[i].pool_backendpid); /* int32 + data */
- len += 4 + strlen(pools[i].pool_connected); /* int32 + data */
- len = htonl(len);
- pool_write(frontend, &len, sizeof(len));
- s = htons(num_fields);
- pool_write(frontend, &s, sizeof(s));
-
- len = htonl(strlen(pools[i].pool_pid));
- pool_write(frontend, &len, sizeof(len));
- pool_write(frontend, pools[i].pool_pid, strlen(pools[i].pool_pid));
-
- len = htonl(strlen(pools[i].start_time));
- pool_write(frontend, &len, sizeof(len));
- pool_write(frontend, pools[i].start_time, strlen(pools[i].start_time));
-
- len = htonl(strlen(pools[i].pool_id));
- pool_write(frontend, &len, sizeof(len));
- pool_write(frontend, pools[i].pool_id, strlen(pools[i].pool_id));
-
- len = htonl(strlen(pools[i].backend_id));
- pool_write(frontend, &len, sizeof(len));
- pool_write(frontend, pools[i].backend_id, strlen(pools[i].backend_id));
-
- len = htonl(strlen(pools[i].database));
- pool_write(frontend, &len, sizeof(len));
- pool_write(frontend, pools[i].database, strlen(pools[i].database));
-
- len = htonl(strlen(pools[i].username));
- pool_write(frontend, &len, sizeof(len));
- pool_write(frontend, pools[i].username, strlen(pools[i].username));
-
- len = htonl(strlen(pools[i].create_time));
- pool_write(frontend, &len, sizeof(len));
- pool_write(frontend, pools[i].create_time, strlen(pools[i].create_time));
-
- len = htonl(strlen(pools[i].pool_majorversion));
- pool_write(frontend, &len, sizeof(len));
- pool_write(frontend, pools[i].pool_majorversion, strlen(pools[i].pool_majorversion));
-
- len = htonl(strlen(pools[i].pool_minorversion));
- pool_write(frontend, &len, sizeof(len));
- pool_write(frontend, pools[i].pool_minorversion, strlen(pools[i].pool_minorversion));
-
- len = htonl(strlen(pools[i].pool_counter));
- pool_write(frontend, &len, sizeof(len));
- pool_write(frontend, pools[i].pool_counter, strlen(pools[i].pool_counter));
-
- len = htonl(strlen(pools[i].pool_backendpid));
- pool_write(frontend, &len, sizeof(len));
- pool_write(frontend, pools[i].pool_backendpid, strlen(pools[i].pool_backendpid));
-
- len = htonl(strlen(pools[i].pool_connected));
- pool_write(frontend, &len, sizeof(len));
- pool_write(frontend, pools[i].pool_connected, strlen(pools[i].pool_connected));
+ snprintf(proc_pid, sizeof(proc_pid), "%d", pools[i].pool_pid);
+ snprintf(pool_id, sizeof(pool_id), "%d", pools[i].pool_id);
+ if (pools[i].start_time)
+ strftime(proc_start_time, POOLCONFIG_MAXDATELEN, "%Y-%m-%d %H:%M:%S", localtime(&pools[i].start_time));
+ else
+ *proc_start_time = '\0';
+ if (pools[i].create_time)
+ strftime(proc_create_time, POOLCONFIG_MAXDATELEN, "%Y-%m-%d %H:%M:%S", localtime(&pools[i].create_time));
+ else
+ *proc_create_time = '\0';
+ snprintf(majorversion, sizeof(majorversion), "%d", pools[i].pool_majorversion);
+ snprintf(minorversion, sizeof(minorversion), "%d", pools[i].pool_minorversion);
+ snprintf(pool_counter, sizeof(pool_counter), "%d", pools[i].pool_counter);
+ snprintf(backend_id, sizeof(backend_pid), "%d", pools[i].backend_id);
+ snprintf(backend_pid, sizeof(backend_pid), "%d", pools[i].pool_backendpid);
+ snprintf(connected, sizeof(connected), "%d", pools[i].pool_connected);
+
+ if (MAJOR(backend) == PROTO_MAJOR_V2)
+ {
+ pool_write(frontend, "D", 1);
+ pool_write_and_flush(frontend, nullmap, nbytes);
+ }
+ else
+ {
+ pool_write(frontend, "D", 1);
+ len = 6; /* int32 + int16; */
+ len += 4 + strlen(proc_pid); /* int32 + data */
+ len += 4 + strlen(proc_start_time); /* int32 + data */
+ len += 4 + strlen(pool_id); /* int32 + data */
+ len += 4 + strlen(backend_id); /* int32 + data */
+ len += 4 + strlen(pools[i].database); /* int32 + data */
+ len += 4 + strlen(pools[i].username); /* int32 + data */
+ len += 4 + strlen(proc_create_time); /* int32 + data */
+ len += 4 + strlen(majorversion); /* int32 + data */
+ len += 4 + strlen(minorversion); /* int32 + data */
+ len += 4 + strlen(pool_counter); /* int32 + data */
+ len += 4 + strlen(backend_pid); /* int32 + data */
+ len += 4 + strlen(connected); /* int32 + data */
+
+ len = htonl(len);
+ pool_write(frontend, &len, sizeof(len));
+ s = htons(num_fields);
+ pool_write(frontend, &s, sizeof(s));
+ }
+
+ len = strlen(proc_pid);
+ size = htonl(len+hsize);
+ pool_write(frontend, &size, sizeof(size));
+ pool_write(frontend, proc_pid, len);
+
+ len = strlen(proc_start_time);
+ size = htonl(len+hsize);
+ pool_write(frontend, &size, sizeof(size));
+ pool_write(frontend, proc_start_time, len);
+
+ len = strlen(pool_id);
+ size = htonl(len+hsize);
+ pool_write(frontend, &size, sizeof(size));
+ pool_write(frontend, pool_id, len);
+
+ len = strlen(backend_id);
+ size = htonl(len+hsize);
+ pool_write(frontend, &size, sizeof(size));
+ pool_write(frontend, backend_id, len);
+
+ len = strlen(pools[i].database);
+ size = htonl(len+hsize);
+ pool_write(frontend, &size, sizeof(size));
+ pool_write(frontend, pools[i].database, len);
+
+ len = strlen(pools[i].username);
+ size = htonl(len+hsize);
+ pool_write(frontend, &size, sizeof(size));
+ pool_write(frontend, pools[i].username, len);
+
+ len = strlen(proc_create_time);
+ size = htonl(len+hsize);
+ pool_write(frontend, &size, sizeof(size));
+ pool_write(frontend, proc_create_time, len);
+
+ len = strlen(majorversion);
+ size = htonl(len+hsize);
+ pool_write(frontend, &size, sizeof(size));
+ pool_write(frontend, majorversion, len);
+
+ len = strlen(minorversion);
+ size = htonl(len+hsize);
+ pool_write(frontend, &size, sizeof(size));
+ pool_write(frontend, minorversion, len);
+
+ len = strlen(pool_counter);
+ size = htonl(len+hsize);
+ pool_write(frontend, &size, sizeof(size));
+ pool_write(frontend, pool_counter, len);
+
+ len = strlen(backend_pid);
+ size = htonl(len+hsize);
+ pool_write(frontend, &size, sizeof(size));
+ pool_write(frontend, backend_pid, len);
+
+ len = strlen(connected);
+ size = htonl(len+hsize);
+ pool_write(frontend, &size, sizeof(size));
+ pool_write(frontend, connected, len);
}
- }
send_complete_and_ready(frontend, backend, nrows);