From 76b4c5001ead337d3cb221b65488998ed2589afb Mon Sep 17 00:00:00 2001 From: Victor Polevoy Date: Mon, 14 Jul 2025 18:51:27 +0200 Subject: [PATCH] Use shmem instead of a buffer --- pgxn/neon/communicator/src/neon_request.rs | 4 +-- pgxn/neon/communicator_new.c | 30 +++++++++++----------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/pgxn/neon/communicator/src/neon_request.rs b/pgxn/neon/communicator/src/neon_request.rs index 20f896651d..98bdbb8822 100644 --- a/pgxn/neon/communicator/src/neon_request.rs +++ b/pgxn/neon/communicator/src/neon_request.rs @@ -190,13 +190,13 @@ pub struct CReadSlruSegmentRequest { pub request_lsn: CLsn, /// Must be a null-terminated C string containing **absolute** /// file path. - pub destination_file_path: [std::ffi::c_char; libc::PATH_MAX as usize], + pub destination_file_path: ShmemBuf, } impl CReadSlruSegmentRequest { /// Returns the path to the file where the segment is read into. pub(crate) fn destination_file_path(&self) -> String { - unsafe { CStr::from_ptr(self.destination_file_path.as_ptr()) } + unsafe { CStr::from_ptr(self.destination_file_path.as_mut_ptr() as *const _) } .to_string_lossy() .into_owned() } diff --git a/pgxn/neon/communicator_new.c b/pgxn/neon/communicator_new.c index b14fd5a9f8..a7225e78e7 100644 --- a/pgxn/neon/communicator_new.c +++ b/pgxn/neon/communicator_new.c @@ -1021,28 +1021,28 @@ communicator_new_read_slru_segment( } // Scoping should help deallocate the absolute path buffer. - { - char abs_path[PATH_MAX]; + char *abs_path = bounce_buf(); - if (path[0] != '/') { - char cwd[PATH_MAX]; - getcwd(cwd, sizeof(cwd)); + if (path[0] != '/') { + char cwd[PATH_MAX]; + getcwd(cwd, sizeof(cwd)); - const int size = snprintf(NULL, 0, "%s/%s", cwd, path); - if (size < 0 || size >= PATH_MAX) { - elog(ERROR, "read_slru_segment failed to create an absolute path for \"%s\"", path); - return -1; - } + const int size = snprintf(NULL, 0, "%s/%s", cwd, path); - snprintf(abs_path, size + 1, "%s/%s", cwd, path); - } else { - strncpy(abs_path, path, sizeof(abs_path)); + if (size < 0 || size >= PATH_MAX) { + elog(ERROR, "read_slru_segment failed to create an absolute path for \"%s\"", path); + return -1; } - strncpy(request.read_slru_segment.destination_file_path, abs_path, sizeof(request.read_slru_segment.destination_file_path)); + + snprintf(abs_path, size + 1, "%s/%s", cwd, path); + } else { + strncpy(abs_path, path, sizeof(abs_path)); } + request.read_slru_segment.destination_file_path.ptr = abs_path; + elog(DEBUG5, "readslrusegment called for kind=%u, segno=%u, file_path=\"%s\"", - kind, segno, request.read_slru_segment.destination_file_path); + kind, segno, request.read_slru_segment.destination_file_path.ptr); /* FIXME: see `request_lsns` in main_loop.rs for why this is needed */ XLogSetAsyncXactLSN(request_lsns->request_lsn);