View Issue Details

IDProjectCategoryView StatusLast Update
0000001Pgpool-IIEnhancementpublic2012-02-20 19:45
Reportersean@chittenden.orgAssigned To 
PrioritynormalSeveritytweakReproducibilityalways
Status newResolutionopen 
Product Version 
Target VersionFixed in Version 
Summary0000001: Make pid_file optional
DescriptionAttached patch makes the use of a pid file optional. Internally I changed the meaning of NULL to mean "use the default PID filename", an empty string means no pid file, and a non-zero length pid filename means a valid pid file.
Steps To Reproducepatch -p1 < pid_file.patch
TagsNo tags attached.

Activities

sean@chittenden.org

2012-01-11 14:04

reporter   ~0000001

Use pid_file_v2 patch. I changed it so that a value of "-" uses no PID file instead of an empty string.

kitagawa

2012-02-20 19:45

developer  

pid_file.patch (3,237 bytes)
diff --git a/doc/pgpool-en.html b/doc/pgpool-en.html
index 933f620..d66ee95 100644
--- a/doc/pgpool-en.html
+++ b/doc/pgpool-en.html
@@ -598,7 +598,7 @@ max_pool*num_init_children*2 <= (max_connections - superuser_reserved_connection
   <dt><a name="PID_FILE_NAME"></a>pid_file_name</dt>
   <dd>
       <p>Full path to a file which contains pgpool's process id.
-	    Default is "/var/run/pgpool/pgpool.pid".
+	    Default is "/var/run/pgpool/pgpool.pid". When set to an empty string, no PID file will be used (thereby disabling the stop command, but useful when running under runit or daemontools).
       You need to restart pgpool-II if you change this value.
        </p>
   </dd>
diff --git a/main.c b/main.c
index 123e899..f13fb13 100644
--- a/main.c
+++ b/main.c
@@ -350,16 +350,21 @@ int main(int argc, char **argv)
 	{
 		if (!strcmp(argv[optind], "reload"))
 		{
-				pid_t pid;
-
-				pid = read_pid_file();
-				if (pid < 0)
-				{
-					pool_error("could not read pid file");
-					pool_shmem_exit(1);
-					exit(1);
-				}
+			pid_t pid;
 
+			pid = read_pid_file();
+			if (pid < 0)
+			{
+				pool_error("could not read pid file");
+				pool_shmem_exit(1);
+				exit(1);
+			}
+			else if (pid == 0)
+			{
+				/* Noop, nothing to do with an empty PID */
+			}
+			else
+			{
 				if (kill(pid, SIGHUP) == -1)
 				{
 					pool_error("could not reload configuration file pid: %d. reason: %s", pid, strerror(errno));
@@ -368,6 +373,7 @@ int main(int argc, char **argv)
 				}
 				pool_shmem_exit(0);
 				exit(0);
+			}
 		}
 		if (!strcmp(argv[optind], "stop"))
 		{
@@ -843,10 +849,10 @@ static void usage(void)
 */
 static void daemonize(void)
 {
-	int			i;
+	int		i;
 	pid_t		pid;
-	int			fdlimit;
-    int         rc_chdir;
+	int		fdlimit;
+	int		rc_chdir;
 
 	pid = fork();
 	if (pid == (pid_t) -1)
@@ -880,8 +886,8 @@ static void daemonize(void)
 	dup2(i, 1);
 	dup2(i, 2);
 
-    fdlimit = sysconf(_SC_OPEN_MAX);
-    for (i = 3; i < fdlimit; i++)
+	fdlimit = sysconf(_SC_OPEN_MAX);
+	for (i = 3; i < fdlimit; i++)
 		close(i);
 
 	write_pid_file();
@@ -902,6 +908,11 @@ static void stop_me(void)
 		pool_shmem_exit(1);
 		exit(1);
 	}
+	else if (pid == 0)
+	{
+		pool_error("could not stop, no pid file specified");
+		exit(1);
+	}
 
 	if (kill(pid, stop_sig) == -1)
 	{
@@ -928,6 +939,17 @@ static int read_pid_file(void)
 	FILE *fd;
 	char pidbuf[128];
 
+	if (pool_config->pid_file_name == NULL)
+	{
+		/* Use the default PID file name*/
+		pool_config->pid_file_name = DEFAULT_PID_FILE_NAME;
+	}
+	else if (strlen(pool_config->pid_file_name) == 0)
+	{
+		/* An empty string means no PID */
+		return 0;
+	}
+
 	fd = fopen(pool_config->pid_file_name, "r");
 	if (!fd)
 	{
@@ -952,6 +974,12 @@ static void write_pid_file(void)
 	FILE *fd;
 	char pidbuf[128];
 
+	if (strlen(pool_config->pid_file_name) == 0)
+	{
+		/* noop, no pid file configured */
+		return;
+	}
+
 	fd = fopen(pool_config->pid_file_name, "w");
 	if (!fd)
 	{
@@ -1339,7 +1367,10 @@ static void myexit(int code)
 
 	myunlink(un_addr.sun_path);
 	myunlink(pcp_un_addr.sun_path);
-	myunlink(pool_config->pid_file_name);
+	if (strlen(pool_config->pid_file_name) > 0)
+	{
+		myunlink(pool_config->pid_file_name);
+	}
 
 	write_status_file();
 

pid_file.patch (3,237 bytes)

kitagawa

2012-02-20 19:45

developer  

pid_file_v2.patch (3,244 bytes)
diff --git a/doc/pgpool-en.html b/doc/pgpool-en.html
index 933f620..af1c698 100644
--- a/doc/pgpool-en.html
+++ b/doc/pgpool-en.html
@@ -598,7 +598,7 @@ max_pool*num_init_children*2 <= (max_connections - superuser_reserved_connection
   <dt><a name="PID_FILE_NAME"></a>pid_file_name</dt>
   <dd>
       <p>Full path to a file which contains pgpool's process id.
-	    Default is "/var/run/pgpool/pgpool.pid".
+	    Default is "/var/run/pgpool/pgpool.pid". When set to a "-", no PID file will be used (thereby disabling the stop command, but useful when running under runit or daemontools).
       You need to restart pgpool-II if you change this value.
        </p>
   </dd>
diff --git a/main.c b/main.c
index 123e899..f67eb99 100644
--- a/main.c
+++ b/main.c
@@ -350,16 +350,21 @@ int main(int argc, char **argv)
 	{
 		if (!strcmp(argv[optind], "reload"))
 		{
-				pid_t pid;
-
-				pid = read_pid_file();
-				if (pid < 0)
-				{
-					pool_error("could not read pid file");
-					pool_shmem_exit(1);
-					exit(1);
-				}
+			pid_t pid;
 
+			pid = read_pid_file();
+			if (pid < 0)
+			{
+				pool_error("could not read pid file");
+				pool_shmem_exit(1);
+				exit(1);
+			}
+			else if (pid == 0)
+			{
+				/* Noop, nothing to do with an empty PID */
+			}
+			else
+			{
 				if (kill(pid, SIGHUP) == -1)
 				{
 					pool_error("could not reload configuration file pid: %d. reason: %s", pid, strerror(errno));
@@ -368,6 +373,7 @@ int main(int argc, char **argv)
 				}
 				pool_shmem_exit(0);
 				exit(0);
+			}
 		}
 		if (!strcmp(argv[optind], "stop"))
 		{
@@ -843,10 +849,10 @@ static void usage(void)
 */
 static void daemonize(void)
 {
-	int			i;
+	int		i;
 	pid_t		pid;
-	int			fdlimit;
-    int         rc_chdir;
+	int		fdlimit;
+	int		rc_chdir;
 
 	pid = fork();
 	if (pid == (pid_t) -1)
@@ -880,8 +886,8 @@ static void daemonize(void)
 	dup2(i, 1);
 	dup2(i, 2);
 
-    fdlimit = sysconf(_SC_OPEN_MAX);
-    for (i = 3; i < fdlimit; i++)
+	fdlimit = sysconf(_SC_OPEN_MAX);
+	for (i = 3; i < fdlimit; i++)
 		close(i);
 
 	write_pid_file();
@@ -902,6 +908,11 @@ static void stop_me(void)
 		pool_shmem_exit(1);
 		exit(1);
 	}
+	else if (pid == 0)
+	{
+		pool_error("could not stop, no pid file specified");
+		exit(1);
+	}
 
 	if (kill(pid, stop_sig) == -1)
 	{
@@ -928,6 +939,17 @@ static int read_pid_file(void)
 	FILE *fd;
 	char pidbuf[128];
 
+	if (pool_config->pid_file_name == NULL)
+	{
+		/* Use the default PID file name*/
+		pool_config->pid_file_name = DEFAULT_PID_FILE_NAME;
+	}
+	else if (strcmp(pool_config->pid_file_name, "-") == 0)
+	{
+		/* An empty string means no PID */
+		return 0;
+	}
+
 	fd = fopen(pool_config->pid_file_name, "r");
 	if (!fd)
 	{
@@ -952,6 +974,12 @@ static void write_pid_file(void)
 	FILE *fd;
 	char pidbuf[128];
 
+	if (strcmp(pool_config->pid_file_name, "-") == 0)
+	{
+		/* noop, no pid file configured */
+		return;
+	}
+
 	fd = fopen(pool_config->pid_file_name, "w");
 	if (!fd)
 	{
@@ -1339,7 +1367,10 @@ static void myexit(int code)
 
 	myunlink(un_addr.sun_path);
 	myunlink(pcp_un_addr.sun_path);
-	myunlink(pool_config->pid_file_name);
+	if (strcmp(pool_config->pid_file_name, "-") !=  0)
+	{
+		myunlink(pool_config->pid_file_name);
+	}
 
 	write_status_file();
 

pid_file_v2.patch (3,244 bytes)

Issue History

Date Modified Username Field Change
2012-01-11 13:19 sean@chittenden.org New Issue
2012-01-11 13:19 sean@chittenden.org File Added: pid_file.patch
2012-01-11 14:03 sean@chittenden.org File Added: pid_file_v2.patch
2012-01-11 14:04 sean@chittenden.org Note Added: 0000001
2012-02-20 19:44 kitagawa File Deleted: pid_file.patch
2012-02-20 19:44 kitagawa File Deleted: pid_file_v2.patch
2012-02-20 19:45 kitagawa File Added: pid_file.patch
2012-02-20 19:45 kitagawa File Added: pid_file_v2.patch