Subject: Quote-less file names in error messages

From: Kyotaro Horiguchi <[email-masked]>
Date: Fri, 04 Apr 2025 12:03:28 +0900 (JST)

Hello,

The recent commit 2da74d8d640 added the following new messages:

+		libpq_append_conn_error(conn, "could not open ssl keylog file %s: %s",
+		libpq_append_conn_error(conn, "could not write to ssl keylog file %s: %s

However, I believe our convention is to quote file names in such messages.

The attached patch 0001 fixes this issue.

While working on this, I found a few other instances of the same
issue:

- A WARNING message in `fd.c` seems worth fixing (0002).

- Two DEBUG2 messages in `xlog.c` seem less important to fix (0003).

- I don't think it's worth bothering with those in developer tools (0004).

Please find the attached patches.

regards.

-- 
Kyotaro Horiguchi
NTT Open Source Software Center
>From 408e4b89f7457dba3f96732addea2ee03a09ae5f Mon Sep 17 00:00:00 2001
From: Kyotaro Horiguchi <[email-masked]>
Date: Fri, 4 Apr 2025 11:30:12 +0900
Subject: [PATCH 1/4] Quote file names in recently introduced error messages

Add missing quotes around file names in the messages added by
recent commit 2da74d8d640.
---
 src/interfaces/libpq/fe-secure-openssl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/interfaces/libpq/fe-secure-openssl.c b/src/interfaces/libpq/fe-secure-openssl.c
index 4bfd8e0447c..78f9e84eb35 100644
--- a/src/interfaces/libpq/fe-secure-openssl.c
+++ b/src/interfaces/libpq/fe-secure-openssl.c
@@ -711,7 +711,7 @@ SSL_CTX_keylog_cb(const SSL *ssl, const char *line)
 
 	if (fd == -1)
 	{
-		libpq_append_conn_error(conn, "could not open ssl keylog file %s: %s",
+		libpq_append_conn_error(conn, "could not open ssl keylog file \"%s\": %s",
 								conn->sslkeylogfile, pg_strerror(errno));
 		return;
 	}
@@ -719,7 +719,7 @@ SSL_CTX_keylog_cb(const SSL *ssl, const char *line)
 	/* line is guaranteed by OpenSSL to be NUL terminated */
 	rc = write(fd, line, strlen(line));
 	if (rc < 0)
-		libpq_append_conn_error(conn, "could not write to ssl keylog file %s: %s",
+		libpq_append_conn_error(conn, "could not write to ssl keylog file \"%s\": %s",
 								conn->sslkeylogfile, pg_strerror(errno));
 	else
 		rc = write(fd, "\n", 1);
-- 
2.43.5

>From d761188a30b9543e7e1ecb71b6f3c5a64cb41dcf Mon Sep 17 00:00:00 2001
From: Kyotaro Horiguchi <[email-masked]>
Date: Fri, 4 Apr 2025 11:34:10 +0900
Subject: [PATCH 2/4] Quote file names in an exising WARNING message

Add a missing pair of quotes around a file name in an existing WARNING
message in fd.c.
---
 src/backend/storage/file/fd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c
index 0e8299dd556..7f74d3be258 100644
--- a/src/backend/storage/file/fd.c
+++ b/src/backend/storage/file/fd.c
@@ -3293,7 +3293,7 @@ CleanupTempFiles(bool isCommit, bool isProcExit)
 				else if (fdstate & FD_CLOSE_AT_EOXACT)
 				{
 					elog(WARNING,
-						 "temporary file %s not closed at end-of-transaction",
+						 "temporary file \"%s\" not closed at end-of-transaction",
 						 VfdCache[i].fileName);
 					FileClose(i);
 				}
-- 
2.43.5

>From 19d6bfdc9399c2e1dc0c933fdc6b4491851c55ca Mon Sep 17 00:00:00 2001
From: Kyotaro Horiguchi <[email-masked]>
Date: Fri, 4 Apr 2025 11:42:23 +0900
Subject: [PATCH 3/4] Quote file names in existing DEBUG2 messages

Add missing quotes around file names in existing DEBUG2 messages in
xlog.c.
---
 src/backend/access/transam/xlog.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index ec40c0b7c42..083d1a17272 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -4021,7 +4021,7 @@ RemoveOldXlogFiles(XLogSegNo segno, XLogRecPtr lastredoptr, XLogRecPtr endptr,
 	 */
 	XLogFileName(lastoff, 0, segno, wal_segment_size);
 
-	elog(DEBUG2, "attempting to remove WAL segments older than log file %s",
+	elog(DEBUG2, "attempting to remove WAL segments older than log file \"%s\"",
 		 lastoff);
 
 	xldir = AllocateDir(XLOGDIR);
@@ -4098,7 +4098,7 @@ RemoveNonParentXlogFiles(XLogRecPtr switchpoint, TimeLineID newTLI)
 	 */
 	XLogFileName(switchseg, newTLI, switchLogSegNo, wal_segment_size);
 
-	elog(DEBUG2, "attempting to remove WAL segments newer than log file %s",
+	elog(DEBUG2, "attempting to remove WAL segments newer than log file \"%s\"",
 		 switchseg);
 
 	xldir = AllocateDir(XLOGDIR);
-- 
2.43.5

>From fd283b2a8ad28f25054c86fa8cadba4f1b982a12 Mon Sep 17 00:00:00 2001
From: Kyotaro Horiguchi <[email-masked]>
Date: Fri, 4 Apr 2025 11:45:54 +0900
Subject: [PATCH 4/4] Quote file names in developer tool messages

Add missing quotes around file names in some messages in developer tools.
---
 src/interfaces/ecpg/test/pg_regress_ecpg.c | 10 +++++-----
 src/tools/pg_bsd_indent/args.c             |  2 +-
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/interfaces/ecpg/test/pg_regress_ecpg.c b/src/interfaces/ecpg/test/pg_regress_ecpg.c
index ba3477f9dd8..88ccb58433d 100644
--- a/src/interfaces/ecpg/test/pg_regress_ecpg.c
+++ b/src/interfaces/ecpg/test/pg_regress_ecpg.c
@@ -40,13 +40,13 @@ ecpg_filter_source(const char *sourcefile, const char *outfile)
 	s = fopen(sourcefile, "r");
 	if (!s)
 	{
-		fprintf(stderr, "Could not open file %s for reading\n", sourcefile);
+		fprintf(stderr, "Could not open file \"%s\" for reading\n", sourcefile);
 		exit(2);
 	}
 	t = fopen(outfile, "w");
 	if (!t)
 	{
-		fprintf(stderr, "Could not open file %s for writing\n", outfile);
+		fprintf(stderr, "Could not open file \"%s\” for writing\n", outfile);
 		exit(2);
 	}
 
@@ -99,13 +99,13 @@ ecpg_filter_stderr(const char *resultfile, const char *tmpfile)
 	s = fopen(resultfile, "r");
 	if (!s)
 	{
-		fprintf(stderr, "Could not open file %s for reading\n", resultfile);
+		fprintf(stderr, "Could not open file \"%s\" for reading\n", resultfile);
 		exit(2);
 	}
 	t = fopen(tmpfile, "w");
 	if (!t)
 	{
-		fprintf(stderr, "Could not open file %s for writing\n", tmpfile);
+		fprintf(stderr, "Could not open file \"%s\" for writing\n", tmpfile);
 		exit(2);
 	}
 
@@ -133,7 +133,7 @@ ecpg_filter_stderr(const char *resultfile, const char *tmpfile)
 	fclose(t);
 	if (rename(tmpfile, resultfile) != 0)
 	{
-		fprintf(stderr, "Could not overwrite file %s with %s\n",
+		fprintf(stderr, "Could not overwrite file \"%s\" with \"%s\"\n",
 				resultfile, tmpfile);
 		exit(2);
 	}
diff --git a/src/tools/pg_bsd_indent/args.c b/src/tools/pg_bsd_indent/args.c
index 5fa7e6b038c..c76cfd7b686 100644
--- a/src/tools/pg_bsd_indent/args.c
+++ b/src/tools/pg_bsd_indent/args.c
@@ -338,7 +338,7 @@ add_typedefs_from_file(const char *str)
     char line[BUFSIZ];
 
     if ((file = fopen(str, "r")) == NULL) {
-	fprintf(stderr, "indent: cannot open file %s\n", str);
+	fprintf(stderr, "indent: cannot open file \"%s\"\n", str);
 	exit(1);
     }
     while ((fgets(line, BUFSIZ, file)) != NULL) {
-- 
2.43.5

---

From: Daniel Gustafsson <[email-masked]>
Date: Fri, 4 Apr 2025 09:40:01 +0200

> On 4 Apr 2025, at 05:03, Kyotaro Horiguchi <[email-masked]> wrote:
> 
> Hello,
> 

Thanks for the report, I'll get it fixed.

> - A WARNING message in `fd.c` seems worth fixing (0002).

Thi is an elog() and not an error intended to be common for users, so I'm not
sure it's worth the churn really as it's been there since 2012.  Changing it
might introduce conflicts in backpatching for little gain.

> - I don't think it's worth bothering with those in developer tools (0004).

Agreed.

--
Daniel Gustafsson