Skip to content

Commit 792263a

Browse files
committed
fix parsing; resolve comments
Signed-off-by: Alex Chi Z <[email protected]>
1 parent d60fa40 commit 792263a

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

pageserver/src/page_service.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -2560,12 +2560,20 @@ where
25602560
tracing::warn!("failed to parse the startup options: {options}");
25612561
break;
25622562
}
2563-
} else if parsing_config {
2564-
let Some((key, value)) = item.split_once('=') else {
2563+
} else if item.starts_with("-c") || parsing_config {
2564+
let Some((mut key, value)) = item.split_once('=') else {
25652565
// "-c" followed with an invalid option
25662566
tracing::warn!("failed to parse the startup options: {options}");
25672567
break;
25682568
};
2569+
if !parsing_config {
2570+
// Parse "-coptions=X"
2571+
let Some(stripped_key) = key.strip_prefix("-c") else {
2572+
tracing::warn!("failed to parse the startup options: {options}");
2573+
break;
2574+
};
2575+
key = stripped_key;
2576+
}
25692577
if key == "neon.endpoint_type" {
25702578
Span::current().record("endpoint_type", field::display(value));
25712579
} else {

pgxn/neon/libpagestore.c

+5-8
Original file line numberDiff line numberDiff line change
@@ -407,8 +407,8 @@ pageserver_connect(shardno_t shard_no, int elevel)
407407
{
408408
const char *keywords[5];
409409
const char *values[5];
410-
char pid_str[16];
411-
char endpoint_str[36];
410+
char pid_str[16] = { 0 };
411+
char endpoint_str[36] = { 0 };
412412
int n_pgsql_params;
413413
TimestampTz now;
414414
int64 us_since_last_attempt;
@@ -481,25 +481,22 @@ pageserver_connect(shardno_t shard_no, int elevel)
481481
}
482482

483483
{
484-
int ret = 0;
485484
bool param_set = false;
486485
switch (neon_endpoint_type)
487486
{
488487
case EP_TYPE_PRIMARY:
489-
ret = snprintf(endpoint_str, sizeof(endpoint_str), "-c neon.endpoint_type=primary");
488+
strncpy(endpoint_str, "-c neon.endpoint_type=primary", sizeof(endpoint_str));
490489
param_set = true;
491490
break;
492491
case EP_TYPE_REPLICA:
493-
ret = snprintf(endpoint_str, sizeof(endpoint_str), "-c neon.endpoint_type=replica");
492+
strncpy(endpoint_str, "-c neon.endpoint_type=replica", sizeof(endpoint_str));
494493
param_set = true;
495494
break;
496495
case EP_TYPE_STATIC:
497-
ret = snprintf(endpoint_str, sizeof(endpoint_str), "-c neon.endpoint_type=static");
496+
strncpy(endpoint_str, "-c neon.endpoint_type=static", sizeof(endpoint_str));
498497
param_set = true;
499498
break;
500499
}
501-
if (ret < 0 || ret >= (int)(sizeof(endpoint_str)))
502-
elog(FATAL, "stack-allocated buffer too small to hold endpoint type");
503500
if (param_set)
504501
{
505502
keywords[n_pgsql_params] = "options";

0 commit comments

Comments
 (0)