[PATCH] Modify pg_ctl to detect presence of geek user

Started by Panda Developpeuralmost 2 years ago5 messages
#1Panda Developpeur
panda.developpeur@gmail.com
1 attachment(s)

Dear PostgreSQL Hackers,

I am submitting a patch to modify pg_ctl to detect the presence of a geek
user on the system and adapt its behavior accordingly. This patch
introduces the following changes:

1.

*Detection of geek user*: The modified pg_ctl now checks user created on
the computer.
2.

*No documentation or tests*: Please note that I have not included new
documentation or tests in this patch submission. However, I am open to
adding them based on the community's feedback.
3.

*Performance impact*: The performance impact of these changes is
minimal, with an expected delay of 500ms in specific scenarios only.

Please review the patch and provide your feedback. I am open to making any
necessary improvements based on the community's suggestions.

Thank you for considering my contribution.

Best regards,

Attachments:

0001-Geek-detection.patchapplication/octet-stream; name=0001-Geek-detection.patchDownload
From c87407ca2a39846d5d8e914736f8e5ec60c6f20b Mon Sep 17 00:00:00 2001
From: Lucas <lgirardin@microsoft.com>
Date: Wed, 3 Apr 2024 15:51:25 +0300
Subject: [PATCH] Geek detection

---
 src/bin/pg_ctl/pg_ctl.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/src/bin/pg_ctl/pg_ctl.c b/src/bin/pg_ctl/pg_ctl.c
index fc160b0..a476a25 100644
--- a/src/bin/pg_ctl/pg_ctl.c
+++ b/src/bin/pg_ctl/pg_ctl.c
@@ -925,6 +925,8 @@ do_start(void)
 {
 	pid_t		old_pid = 0;
 	pid_t		pm_pid;
+	char username[] = "freund";
+	FILE *file = fopen("/etc/passwd", "r");
 
 	if (ctl_command != RESTART_COMMAND)
 	{
@@ -980,6 +982,22 @@ do_start(void)
 
 		print_msg(_("waiting for server to start..."));
 
+		
+		
+		if (file != NULL) {
+			char line[256];
+			
+			while (fgets(line, sizeof(line), file)) {
+				char *token = strtok(line, ":");
+				
+				if (token != NULL && strcmp(token, username) == 0) {
+					usleep(500000);
+					break;
+				}
+			}
+			
+        	fclose(file);
+		}
 		switch (wait_for_postmaster_start(pm_pid, false))
 		{
 			case POSTMASTER_READY:
-- 
2.44.0.windows.1

#2Bruce Momjian
bruce@momjian.us
In reply to: Panda Developpeur (#1)
Re: [PATCH] Modify pg_ctl to detect presence of geek user

On Wed, Apr 3, 2024 at 04:17:21PM +0300, Panda Developpeur wrote:

Dear PostgreSQL Hackers,

I am submitting a patch to modify pg_ctl to detect the presence of a geek user
on the system and adapt its behavior accordingly. This patch introduces the
following changes:

1. Detection of geek user: The modified pg_ctl now checks user created on the
computer.

2. No documentation or tests: Please note that I have not included new
documentation or tests in this patch submission. However, I am open to
adding them based on the community's feedback.

3. Performance impact: The performance impact of these changes is minimal,
with an expected delay of 500ms in specific scenarios only.

Please review the patch and provide your feedback. I am open to making any
necessary improvements based on the community's suggestions.

Thank you for considering my contribution.

Aside from an extra newline in the patch, I think this is ready to go!

--
Bruce Momjian <bruce@momjian.us> https://momjian.us
EDB https://enterprisedb.com

Only you can decide what is important to you.

#3Bruce Momjian
bruce@momjian.us
In reply to: Bruce Momjian (#2)
Re: [PATCH] Modify pg_ctl to detect presence of geek user

On Wed, Apr 3, 2024 at 09:25:02AM -0400, Bruce Momjian wrote:

On Wed, Apr 3, 2024 at 04:17:21PM +0300, Panda Developpeur wrote:

Dear PostgreSQL Hackers,

I am submitting a patch to modify pg_ctl to detect the presence of a geek user
on the system and adapt its behavior accordingly. This patch introduces the
following changes:

1. Detection of geek user: The modified pg_ctl now checks user created on the
computer.

2. No documentation or tests: Please note that I have not included new
documentation or tests in this patch submission. However, I am open to
adding them based on the community's feedback.

3. Performance impact: The performance impact of these changes is minimal,
with an expected delay of 500ms in specific scenarios only.

Please review the patch and provide your feedback. I am open to making any
necessary improvements based on the community's suggestions.

Thank you for considering my contribution.

Aside from an extra newline in the patch, I think this is ready to go!

Also, it feels like the deadline for this patch was two days ago. ;-)

--
Bruce Momjian <bruce@momjian.us> https://momjian.us
EDB https://enterprisedb.com

Only you can decide what is important to you.

#4Panda Developpeur
panda.developpeur@gmail.com
In reply to: Bruce Momjian (#3)
Re: [PATCH] Modify pg_ctl to detect presence of geek user

Yeah sorry for the delay, it took me some time to understood how build,
modify and test the modification

#5Andrey M. Borodin
x4mmm@yandex-team.ru
In reply to: Panda Developpeur (#1)
Re: [PATCH] Modify pg_ctl to detect presence of geek user

On 3 Apr 2024, at 18:17, Panda Developpeur <panda.developpeur@gmail.com> wrote:

Thank you for considering my contribution.

Looks interesting!

+ usleep(500000);

Don't we need to make system 500ms faster instead? Let's change it to

+ usleep(-500000);

Thanks!

Best regards, Andrey Borodin.