pg_hba.conf - patch to report all parsing errors, and then bail - Mailing list pgsql-hackers

From Selena Deckelmann
Subject pg_hba.conf - patch to report all parsing errors, and then bail
Date
Msg-id 49B2B87E.2050001@endpoint.com
Whole thread Raw
Responses Re: pg_hba.conf - patch to report all parsing errors, and then bail  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Currently, load_hba() bails on the first parsing error. It would be
better for the typo-prone sysadmin if it reported ALL errors, and THEN
bailed out.

This patch implements that behavior.  Tested against 8.4 HEAD this morning.

Idea is to do a similar thing for postgresql.conf. That is a little more
complicated and will be a separate patch.

-selena


--
Selena Deckelmann
End Point Corporation
selena@endpoint.com
503-282-2512
diff --git a/src/backend/libpq/hba.c b/src/backend/libpq/hba.c
index 6923d06..c6a7ba7 100644
--- a/src/backend/libpq/hba.c
+++ b/src/backend/libpq/hba.c
@@ -1304,6 +1304,7 @@ load_hba(void)
     List *hba_line_nums = NIL;
     ListCell   *line, *line_num;
     List *new_parsed_lines = NIL;
+    bool OK = true;

     file = AllocateFile(HbaFileName, "r");
     if (file == NULL)
@@ -1332,17 +1333,22 @@ load_hba(void)

         if (!parse_hba_line(lfirst(line), lfirst_int(line_num), newline))
         {
-            /* Parse error in the file, so bail out */
+            /* Parse error in the file, so indicate there's a problem */
             free_hba_record(newline);
             pfree(newline);
             clean_hba_list(new_parsed_lines);
             /* Error has already been reported in the parsing function */
-            return false;
+            OK = false;
+            continue;
         }

         new_parsed_lines = lappend(new_parsed_lines, newline);
     }

+    if (!OK)
+        /* Parsing failed, so bail out */
+        return false;
+
     /* Loaded new file successfully, replace the one we use */
     clean_hba_list(parsed_hba_lines);
     parsed_hba_lines = new_parsed_lines;

pgsql-hackers by date:

Previous
From: Pavel Stehule
Date:
Subject: Re: Out parameters handling
Next
From: Tom Lane
Date:
Subject: Re: pg_hba.conf - patch to report all parsing errors, and then bail