Feature: Check if socket file exists at startup and remove them if PID file doesn...
authorBo Peng <pengbo@sraoss.co.jp>
Tue, 28 Jan 2020 06:20:46 +0000 (15:20 +0900)
committerBo Peng <pengbo@sraoss.co.jp>
Tue, 28 Jan 2020 06:25:02 +0000 (15:25 +0900)
If the previuos socket files exist, pgpool startup fails due to bind() failire.
This commit is to remove socket files at startup if PID file doesn't exist.

Also, I found some messages are effectively ignorede because log system is not yet initialized at start point.
I changed them to standard fprintf(stderr...).

src/main/main.c
src/main/pgpool_main.c

index eec3c3e4868e4772d675d59fb8b54b8297988e4d..cc3d48df354e6b72e77ab6aea39d8cb5d657df4e 100644 (file)
@@ -278,12 +278,11 @@ main(int argc, char **argv)
                {
                        if (kill(pid, 0) == 0)
                        {
-                               ereport(FATAL,
-                                               (errmsg("pid file found. is another pgpool(%d) is running?\n", pid)));
+                               fprintf(stderr, "ERROR: pid file found. is another pgpool(%d) is running?\n", pid);
+                               exit(EXIT_FAILURE);
                        }
                        else
-                               ereport(NOTICE,
-                                               (errmsg("pid file found but it seems bogus. Trying to start pgpool anyway...\n")));
+                               fprintf(stderr, "NOTICE: pid file found but it seems bogus. Trying to start pgpool anyway...\n");
                }
        }
 
index 626644631dbe8dee78baa8a7afcb9f9bc0a49cf6..f0b01434b9897f6d9b37bcfed33a4a238a5c6f9e 100644 (file)
@@ -960,6 +960,9 @@ create_unix_domain_socket(struct sockaddr_un un_addr_tmp)
        int                     status;
        int                     len;
 
+       /* Delete any pre-existing socket file to avoid failure at bind() time */
+       unlink(un_addr_tmp.sun_path);
+
        fd = socket(AF_UNIX, SOCK_STREAM, 0);
        if (fd == -1)
        {