Skip to content

Commit 4c8f8ff

Browse files
committed
Further code review for pg_stat_ssl patch.
Fix additional bogosity in commit 9029f4b. Include the BackendSslStatusBuffer in the BackendStatusShmemSize calculation, avoid ugly and error-prone casts to char* and back, put related code stanzas into a consistent order (and fix a couple of previous instances of that sin). All cosmetic except for the size oversight.
1 parent 7d791ed commit 4c8f8ff

File tree

1 file changed

+38
-27
lines changed

1 file changed

+38
-27
lines changed

src/backend/postmaster/pgstat.c

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2478,8 +2478,8 @@ pgstat_fetch_global(void)
24782478

24792479
static PgBackendStatus *BackendStatusArray = NULL;
24802480
static PgBackendStatus *MyBEEntry = NULL;
2481-
static char *BackendClientHostnameBuffer = NULL;
24822481
static char *BackendAppnameBuffer = NULL;
2482+
static char *BackendClientHostnameBuffer = NULL;
24832483
static char *BackendActivityBuffer = NULL;
24842484
static Size BackendActivityBufferSize = 0;
24852485
#ifdef USE_SSL
@@ -2495,13 +2495,22 @@ BackendStatusShmemSize(void)
24952495
{
24962496
Size size;
24972497

2498+
/* BackendStatusArray: */
24982499
size = mul_size(sizeof(PgBackendStatus), MaxBackends);
2500+
/* BackendAppnameBuffer: */
2501+
size = add_size(size,
2502+
mul_size(NAMEDATALEN, MaxBackends));
2503+
/* BackendClientHostnameBuffer: */
24992504
size = add_size(size,
25002505
mul_size(NAMEDATALEN, MaxBackends));
2506+
/* BackendActivityBuffer: */
25012507
size = add_size(size,
25022508
mul_size(pgstat_track_activity_query_size, MaxBackends));
2509+
#ifdef USE_SSL
2510+
/* BackendSslStatusBuffer: */
25032511
size = add_size(size,
2504-
mul_size(NAMEDATALEN, MaxBackends));
2512+
mul_size(sizeof(PgBackendSSLStatus), MaxBackends));
2513+
#endif
25052514
return size;
25062515
}
25072516

@@ -2566,26 +2575,6 @@ CreateSharedBackendStatus(void)
25662575
}
25672576
}
25682577

2569-
#ifdef USE_SSL
2570-
/* Create or attach to the shared SSL status buffer */
2571-
size = mul_size(sizeof(PgBackendSSLStatus), MaxBackends);
2572-
BackendSslStatusBuffer = (PgBackendSSLStatus *)
2573-
ShmemInitStruct("Backend SSL Status Buffer", size, &found);
2574-
2575-
if (!found)
2576-
{
2577-
MemSet(BackendSslStatusBuffer, 0, size);
2578-
2579-
/* Initialize st_sslstatus pointers. */
2580-
buffer = (char *) BackendSslStatusBuffer;
2581-
for (i = 0; i < MaxBackends; i++)
2582-
{
2583-
BackendStatusArray[i].st_sslstatus = (PgBackendSSLStatus *) buffer;
2584-
buffer += sizeof(PgBackendSSLStatus);
2585-
}
2586-
}
2587-
#endif
2588-
25892578
/* Create or attach to the shared activity buffer */
25902579
BackendActivityBufferSize = mul_size(pgstat_track_activity_query_size,
25912580
MaxBackends);
@@ -2606,6 +2595,28 @@ CreateSharedBackendStatus(void)
26062595
buffer += pgstat_track_activity_query_size;
26072596
}
26082597
}
2598+
2599+
#ifdef USE_SSL
2600+
/* Create or attach to the shared SSL status buffer */
2601+
size = mul_size(sizeof(PgBackendSSLStatus), MaxBackends);
2602+
BackendSslStatusBuffer = (PgBackendSSLStatus *)
2603+
ShmemInitStruct("Backend SSL Status Buffer", size, &found);
2604+
2605+
if (!found)
2606+
{
2607+
PgBackendSSLStatus *ptr;
2608+
2609+
MemSet(BackendSslStatusBuffer, 0, size);
2610+
2611+
/* Initialize st_sslstatus pointers. */
2612+
ptr = BackendSslStatusBuffer;
2613+
for (i = 0; i < MaxBackends; i++)
2614+
{
2615+
BackendStatusArray[i].st_sslstatus = ptr;
2616+
ptr++;
2617+
}
2618+
}
2619+
#endif
26092620
}
26102621

26112622

@@ -2932,11 +2943,11 @@ pgstat_read_current_status(void)
29322943
volatile PgBackendStatus *beentry;
29332944
LocalPgBackendStatus *localtable;
29342945
LocalPgBackendStatus *localentry;
2946+
char *localappname,
2947+
*localactivity;
29352948
#ifdef USE_SSL
29362949
PgBackendSSLStatus *localsslstatus;
29372950
#endif
2938-
char *localappname,
2939-
*localactivity;
29402951
int i;
29412952

29422953
Assert(!pgStatRunningInCollector);
@@ -2951,15 +2962,15 @@ pgstat_read_current_status(void)
29512962
localappname = (char *)
29522963
MemoryContextAlloc(pgStatLocalContext,
29532964
NAMEDATALEN * MaxBackends);
2965+
localactivity = (char *)
2966+
MemoryContextAlloc(pgStatLocalContext,
2967+
pgstat_track_activity_query_size * MaxBackends);
29542968
#ifdef USE_SSL
29552969
localsslstatus = (PgBackendSSLStatus *)
29562970
MemoryContextAlloc(pgStatLocalContext,
29572971
sizeof(PgBackendSSLStatus) * MaxBackends);
29582972
#endif
29592973

2960-
localactivity = (char *)
2961-
MemoryContextAlloc(pgStatLocalContext,
2962-
pgstat_track_activity_query_size * MaxBackends);
29632974
localNumBackends = 0;
29642975

29652976
beentry = BackendStatusArray;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy