agora inbox for pgsql-hackers@postgresql.org  
help / color / mirror / Atom feed
From: Andres Freund <andres@anarazel.de>
Subject: [PATCH v1 5/5] initdb: call isatty() only once in bootparse.y.
Date: Sun, 20 Feb 2022 13:39:40 -0800

Causes a not insignificant amount of syscalls...
---
 src/backend/bootstrap/bootparse.y | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/backend/bootstrap/bootparse.y b/src/backend/bootstrap/bootparse.y
index 142433f63f3..dff86f71583 100644
--- a/src/backend/bootstrap/bootparse.y
+++ b/src/backend/bootstrap/bootparse.y
@@ -62,11 +62,17 @@ do_start(void)
 static void
 do_end(void)
 {
+	static int isatty_cached = -1;
+
 	/* Reclaim memory allocated while processing this line */
 	MemoryContextSwitchTo(CurTransactionContext);
 	MemoryContextReset(per_line_ctx);
 	CHECK_FOR_INTERRUPTS();		/* allow SIGINT to kill bootstrap run */
-	if (isatty(0))
+
+	if (isatty_cached == -1)
+		isatty_cached = isatty(0);
+
+	if (isatty_cached)
 	{
 		printf("bootstrap> ");
 		fflush(stdout);
-- 
2.34.0


--soaxem2ryrapfc7g--





view thread (2+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: andres@anarazel.de
  Subject: Re: [PATCH v1 5/5] initdb: call isatty() only once in bootparse.y.
  In-Reply-To: <no-message-id-651315@localhost>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox