Make SIGHUP less painful if pg_hba.conf is not readable - Mailing list pgsql-hackers

From Selena Deckelmann
Subject Make SIGHUP less painful if pg_hba.conf is not readable
Date
Msg-id 49ADDF6E.5080903@endpoint.com
Whole thread Raw
Responses Re: Make SIGHUP less painful if pg_hba.conf is not readable  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
This is my first patch. I hope it's not stupid.

We ran into a little issue today where permission/ownership on
pg_hba.conf was accidentally changed to something that the postgres user
could not read.  When a SIGHUP was issued, the postmaster quit. That was
kind of a bummer.

>From the comment in hba.c, it appears that the desired behavior is to
have the system ignore the failure, and continue using what's already
loaded into memory.  And, turns out, that's what I would like Postgres
to do as well.

So, this patch changes the error issued from load_hba() from FATAL to
WARNING if the file is not found, and returns.

Startup behavior (FATAL if pg_hba.conf can't be found) is not changed.

Tested against 8.4devel HEAD today.

Patch attached.

--
Selena Deckelmann
End Point Corporation
selena@endpoint.com

diff --git a/src/backend/libpq/hba.c b/src/backend/libpq/hba.c
index a134b45..931ca86 100644
--- a/src/backend/libpq/hba.c
+++ b/src/backend/libpq/hba.c
@@ -1307,11 +1307,14 @@ load_hba(void)

     file = AllocateFile(HbaFileName, "r");
     /* Failure is fatal since with no HBA entries we can do nothing... */
-    if (file == NULL)
-        ereport(FATAL,
+    if (file == NULL)
+    {
+        ereport(WARNING,
                 (errcode_for_file_access(),
                  errmsg("could not open configuration file \"%s\": %m",
                         HbaFileName)));
+        return false;
+    }

     tokenize_file(HbaFileName, file, &hba_lines, &hba_line_nums);
     FreeFile(file);

pgsql-hackers by date:

Previous
From: Fujii Masao
Date:
Subject: Re: Immediate shutdown and system(3)
Next
From: Emmanuel Cecchet
Date:
Subject: Regclass and quoted table names