Thread: Syslog Facility Patch

Syslog Facility Patch

From
Larry Rosenman
Date:
Here is a patch for allowing the syslog facility to be set.


Index: doc/src/sgml/runtime.sgml
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/doc/src/sgml/runtime.sgml,v
retrieving revision 1.33
diff -c -r1.33 runtime.sgml
*** doc/src/sgml/runtime.sgml    2000/11/10 16:32:09    1.33
--- doc/src/sgml/runtime.sgml    2000/11/12 17:13:37
***************
*** 822,827 ****
--- 822,839 ----      </varlistentry>       <varlistentry>
+       <term>SYSLOG_FACILITY (<type>string</type>)</term>
+        <listitem>
+         <para>
+           If the SYSLOG option is set to 1 or greater, this option determines
+           the <application>syslog</application> facility used.  You may choose
+           from LOCAL0, LOCAL1, LOCAL2, LOCAL3, LOCAL4, LOCAL5, LOCAL6, LOCAL7.
+           the default is LOCAL0
+         </para>
+        </listitem>
+      </varlistentry>
+ 
+      <varlistentry>       <term>TRACE_NOTIFY (<type>boolean</type>)</term>       <listitem>        <para>
Index: src/backend/utils/error/elog.c
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/utils/error/elog.c,v
retrieving revision 1.65
diff -c -r1.65 elog.c
*** src/backend/utils/error/elog.c    2000/10/30 06:48:36    1.65
--- src/backend/utils/error/elog.c    2000/11/12 17:13:39
***************
*** 58,63 ****
--- 58,64 ----  * ... in theory anyway  */ int Use_syslog = 0;
+ char *Syslog_facility = "LOCAL0";  static void write_syslog(int level, const char *line); 
***************
*** 620,625 ****
--- 621,627 ----      static bool    openlog_done = false;     static unsigned long seq = 0;
+     static int    syslog_fac = LOG_LOCAL0;     int len = strlen(line);      if (Use_syslog == 0)
***************
*** 627,633 ****      if (!openlog_done)     {
!         openlog("postgres", LOG_PID | LOG_NDELAY, LOG_LOCAL0);         openlog_done = true;     } 
--- 629,651 ----      if (!openlog_done)     {
!         if (strcmp(Syslog_facility,"LOCAL0") == 0) 
!             syslog_fac = LOG_LOCAL0;
!         if (strcmp(Syslog_facility,"LOCAL1") == 0)
!             syslog_fac = LOG_LOCAL1;
!         if (strcmp(Syslog_facility,"LOCAL2") == 0)
!             syslog_fac = LOG_LOCAL2;
!         if (strcmp(Syslog_facility,"LOCAL3") == 0)
!             syslog_fac = LOG_LOCAL3;
!         if (strcmp(Syslog_facility,"LOCAL4") == 0)
!             syslog_fac = LOG_LOCAL4;
!         if (strcmp(Syslog_facility,"LOCAL5") == 0)
!             syslog_fac = LOG_LOCAL5;
!         if (strcmp(Syslog_facility,"LOCAL6") == 0)
!             syslog_fac = LOG_LOCAL6;
!         if (strcmp(Syslog_facility,"LOCAL7") == 0)
!             syslog_fac = LOG_LOCAL7;
!         openlog("postgres", LOG_PID | LOG_NDELAY, syslog_fac);         openlog_done = true;     } 
Index: src/backend/utils/misc/guc.c
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/utils/misc/guc.c,v
retrieving revision 1.16
diff -c -r1.16 guc.c
*** src/backend/utils/misc/guc.c    2000/11/09 11:25:59    1.16
--- src/backend/utils/misc/guc.c    2000/11/12 17:13:39
***************
*** 39,44 ****
--- 39,45 ---- extern int CheckPointTimeout; extern int XLOGbuffers; extern int XLOG_DEBUG;
+ extern char * Syslog_facility;  /*  * Debugging options
***************
*** 303,308 ****
--- 304,312 ----      {"unix_socket_group",         PGC_POSTMASTER,       &Unix_socket_group,      "", NULL},
+ #ifdef ENABLE_SYSLOG
+     {"syslog_facility",    PGC_SIGHUP,    &Syslog_facility, "LOCAL0", NULL},     
+ #endif      {NULL, 0, NULL, NULL, NULL} };

-- 
Larry Rosenman                      http://www.lerctr.org/~ler
Phone: +1 972-414-9812 (voice) Internet: ler@lerctr.org
US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749


Re: Syslog Facility Patch

From
Peter Eisentraut
Date:
Larry Rosenman writes:

> Here is a patch for allowing the syslog facility to be set.

I think you want to check for invalid values, like "LOCAL37.5".  The last
field in the ConfigNamesString structure (see below) allows you to set a
"parse hook", that is, a function that parses the input value and returns
true if it is okay.  At least this is how it is supposed to work, I've
never actually tried it. :)  Or maybe just make it an integer option?

> ***************
> *** 303,308 ****
> --- 304,312 ----
>   
>       {"unix_socket_group",         PGC_POSTMASTER,       &Unix_socket_group,
>        "", NULL},
> + #ifdef ENABLE_SYSLOG
> +     {"syslog_facility",    PGC_SIGHUP,    &Syslog_facility, "LOCAL0", NULL},     
> + #endif
>   
>       {NULL, 0, NULL, NULL, NULL}
>   };
> 
> 

-- 
Peter Eisentraut      peter_e@gmx.net       http://yi.org/peter-e/



Re: Syslog Facility Patch

From
Larry Rosenman
Date:
OK, I don't like it (it just says "syntax error"), but here is an
improved version.  I also switched to strcasecmp...


Index: doc/src/sgml/runtime.sgml
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/doc/src/sgml/runtime.sgml,v
retrieving revision 1.33
diff -c -r1.33 runtime.sgml
*** doc/src/sgml/runtime.sgml    2000/11/10 16:32:09    1.33
--- doc/src/sgml/runtime.sgml    2000/11/12 19:59:10
***************
*** 822,827 ****
--- 822,839 ----      </varlistentry>       <varlistentry>
+       <term>SYSLOG_FACILITY (<type>string</type>)</term>
+        <listitem>
+         <para>
+           If the SYSLOG option is set to 1 or greater, this option determines
+           the <application>syslog</application> facility used.  You may choose
+           from LOCAL0, LOCAL1, LOCAL2, LOCAL3, LOCAL4, LOCAL5, LOCAL6, LOCAL7.
+           the default is LOCAL0
+         </para>
+        </listitem>
+      </varlistentry>
+ 
+      <varlistentry>       <term>TRACE_NOTIFY (<type>boolean</type>)</term>       <listitem>        <para>
Index: src/backend/utils/error/elog.c
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/utils/error/elog.c,v
retrieving revision 1.65
diff -c -r1.65 elog.c
*** src/backend/utils/error/elog.c    2000/10/30 06:48:36    1.65
--- src/backend/utils/error/elog.c    2000/11/12 19:59:13
***************
*** 58,63 ****
--- 58,64 ----  * ... in theory anyway  */ int Use_syslog = 0;
+ char *Syslog_facility = "LOCAL0";  static void write_syslog(int level, const char *line); 
***************
*** 620,625 ****
--- 621,627 ----      static bool    openlog_done = false;     static unsigned long seq = 0;
+     static int    syslog_fac = LOG_LOCAL0;     int len = strlen(line);      if (Use_syslog == 0)
***************
*** 627,633 ****      if (!openlog_done)     {
!         openlog("postgres", LOG_PID | LOG_NDELAY, LOG_LOCAL0);         openlog_done = true;     } 
--- 629,651 ----      if (!openlog_done)     {
!         if (strcasecmp(Syslog_facility,"LOCAL0") == 0) 
!             syslog_fac = LOG_LOCAL0;
!         if (strcasecmp(Syslog_facility,"LOCAL1") == 0)
!             syslog_fac = LOG_LOCAL1;
!         if (strcasecmp(Syslog_facility,"LOCAL2") == 0)
!             syslog_fac = LOG_LOCAL2;
!         if (strcasecmp(Syslog_facility,"LOCAL3") == 0)
!             syslog_fac = LOG_LOCAL3;
!         if (strcasecmp(Syslog_facility,"LOCAL4") == 0)
!             syslog_fac = LOG_LOCAL4;
!         if (strcasecmp(Syslog_facility,"LOCAL5") == 0)
!             syslog_fac = LOG_LOCAL5;
!         if (strcasecmp(Syslog_facility,"LOCAL6") == 0)
!             syslog_fac = LOG_LOCAL6;
!         if (strcasecmp(Syslog_facility,"LOCAL7") == 0)
!             syslog_fac = LOG_LOCAL7;
!         openlog("postgres", LOG_PID | LOG_NDELAY, syslog_fac);         openlog_done = true;     } 
Index: src/backend/utils/misc/guc.c
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/utils/misc/guc.c,v
retrieving revision 1.16
diff -c -r1.16 guc.c
*** src/backend/utils/misc/guc.c    2000/11/09 11:25:59    1.16
--- src/backend/utils/misc/guc.c    2000/11/12 19:59:15
***************
*** 39,44 ****
--- 39,48 ---- extern int CheckPointTimeout; extern int XLOGbuffers; extern int XLOG_DEBUG;
+ #ifdef ENABLE_SYSLOG
+ extern char * Syslog_facility;
+ bool check_facility(const char *facility);
+ #endif  /*  * Debugging options
***************
*** 303,308 ****
--- 307,315 ----      {"unix_socket_group",         PGC_POSTMASTER,       &Unix_socket_group,      "", NULL},
+ #ifdef ENABLE_SYSLOG
+     {"syslog_facility",    PGC_SIGHUP,    &Syslog_facility, "LOCAL0", check_facility},     
+ #endif      {NULL, 0, NULL, NULL, NULL} };
***************
*** 807,809 ****
--- 814,832 ----         if (*cp == '-')             *cp = '_'; }
+ #ifdef ENABLE_SYSLOG
+ bool check_facility(const char *facility)
+ {
+     if (strcasecmp(facility,"LOCAL0") == 0) return true;
+     if (strcasecmp(facility,"LOCAL1") == 0) return true;
+     if (strcasecmp(facility,"LOCAL2") == 0) return true;
+     if (strcasecmp(facility,"LOCAL3") == 0) return true;
+     if (strcasecmp(facility,"LOCAL4") == 0) return true;
+     if (strcasecmp(facility,"LOCAL5") == 0) return true;
+     if (strcasecmp(facility,"LOCAL6") == 0) return true;
+     if (strcasecmp(facility,"LOCAL7") == 0) return true;
+     fprintf(stderr,"invalid syslog_facility %s\n",facility);
+     elog(FATAL,"invalid syslog_facility %s",facility);
+     return false;
+ }
+ #endif
* Peter Eisentraut <peter_e@gmx.net> [001112 12:18]:
> Larry Rosenman writes:
> 
> > Here is a patch for allowing the syslog facility to be set.
> 
> I think you want to check for invalid values, like "LOCAL37.5".  The last
> field in the ConfigNamesString structure (see below) allows you to set a
> "parse hook", that is, a function that parses the input value and returns
> true if it is okay.  At least this is how it is supposed to work, I've
> never actually tried it. :)  Or maybe just make it an integer option?
> 
> > ***************
> > *** 303,308 ****
> > --- 304,312 ----
> >   
> >       {"unix_socket_group",         PGC_POSTMASTER,       &Unix_socket_group,
> >        "", NULL},
> > + #ifdef ENABLE_SYSLOG
> > +     {"syslog_facility",    PGC_SIGHUP,    &Syslog_facility, "LOCAL0", NULL},     
> > + #endif
> >   
> >       {NULL, 0, NULL, NULL, NULL}
> >   };
> > 
> > 
> 
> -- 
> Peter Eisentraut      peter_e@gmx.net       http://yi.org/peter-e/

-- 
Larry Rosenman                      http://www.lerctr.org/~ler
Phone: +1 972-414-9812 (voice) Internet: ler@lerctr.org
US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749


Re: Syslog Facility Patch

From
Larry Rosenman
Date:
* Larry Rosenman <ler@lerctr.org> [001112 14:02]:
> OK, I don't like it (it just says "syntax error"), but here is an
> improved version.  I also switched to strcasecmp...
In looking at this some more, it appears that *SOMETHING* is not
allowing messages from set_config_option() in
/src/backend/utils/misc/guc.c out WHEN WE ARE DEALING WITH syslog type
stuff and we are reading it from the postgresql.conf file.  I'm not
sure how to deal with this..  I set syslog=2 then syslog_facility to 
some invalid value, and all I get is the syntax error message, not the 
"option rejects value" message. 

Anyone got any ideas? 

Oh, delete the elog() and fprintf() before you commit my patch (in
check_facility() in guc.c), please. 


-- 
Larry Rosenman                      http://www.lerctr.org/~ler
Phone: +1 972-414-9812 (voice) Internet: ler@lerctr.org
US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749


Re: Syslog Facility Patch

From
Larry Rosenman
Date:
* Larry Rosenman <ler@lerctr.org> [001112 15:41]:
> * Larry Rosenman <ler@lerctr.org> [001112 14:02]:
> > OK, I don't like it (it just says "syntax error"), but here is an
> > improved version.  I also switched to strcasecmp...
> In looking at this some more, it appears that *SOMETHING* is not
> allowing messages from set_config_option() in
> /src/backend/utils/misc/guc.c out WHEN WE ARE DEALING WITH syslog type
> stuff and we are reading it from the postgresql.conf file.  I'm not
> sure how to deal with this..  I set syslog=2 then syslog_facility to 
> some invalid value, and all I get is the syntax error message, not the 
> "option rejects value" message. 
> 
> Anyone got any ideas? 
> 
> Oh, delete the elog() and fprintf() before you commit my patch (in
> check_facility() in guc.c), please. 
Oh, more, if I give an invalid value on the command line, we get the
right message out.  So, it appears to be a conf file issue.  

I'm no (f)lex guru, nor do I totally understand the startup stuff. 

I feel the patch (modulo the killing of the elog() and fprintf() is
valuable.  I think I am the first to use the string parse_hook, so
this is probably the first time we've had this issue. 

Any help would be appreciated. 

LER

-- 
Larry Rosenman                      http://www.lerctr.org/~ler
Phone: +1 972-414-9812 (voice) Internet: ler@lerctr.org
US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749


Re: Syslog Facility Patch

From
Larry Rosenman
Date:
Here is a cleaned up patch, without the elog() and fprintf(), and some
minor formatting fixups. 


Index: doc/src/sgml/runtime.sgml
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/doc/src/sgml/runtime.sgml,v
retrieving revision 1.33
diff -c -r1.33 runtime.sgml
*** doc/src/sgml/runtime.sgml    2000/11/10 16:32:09    1.33
--- doc/src/sgml/runtime.sgml    2000/11/12 23:02:17
***************
*** 822,827 ****
--- 822,839 ----      </varlistentry>       <varlistentry>
+       <term>SYSLOG_FACILITY (<type>string</type>)</term>
+        <listitem>
+         <para>
+           If the SYSLOG option is set to 1 or greater, this option determines
+           the <application>syslog</application> facility used.  You may choose
+           from LOCAL0, LOCAL1, LOCAL2, LOCAL3, LOCAL4, LOCAL5, LOCAL6, LOCAL7.
+           the default is LOCAL0
+         </para>
+        </listitem>
+      </varlistentry>
+ 
+      <varlistentry>       <term>TRACE_NOTIFY (<type>boolean</type>)</term>       <listitem>        <para>
Index: src/backend/utils/error/elog.c
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/utils/error/elog.c,v
retrieving revision 1.65
diff -c -r1.65 elog.c
*** src/backend/utils/error/elog.c    2000/10/30 06:48:36    1.65
--- src/backend/utils/error/elog.c    2000/11/12 23:02:20
***************
*** 58,63 ****
--- 58,64 ----  * ... in theory anyway  */ int Use_syslog = 0;
+ char *Syslog_facility = "LOCAL0";  static void write_syslog(int level, const char *line); 
***************
*** 620,625 ****
--- 621,627 ----      static bool    openlog_done = false;     static unsigned long seq = 0;
+     static int    syslog_fac = LOG_LOCAL0;     int len = strlen(line);      if (Use_syslog == 0)
***************
*** 627,633 ****      if (!openlog_done)     {
!         openlog("postgres", LOG_PID | LOG_NDELAY, LOG_LOCAL0);         openlog_done = true;     } 
--- 629,651 ----      if (!openlog_done)     {
!         if (strcasecmp(Syslog_facility,"LOCAL0") == 0) 
!             syslog_fac = LOG_LOCAL0;
!         if (strcasecmp(Syslog_facility,"LOCAL1") == 0)
!             syslog_fac = LOG_LOCAL1;
!         if (strcasecmp(Syslog_facility,"LOCAL2") == 0)
!             syslog_fac = LOG_LOCAL2;
!         if (strcasecmp(Syslog_facility,"LOCAL3") == 0)
!             syslog_fac = LOG_LOCAL3;
!         if (strcasecmp(Syslog_facility,"LOCAL4") == 0)
!             syslog_fac = LOG_LOCAL4;
!         if (strcasecmp(Syslog_facility,"LOCAL5") == 0)
!             syslog_fac = LOG_LOCAL5;
!         if (strcasecmp(Syslog_facility,"LOCAL6") == 0)
!             syslog_fac = LOG_LOCAL6;
!         if (strcasecmp(Syslog_facility,"LOCAL7") == 0)
!             syslog_fac = LOG_LOCAL7;
!         openlog("postgres", LOG_PID | LOG_NDELAY, syslog_fac);         openlog_done = true;     } 
Index: src/backend/utils/misc/guc.c
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/utils/misc/guc.c,v
retrieving revision 1.16
diff -c -r1.16 guc.c
*** src/backend/utils/misc/guc.c    2000/11/09 11:25:59    1.16
--- src/backend/utils/misc/guc.c    2000/11/12 23:02:22
***************
*** 39,44 ****
--- 39,48 ---- extern int CheckPointTimeout; extern int XLOGbuffers; extern int XLOG_DEBUG;
+ #ifdef ENABLE_SYSLOG
+ extern char *Syslog_facility;
+        bool check_facility(const char *facility);
+ #endif  /*  * Debugging options
***************
*** 303,308 ****
--- 307,316 ----      {"unix_socket_group",         PGC_POSTMASTER,       &Unix_socket_group,      "", NULL},
+ #ifdef ENABLE_SYSLOG
+     {"syslog_facility",           PGC_SIGHUP,        &Syslog_facility, 
+     "LOCAL0", check_facility},     
+ #endif      {NULL, 0, NULL, NULL, NULL} };
***************
*** 807,809 ****
--- 815,832 ----         if (*cp == '-')             *cp = '_'; }
+ #ifdef ENABLE_SYSLOG
+ bool 
+ check_facility(const char *facility)
+ {
+     if (strcasecmp(facility,"LOCAL0") == 0) return true;
+     if (strcasecmp(facility,"LOCAL1") == 0) return true;
+     if (strcasecmp(facility,"LOCAL2") == 0) return true;
+     if (strcasecmp(facility,"LOCAL3") == 0) return true;
+     if (strcasecmp(facility,"LOCAL4") == 0) return true;
+     if (strcasecmp(facility,"LOCAL5") == 0) return true;
+     if (strcasecmp(facility,"LOCAL6") == 0) return true;
+     if (strcasecmp(facility,"LOCAL7") == 0) return true;
+     return false;
+ }
+ #endif
-- 
Larry Rosenman                      http://www.lerctr.org/~ler
Phone: +1 972-414-9812 (voice) Internet: ler@lerctr.org
US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749


Re: Syslog Facility Patch

From
Larry Rosenman
Date:
Ok, You guys are probably tired of me, BUT, here is another one, that
adds the facility to set the program name used in syslog. 
(this includes the other ones). 

One gotcha, the parser doesn't like special characters in strings.
For example, i tried to use pg-test, and if failed the parse coming
from the postgresql.conf file.  

I don't think it's a showstopper..

Comments?



Index: doc/src/sgml/runtime.sgml
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/doc/src/sgml/runtime.sgml,v
retrieving revision 1.33
diff -c -r1.33 runtime.sgml
*** doc/src/sgml/runtime.sgml    2000/11/10 16:32:09    1.33
--- doc/src/sgml/runtime.sgml    2000/11/13 01:15:34
***************
*** 822,827 ****
--- 822,851 ----      </varlistentry>       <varlistentry>
+       <term>SYSLOG_FACILITY (<type>string</type>)</term>
+        <listitem>
+         <para>
+           If the SYSLOG option is set to 1 or greater, this option determines
+           the <application>syslog</application> facility used.  You may choose
+           from LOCAL0, LOCAL1, LOCAL2, LOCAL3, LOCAL4, LOCAL5, LOCAL6, LOCAL7.
+           the default is LOCAL0
+         </para>
+        </listitem>
+      </varlistentry>
+      
+      <varlistentry>
+       <term>SYSLOG_PROGID (<type>string</type>)</term>
+        <listitem>
+         <para>
+          If the SYSLOG option is set to 1 or greater, this option determines
+          the program id used to identify <product>PostgreSQL</product> messages
+          in <application>syslog</application> log messages.  The default is
+          postgres.
+         </para>
+        </listitem>
+       </varlistentry>
+ 
+      <varlistentry>       <term>TRACE_NOTIFY (<type>boolean</type>)</term>       <listitem>        <para>
Index: src/backend/utils/error/elog.c
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/utils/error/elog.c,v
retrieving revision 1.65
diff -c -r1.65 elog.c
*** src/backend/utils/error/elog.c    2000/10/30 06:48:36    1.65
--- src/backend/utils/error/elog.c    2000/11/13 01:15:37
***************
*** 58,63 ****
--- 58,65 ----  * ... in theory anyway  */ int Use_syslog = 0;
+ char *Syslog_facility = "LOCAL0";
+ char *Syslog_progid = "postgres";  static void write_syslog(int level, const char *line); 
***************
*** 620,625 ****
--- 622,628 ----      static bool    openlog_done = false;     static unsigned long seq = 0;
+     static int    syslog_fac = LOG_LOCAL0;     int len = strlen(line);      if (Use_syslog == 0)
***************
*** 627,633 ****      if (!openlog_done)     {
!         openlog("postgres", LOG_PID | LOG_NDELAY, LOG_LOCAL0);         openlog_done = true;     } 
--- 630,652 ----      if (!openlog_done)     {
!         if (strcasecmp(Syslog_facility,"LOCAL0") == 0) 
!             syslog_fac = LOG_LOCAL0;
!         if (strcasecmp(Syslog_facility,"LOCAL1") == 0)
!             syslog_fac = LOG_LOCAL1;
!         if (strcasecmp(Syslog_facility,"LOCAL2") == 0)
!             syslog_fac = LOG_LOCAL2;
!         if (strcasecmp(Syslog_facility,"LOCAL3") == 0)
!             syslog_fac = LOG_LOCAL3;
!         if (strcasecmp(Syslog_facility,"LOCAL4") == 0)
!             syslog_fac = LOG_LOCAL4;
!         if (strcasecmp(Syslog_facility,"LOCAL5") == 0)
!             syslog_fac = LOG_LOCAL5;
!         if (strcasecmp(Syslog_facility,"LOCAL6") == 0)
!             syslog_fac = LOG_LOCAL6;
!         if (strcasecmp(Syslog_facility,"LOCAL7") == 0)
!             syslog_fac = LOG_LOCAL7;
!         openlog(Syslog_progid, LOG_PID | LOG_NDELAY, syslog_fac);         openlog_done = true;     } 
Index: src/backend/utils/misc/guc.c
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/utils/misc/guc.c,v
retrieving revision 1.16
diff -c -r1.16 guc.c
*** src/backend/utils/misc/guc.c    2000/11/09 11:25:59    1.16
--- src/backend/utils/misc/guc.c    2000/11/13 01:15:38
***************
*** 39,44 ****
--- 39,49 ---- extern int CheckPointTimeout; extern int XLOGbuffers; extern int XLOG_DEBUG;
+ #ifdef ENABLE_SYSLOG
+ extern char *Syslog_facility;
+ extern char *Syslog_progid;
+        bool check_facility(const char *facility);
+ #endif  /*  * Debugging options
***************
*** 303,308 ****
--- 308,319 ----      {"unix_socket_group",         PGC_POSTMASTER,       &Unix_socket_group,      "", NULL},
+ #ifdef ENABLE_SYSLOG
+     {"syslog_facility",           PGC_SIGHUP,        &Syslog_facility, 
+     "LOCAL0", check_facility},     
+     {"syslog_progid",             PGC_SIGHUP,        &Syslog_progid, 
+     "postgres", NULL},     
+ #endif      {NULL, 0, NULL, NULL, NULL} };
***************
*** 807,809 ****
--- 818,835 ----         if (*cp == '-')             *cp = '_'; }
+ #ifdef ENABLE_SYSLOG
+ bool 
+ check_facility(const char *facility)
+ {
+     if (strcasecmp(facility,"LOCAL0") == 0) return true;
+     if (strcasecmp(facility,"LOCAL1") == 0) return true;
+     if (strcasecmp(facility,"LOCAL2") == 0) return true;
+     if (strcasecmp(facility,"LOCAL3") == 0) return true;
+     if (strcasecmp(facility,"LOCAL4") == 0) return true;
+     if (strcasecmp(facility,"LOCAL5") == 0) return true;
+     if (strcasecmp(facility,"LOCAL6") == 0) return true;
+     if (strcasecmp(facility,"LOCAL7") == 0) return true;
+     return false;
+ }
+ #endif
-- 
Larry Rosenman                      http://www.lerctr.org/~ler
Phone: +1 972-414-9812 (voice) Internet: ler@lerctr.org
US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749


Re: Syslog Facility Patch

From
Larry Rosenman
Date:
* Larry Rosenman <ler@lerctr.org> [001112 19:20]:
> Ok, You guys are probably tired of me, BUT, here is another one, that
> adds the facility to set the program name used in syslog. 
> (this includes the other ones). 
> 
> One gotcha, the parser doesn't like special characters in strings.
> For example, i tried to use pg-test, and if failed the parse coming
> from the postgresql.conf file.  
> 
> I don't think it's a showstopper..
> 
> Comments?
Any chance of this getting committed? 

LER

-- 
Larry Rosenman                      http://www.lerctr.org/~ler
Phone: +1 972-414-9812 (voice) Internet: ler@lerctr.org
US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749


Re: Syslog Facility Patch

From
Bruce Momjian
Date:
Applied.


> Ok, You guys are probably tired of me, BUT, here is another one, that
> adds the facility to set the program name used in syslog. 
> (this includes the other ones). 
> 
> One gotcha, the parser doesn't like special characters in strings.
> For example, i tried to use pg-test, and if failed the parse coming
> from the postgresql.conf file.  
> 
> I don't think it's a showstopper..
> 
> Comments?
> 
> 
> 
> Index: doc/src/sgml/runtime.sgml
> ===================================================================
> RCS file: /home/projects/pgsql/cvsroot/pgsql/doc/src/sgml/runtime.sgml,v
> retrieving revision 1.33
> diff -c -r1.33 runtime.sgml
> *** doc/src/sgml/runtime.sgml    2000/11/10 16:32:09    1.33
> --- doc/src/sgml/runtime.sgml    2000/11/13 01:15:34
> ***************
> *** 822,827 ****
> --- 822,851 ----
>        </varlistentry>
>   
>        <varlistentry>
> +       <term>SYSLOG_FACILITY (<type>string</type>)</term>
> +        <listitem>
> +         <para>
> +           If the SYSLOG option is set to 1 or greater, this option determines
> +           the <application>syslog</application> facility used.  You may choose
> +           from LOCAL0, LOCAL1, LOCAL2, LOCAL3, LOCAL4, LOCAL5, LOCAL6, LOCAL7.
> +           the default is LOCAL0
> +         </para>
> +        </listitem>
> +      </varlistentry>
> +      
> +      <varlistentry>
> +       <term>SYSLOG_PROGID (<type>string</type>)</term>
> +        <listitem>
> +         <para>
> +          If the SYSLOG option is set to 1 or greater, this option determines
> +          the program id used to identify <product>PostgreSQL</product> messages
> +          in <application>syslog</application> log messages.  The default is
> +          postgres.
> +         </para>
> +        </listitem>
> +       </varlistentry>
> + 
> +      <varlistentry>
>         <term>TRACE_NOTIFY (<type>boolean</type>)</term>
>         <listitem>
>          <para>
> Index: src/backend/utils/error/elog.c
> ===================================================================
> RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/utils/error/elog.c,v
> retrieving revision 1.65
> diff -c -r1.65 elog.c
> *** src/backend/utils/error/elog.c    2000/10/30 06:48:36    1.65
> --- src/backend/utils/error/elog.c    2000/11/13 01:15:37
> ***************
> *** 58,63 ****
> --- 58,65 ----
>    * ... in theory anyway
>    */
>   int Use_syslog = 0;
> + char *Syslog_facility = "LOCAL0";
> + char *Syslog_progid = "postgres";
>   
>   static void write_syslog(int level, const char *line);
>   
> ***************
> *** 620,625 ****
> --- 622,628 ----
>   
>       static bool    openlog_done = false;
>       static unsigned long seq = 0;
> +     static int    syslog_fac = LOG_LOCAL0;
>       int len = strlen(line);
>   
>       if (Use_syslog == 0)
> ***************
> *** 627,633 ****
>   
>       if (!openlog_done)
>       {
> !         openlog("postgres", LOG_PID | LOG_NDELAY, LOG_LOCAL0);
>           openlog_done = true;
>       }
>   
> --- 630,652 ----
>   
>       if (!openlog_done)
>       {
> !         if (strcasecmp(Syslog_facility,"LOCAL0") == 0) 
> !             syslog_fac = LOG_LOCAL0;
> !         if (strcasecmp(Syslog_facility,"LOCAL1") == 0)
> !             syslog_fac = LOG_LOCAL1;
> !         if (strcasecmp(Syslog_facility,"LOCAL2") == 0)
> !             syslog_fac = LOG_LOCAL2;
> !         if (strcasecmp(Syslog_facility,"LOCAL3") == 0)
> !             syslog_fac = LOG_LOCAL3;
> !         if (strcasecmp(Syslog_facility,"LOCAL4") == 0)
> !             syslog_fac = LOG_LOCAL4;
> !         if (strcasecmp(Syslog_facility,"LOCAL5") == 0)
> !             syslog_fac = LOG_LOCAL5;
> !         if (strcasecmp(Syslog_facility,"LOCAL6") == 0)
> !             syslog_fac = LOG_LOCAL6;
> !         if (strcasecmp(Syslog_facility,"LOCAL7") == 0)
> !             syslog_fac = LOG_LOCAL7;
> !         openlog(Syslog_progid, LOG_PID | LOG_NDELAY, syslog_fac);
>           openlog_done = true;
>       }
>   
> Index: src/backend/utils/misc/guc.c
> ===================================================================
> RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/utils/misc/guc.c,v
> retrieving revision 1.16
> diff -c -r1.16 guc.c
> *** src/backend/utils/misc/guc.c    2000/11/09 11:25:59    1.16
> --- src/backend/utils/misc/guc.c    2000/11/13 01:15:38
> ***************
> *** 39,44 ****
> --- 39,49 ----
>   extern int CheckPointTimeout;
>   extern int XLOGbuffers;
>   extern int XLOG_DEBUG;
> + #ifdef ENABLE_SYSLOG
> + extern char *Syslog_facility;
> + extern char *Syslog_progid;
> +        bool check_facility(const char *facility);
> + #endif
>   
>   /*
>    * Debugging options
> ***************
> *** 303,308 ****
> --- 308,319 ----
>   
>       {"unix_socket_group",         PGC_POSTMASTER,       &Unix_socket_group,
>        "", NULL},
> + #ifdef ENABLE_SYSLOG
> +     {"syslog_facility",           PGC_SIGHUP,        &Syslog_facility, 
> +     "LOCAL0", check_facility},     
> +     {"syslog_progid",             PGC_SIGHUP,        &Syslog_progid, 
> +     "postgres", NULL},     
> + #endif
>   
>       {NULL, 0, NULL, NULL, NULL}
>   };
> ***************
> *** 807,809 ****
> --- 818,835 ----
>           if (*cp == '-')
>               *cp = '_';
>   }
> + #ifdef ENABLE_SYSLOG
> + bool 
> + check_facility(const char *facility)
> + {
> +     if (strcasecmp(facility,"LOCAL0") == 0) return true;
> +     if (strcasecmp(facility,"LOCAL1") == 0) return true;
> +     if (strcasecmp(facility,"LOCAL2") == 0) return true;
> +     if (strcasecmp(facility,"LOCAL3") == 0) return true;
> +     if (strcasecmp(facility,"LOCAL4") == 0) return true;
> +     if (strcasecmp(facility,"LOCAL5") == 0) return true;
> +     if (strcasecmp(facility,"LOCAL6") == 0) return true;
> +     if (strcasecmp(facility,"LOCAL7") == 0) return true;
> +     return false;
> + }
> + #endif
> -- 
> Larry Rosenman                      http://www.lerctr.org/~ler
> Phone: +1 972-414-9812 (voice) Internet: ler@lerctr.org
> US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749
> 


--  Bruce Momjian                        |  http://candle.pha.pa.us pgman@candle.pha.pa.us               |  (610)
853-3000+  If your life is a hard drive,     |  830 Blythe Avenue +  Christ can be your backup.        |  Drexel Hill,
Pennsylvania19026
 


Re: Syslog Facility Patch

From
Larry Rosenman
Date:
* Bruce Momjian <pgman@candle.pha.pa.us> [001113 15:36]:
> Applied.
> 
Thanks.  FWIW, I had to pull the CVS copy of guc.c (my cvs update got 
two copies of my updates to the table). 

Comments on my postgresql.conf issues from the rest of the -hackers
corp? 

Thanks!

-- 
Larry Rosenman                      http://www.lerctr.org/~ler
Phone: +1 972-414-9812 (voice) Internet: ler@lerctr.org
US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749


Re: Syslog Facility Patch

From
Peter Eisentraut
Date:
Bruce Momjian writes:

> Applied.

Uh, shouldn't the problems Larry pointed out be fixed first?

> 
> 
> > Ok, You guys are probably tired of me, BUT, here is another one, that
> > adds the facility to set the program name used in syslog. 
> > (this includes the other ones). 
> > 
> > One gotcha, the parser doesn't like special characters in strings.
> > For example, i tried to use pg-test, and if failed the parse coming
> > from the postgresql.conf file.  
> > 
> > I don't think it's a showstopper..
> > 
> > Comments?
> > 
> > 
> > 
> > Index: doc/src/sgml/runtime.sgml
> > ===================================================================
> > RCS file: /home/projects/pgsql/cvsroot/pgsql/doc/src/sgml/runtime.sgml,v
> > retrieving revision 1.33
> > diff -c -r1.33 runtime.sgml
> > *** doc/src/sgml/runtime.sgml    2000/11/10 16:32:09    1.33
> > --- doc/src/sgml/runtime.sgml    2000/11/13 01:15:34
> > ***************
> > *** 822,827 ****
> > --- 822,851 ----
> >        </varlistentry>
> >   
> >        <varlistentry>
> > +       <term>SYSLOG_FACILITY (<type>string</type>)</term>
> > +        <listitem>
> > +         <para>
> > +           If the SYSLOG option is set to 1 or greater, this option determines
> > +           the <application>syslog</application> facility used.  You may choose
> > +           from LOCAL0, LOCAL1, LOCAL2, LOCAL3, LOCAL4, LOCAL5, LOCAL6, LOCAL7.
> > +           the default is LOCAL0
> > +         </para>
> > +        </listitem>
> > +      </varlistentry>
> > +      
> > +      <varlistentry>
> > +       <term>SYSLOG_PROGID (<type>string</type>)</term>
> > +        <listitem>
> > +         <para>
> > +          If the SYSLOG option is set to 1 or greater, this option determines
> > +          the program id used to identify <product>PostgreSQL</product> messages
> > +          in <application>syslog</application> log messages.  The default is
> > +          postgres.
> > +         </para>
> > +        </listitem>
> > +       </varlistentry>
> > + 
> > +      <varlistentry>
> >         <term>TRACE_NOTIFY (<type>boolean</type>)</term>
> >         <listitem>
> >          <para>
> > Index: src/backend/utils/error/elog.c
> > ===================================================================
> > RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/utils/error/elog.c,v
> > retrieving revision 1.65
> > diff -c -r1.65 elog.c
> > *** src/backend/utils/error/elog.c    2000/10/30 06:48:36    1.65
> > --- src/backend/utils/error/elog.c    2000/11/13 01:15:37
> > ***************
> > *** 58,63 ****
> > --- 58,65 ----
> >    * ... in theory anyway
> >    */
> >   int Use_syslog = 0;
> > + char *Syslog_facility = "LOCAL0";
> > + char *Syslog_progid = "postgres";
> >   
> >   static void write_syslog(int level, const char *line);
> >   
> > ***************
> > *** 620,625 ****
> > --- 622,628 ----
> >   
> >       static bool    openlog_done = false;
> >       static unsigned long seq = 0;
> > +     static int    syslog_fac = LOG_LOCAL0;
> >       int len = strlen(line);
> >   
> >       if (Use_syslog == 0)
> > ***************
> > *** 627,633 ****
> >   
> >       if (!openlog_done)
> >       {
> > !         openlog("postgres", LOG_PID | LOG_NDELAY, LOG_LOCAL0);
> >           openlog_done = true;
> >       }
> >   
> > --- 630,652 ----
> >   
> >       if (!openlog_done)
> >       {
> > !         if (strcasecmp(Syslog_facility,"LOCAL0") == 0) 
> > !             syslog_fac = LOG_LOCAL0;
> > !         if (strcasecmp(Syslog_facility,"LOCAL1") == 0)
> > !             syslog_fac = LOG_LOCAL1;
> > !         if (strcasecmp(Syslog_facility,"LOCAL2") == 0)
> > !             syslog_fac = LOG_LOCAL2;
> > !         if (strcasecmp(Syslog_facility,"LOCAL3") == 0)
> > !             syslog_fac = LOG_LOCAL3;
> > !         if (strcasecmp(Syslog_facility,"LOCAL4") == 0)
> > !             syslog_fac = LOG_LOCAL4;
> > !         if (strcasecmp(Syslog_facility,"LOCAL5") == 0)
> > !             syslog_fac = LOG_LOCAL5;
> > !         if (strcasecmp(Syslog_facility,"LOCAL6") == 0)
> > !             syslog_fac = LOG_LOCAL6;
> > !         if (strcasecmp(Syslog_facility,"LOCAL7") == 0)
> > !             syslog_fac = LOG_LOCAL7;
> > !         openlog(Syslog_progid, LOG_PID | LOG_NDELAY, syslog_fac);
> >           openlog_done = true;
> >       }
> >   
> > Index: src/backend/utils/misc/guc.c
> > ===================================================================
> > RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/utils/misc/guc.c,v
> > retrieving revision 1.16
> > diff -c -r1.16 guc.c
> > *** src/backend/utils/misc/guc.c    2000/11/09 11:25:59    1.16
> > --- src/backend/utils/misc/guc.c    2000/11/13 01:15:38
> > ***************
> > *** 39,44 ****
> > --- 39,49 ----
> >   extern int CheckPointTimeout;
> >   extern int XLOGbuffers;
> >   extern int XLOG_DEBUG;
> > + #ifdef ENABLE_SYSLOG
> > + extern char *Syslog_facility;
> > + extern char *Syslog_progid;
> > +        bool check_facility(const char *facility);
> > + #endif
> >   
> >   /*
> >    * Debugging options
> > ***************
> > *** 303,308 ****
> > --- 308,319 ----
> >   
> >       {"unix_socket_group",         PGC_POSTMASTER,       &Unix_socket_group,
> >        "", NULL},
> > + #ifdef ENABLE_SYSLOG
> > +     {"syslog_facility",           PGC_SIGHUP,        &Syslog_facility, 
> > +     "LOCAL0", check_facility},     
> > +     {"syslog_progid",             PGC_SIGHUP,        &Syslog_progid, 
> > +     "postgres", NULL},     
> > + #endif
> >   
> >       {NULL, 0, NULL, NULL, NULL}
> >   };
> > ***************
> > *** 807,809 ****
> > --- 818,835 ----
> >           if (*cp == '-')
> >               *cp = '_';
> >   }
> > + #ifdef ENABLE_SYSLOG
> > + bool 
> > + check_facility(const char *facility)
> > + {
> > +     if (strcasecmp(facility,"LOCAL0") == 0) return true;
> > +     if (strcasecmp(facility,"LOCAL1") == 0) return true;
> > +     if (strcasecmp(facility,"LOCAL2") == 0) return true;
> > +     if (strcasecmp(facility,"LOCAL3") == 0) return true;
> > +     if (strcasecmp(facility,"LOCAL4") == 0) return true;
> > +     if (strcasecmp(facility,"LOCAL5") == 0) return true;
> > +     if (strcasecmp(facility,"LOCAL6") == 0) return true;
> > +     if (strcasecmp(facility,"LOCAL7") == 0) return true;
> > +     return false;
> > + }
> > + #endif
> > -- 
> > Larry Rosenman                      http://www.lerctr.org/~ler
> > Phone: +1 972-414-9812 (voice) Internet: ler@lerctr.org
> > US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749
> > 
> 
> 
> 

-- 
Peter Eisentraut      peter_e@gmx.net       http://yi.org/peter-e/



Re: Syslog Facility Patch

From
Peter Eisentraut
Date:
Larry Rosenman writes:

> Ok, You guys are probably tired of me, BUT, here is another one, that
> adds the facility to set the program name used in syslog. 
> (this includes the other ones). 

Why would one want to do that?  ISTM that that would just be a means to
play games with the sysadmin.

-- 
Peter Eisentraut      peter_e@gmx.net       http://yi.org/peter-e/



Re: Syslog Facility Patch

From
Bruce Momjian
Date:
> * Peter Eisentraut <peter_e@gmx.net> [001113 17:41]:
> > Bruce Momjian writes:
> > 
> > > Applied.
> > 
> > Uh, shouldn't the problems Larry pointed out be fixed first?
> I don't think the problems are BECAUSE of my code.  The new stuff
> works, just putting the new options in postgresql.conf with a bad
> value causes weird messages.  I think the new code should stay, and
> now we have stuff to figure out why guc-file.l or guc.c has a problem
> getting the message out. 
> 
> I requested the commit. 

Man, I knew I saw that request somewhere.  :-)

--  Bruce Momjian                        |  http://candle.pha.pa.us pgman@candle.pha.pa.us               |  (610)
853-3000+  If your life is a hard drive,     |  830 Blythe Avenue +  Christ can be your backup.        |  Drexel Hill,
Pennsylvania19026
 


Re: Syslog Facility Patch

From
Larry Rosenman
Date:
* Peter Eisentraut <peter_e@gmx.net> [001113 17:41]:
> Bruce Momjian writes:
> 
> > Applied.
> 
> Uh, shouldn't the problems Larry pointed out be fixed first?
I don't think the problems are BECAUSE of my code.  The new stuff
works, just putting the new options in postgresql.conf with a bad
value causes weird messages.  I think the new code should stay, and
now we have stuff to figure out why guc-file.l or guc.c has a problem
getting the message out. 

I requested the commit. 

I think the issue is in guc-file.l or somewhere else in the startup of
a new backend to get the right error out. 

I'm not familiar enough with the backend startup to debug these
wierdnesses(sp?). 


LER

-- 
Larry Rosenman                      http://www.lerctr.org/~ler
Phone: +1 972-414-9812 (voice) Internet: ler@lerctr.org
US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749


Re: Syslog Facility Patch

From
Larry Rosenman
Date:
* Peter Eisentraut <peter_e@gmx.net> [001113 17:43]:
> Larry Rosenman writes:
> 
> > Ok, You guys are probably tired of me, BUT, here is another one, that
> > adds the facility to set the program name used in syslog. 
> > (this includes the other ones). 
> 
> Why would one want to do that?  ISTM that that would just be a means to
> play games with the sysadmin.
test vs. production postgresDB's, virtual users (ala uunet), multiple
different pg's listening on different ports. 
> 
> -- 
> Peter Eisentraut      peter_e@gmx.net       http://yi.org/peter-e/

-- 
Larry Rosenman                      http://www.lerctr.org/~ler
Phone: +1 972-414-9812 (voice) Internet: ler@lerctr.org
US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749


Re: Syslog Facility Patch

From
Bruce Momjian
Date:
There were problems?  I saw someone asking why it hadn't been applied
yet.  What do people want?  I can back it out.


> Bruce Momjian writes:
> 
> > Applied.
> 
> Uh, shouldn't the problems Larry pointed out be fixed first?
> 
> > 
> > 
> > > Ok, You guys are probably tired of me, BUT, here is another one, that
> > > adds the facility to set the program name used in syslog. 
> > > (this includes the other ones). 
> > > 
> > > One gotcha, the parser doesn't like special characters in strings.
> > > For example, i tried to use pg-test, and if failed the parse coming
> > > from the postgresql.conf file.  
> > > 
> > > I don't think it's a showstopper..
> > > 
> > > Comments?
> > > 
> > > 
> > > 
> > > Index: doc/src/sgml/runtime.sgml
> > > ===================================================================
> > > RCS file: /home/projects/pgsql/cvsroot/pgsql/doc/src/sgml/runtime.sgml,v
> > > retrieving revision 1.33
> > > diff -c -r1.33 runtime.sgml
> > > *** doc/src/sgml/runtime.sgml    2000/11/10 16:32:09    1.33
> > > --- doc/src/sgml/runtime.sgml    2000/11/13 01:15:34
> > > ***************
> > > *** 822,827 ****
> > > --- 822,851 ----
> > >        </varlistentry>
> > >   
> > >        <varlistentry>
> > > +       <term>SYSLOG_FACILITY (<type>string</type>)</term>
> > > +        <listitem>
> > > +         <para>
> > > +           If the SYSLOG option is set to 1 or greater, this option determines
> > > +           the <application>syslog</application> facility used.  You may choose
> > > +           from LOCAL0, LOCAL1, LOCAL2, LOCAL3, LOCAL4, LOCAL5, LOCAL6, LOCAL7.
> > > +           the default is LOCAL0
> > > +         </para>
> > > +        </listitem>
> > > +      </varlistentry>
> > > +      
> > > +      <varlistentry>
> > > +       <term>SYSLOG_PROGID (<type>string</type>)</term>
> > > +        <listitem>
> > > +         <para>
> > > +          If the SYSLOG option is set to 1 or greater, this option determines
> > > +          the program id used to identify <product>PostgreSQL</product> messages
> > > +          in <application>syslog</application> log messages.  The default is
> > > +          postgres.
> > > +         </para>
> > > +        </listitem>
> > > +       </varlistentry>
> > > + 
> > > +      <varlistentry>
> > >         <term>TRACE_NOTIFY (<type>boolean</type>)</term>
> > >         <listitem>
> > >          <para>
> > > Index: src/backend/utils/error/elog.c
> > > ===================================================================
> > > RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/utils/error/elog.c,v
> > > retrieving revision 1.65
> > > diff -c -r1.65 elog.c
> > > *** src/backend/utils/error/elog.c    2000/10/30 06:48:36    1.65
> > > --- src/backend/utils/error/elog.c    2000/11/13 01:15:37
> > > ***************
> > > *** 58,63 ****
> > > --- 58,65 ----
> > >    * ... in theory anyway
> > >    */
> > >   int Use_syslog = 0;
> > > + char *Syslog_facility = "LOCAL0";
> > > + char *Syslog_progid = "postgres";
> > >   
> > >   static void write_syslog(int level, const char *line);
> > >   
> > > ***************
> > > *** 620,625 ****
> > > --- 622,628 ----
> > >   
> > >       static bool    openlog_done = false;
> > >       static unsigned long seq = 0;
> > > +     static int    syslog_fac = LOG_LOCAL0;
> > >       int len = strlen(line);
> > >   
> > >       if (Use_syslog == 0)
> > > ***************
> > > *** 627,633 ****
> > >   
> > >       if (!openlog_done)
> > >       {
> > > !         openlog("postgres", LOG_PID | LOG_NDELAY, LOG_LOCAL0);
> > >           openlog_done = true;
> > >       }
> > >   
> > > --- 630,652 ----
> > >   
> > >       if (!openlog_done)
> > >       {
> > > !         if (strcasecmp(Syslog_facility,"LOCAL0") == 0) 
> > > !             syslog_fac = LOG_LOCAL0;
> > > !         if (strcasecmp(Syslog_facility,"LOCAL1") == 0)
> > > !             syslog_fac = LOG_LOCAL1;
> > > !         if (strcasecmp(Syslog_facility,"LOCAL2") == 0)
> > > !             syslog_fac = LOG_LOCAL2;
> > > !         if (strcasecmp(Syslog_facility,"LOCAL3") == 0)
> > > !             syslog_fac = LOG_LOCAL3;
> > > !         if (strcasecmp(Syslog_facility,"LOCAL4") == 0)
> > > !             syslog_fac = LOG_LOCAL4;
> > > !         if (strcasecmp(Syslog_facility,"LOCAL5") == 0)
> > > !             syslog_fac = LOG_LOCAL5;
> > > !         if (strcasecmp(Syslog_facility,"LOCAL6") == 0)
> > > !             syslog_fac = LOG_LOCAL6;
> > > !         if (strcasecmp(Syslog_facility,"LOCAL7") == 0)
> > > !             syslog_fac = LOG_LOCAL7;
> > > !         openlog(Syslog_progid, LOG_PID | LOG_NDELAY, syslog_fac);
> > >           openlog_done = true;
> > >       }
> > >   
> > > Index: src/backend/utils/misc/guc.c
> > > ===================================================================
> > > RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/utils/misc/guc.c,v
> > > retrieving revision 1.16
> > > diff -c -r1.16 guc.c
> > > *** src/backend/utils/misc/guc.c    2000/11/09 11:25:59    1.16
> > > --- src/backend/utils/misc/guc.c    2000/11/13 01:15:38
> > > ***************
> > > *** 39,44 ****
> > > --- 39,49 ----
> > >   extern int CheckPointTimeout;
> > >   extern int XLOGbuffers;
> > >   extern int XLOG_DEBUG;
> > > + #ifdef ENABLE_SYSLOG
> > > + extern char *Syslog_facility;
> > > + extern char *Syslog_progid;
> > > +        bool check_facility(const char *facility);
> > > + #endif
> > >   
> > >   /*
> > >    * Debugging options
> > > ***************
> > > *** 303,308 ****
> > > --- 308,319 ----
> > >   
> > >       {"unix_socket_group",         PGC_POSTMASTER,       &Unix_socket_group,
> > >        "", NULL},
> > > + #ifdef ENABLE_SYSLOG
> > > +     {"syslog_facility",           PGC_SIGHUP,        &Syslog_facility, 
> > > +     "LOCAL0", check_facility},     
> > > +     {"syslog_progid",             PGC_SIGHUP,        &Syslog_progid, 
> > > +     "postgres", NULL},     
> > > + #endif
> > >   
> > >       {NULL, 0, NULL, NULL, NULL}
> > >   };
> > > ***************
> > > *** 807,809 ****
> > > --- 818,835 ----
> > >           if (*cp == '-')
> > >               *cp = '_';
> > >   }
> > > + #ifdef ENABLE_SYSLOG
> > > + bool 
> > > + check_facility(const char *facility)
> > > + {
> > > +     if (strcasecmp(facility,"LOCAL0") == 0) return true;
> > > +     if (strcasecmp(facility,"LOCAL1") == 0) return true;
> > > +     if (strcasecmp(facility,"LOCAL2") == 0) return true;
> > > +     if (strcasecmp(facility,"LOCAL3") == 0) return true;
> > > +     if (strcasecmp(facility,"LOCAL4") == 0) return true;
> > > +     if (strcasecmp(facility,"LOCAL5") == 0) return true;
> > > +     if (strcasecmp(facility,"LOCAL6") == 0) return true;
> > > +     if (strcasecmp(facility,"LOCAL7") == 0) return true;
> > > +     return false;
> > > + }
> > > + #endif
> > > -- 
> > > Larry Rosenman                      http://www.lerctr.org/~ler
> > > Phone: +1 972-414-9812 (voice) Internet: ler@lerctr.org
> > > US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749
> > > 
> > 
> > 
> > 
> 
> -- 
> Peter Eisentraut      peter_e@gmx.net       http://yi.org/peter-e/
> 
> 


--  Bruce Momjian                        |  http://candle.pha.pa.us pgman@candle.pha.pa.us               |  (610)
853-3000+  If your life is a hard drive,     |  830 Blythe Avenue +  Christ can be your backup.        |  Drexel Hill,
Pennsylvania19026
 


Re: Syslog Facility Patch

From
Bruce Momjian
Date:
> Larry Rosenman writes:
> 
> > Ok, You guys are probably tired of me, BUT, here is another one, that
> > adds the facility to set the program name used in syslog. 
> > (this includes the other ones). 
> 
> Why would one want to do that?  ISTM that that would just be a means to
> play games with the sysadmin.

Don't rule out the attractiveness of that.  :-)

--  Bruce Momjian                        |  http://candle.pha.pa.us pgman@candle.pha.pa.us               |  (610)
853-3000+  If your life is a hard drive,     |  830 Blythe Avenue +  Christ can be your backup.        |  Drexel Hill,
Pennsylvania19026
 


Re: Syslog Facility Patch

From
Peter Eisentraut
Date:
Larry Rosenman writes:

> * Peter Eisentraut <peter_e@gmx.net> [001113 17:43]:
> > Larry Rosenman writes:
> > 
> > > Ok, You guys are probably tired of me, BUT, here is another one, that
> > > adds the facility to set the program name used in syslog. 
> > > (this includes the other ones). 
> > 
> > Why would one want to do that?  ISTM that that would just be a means to
> > play games with the sysadmin.
> test vs. production postgresDB's, virtual users (ala uunet), multiple
> different pg's listening on different ports. 

Okay, but you can't make these options PGC_SIGHUP unless you make sure to
close and re-open the syslog channel whenever these options
change.  Probably ought to be PGC_POSTMASTER.

-- 
Peter Eisentraut      peter_e@gmx.net       http://yi.org/peter-e/



Re: Syslog Facility Patch

From
Larry Rosenman
Date:
* Peter Eisentraut <peter_e@gmx.net> [001113 23:52]:
> Okay, but you can't make these options PGC_SIGHUP unless you make sure to
> close and re-open the syslog channel whenever these options
> change.  Probably ought to be PGC_POSTMASTER.
Is there a mechanism to "hear" the SIGHUP? Although, it probably
doesn't matter.  I'll do a patch.  I was just following the syslog
lead. 

-- 
Larry Rosenman                      http://www.lerctr.org/~ler
Phone: +1 972-414-9812 (voice) Internet: ler@lerctr.org
US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749


Re: Syslog Facility Patch

From
Larry Rosenman
Date:
* Peter Eisentraut <peter_e@gmx.net> [001113 23:52]:
> Okay, but you can't make these options PGC_SIGHUP unless you make sure to
> close and re-open the syslog channel whenever these options
> change.  Probably ought to be PGC_POSTMASTER.
Here is a patch to change to PGC_POSTMASTER...


Index: guc.c
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/utils/misc/guc.c,v
retrieving revision 1.19
diff -c -r1.19 guc.c
*** guc.c    2000/11/14 01:15:02    1.19
--- guc.c    2000/11/14 13:11:33
***************
*** 309,317 ****     {"unix_socket_group",         PGC_POSTMASTER,       &Unix_socket_group,      "", NULL}, #ifdef
ENABLE_SYSLOG
!     {"syslog_facility",           PGC_SIGHUP,        &Syslog_facility,      "LOCAL0", check_facility},     
!     {"syslog_progid",             PGC_SIGHUP,        &Syslog_progid,      "postgres", NULL},      #endif 
--- 309,317 ----     {"unix_socket_group",         PGC_POSTMASTER,       &Unix_socket_group,      "", NULL}, #ifdef
ENABLE_SYSLOG
!     {"syslog_facility",           PGC_POSTMASTER,        &Syslog_facility,      "LOCAL0", check_facility},     
!     {"syslog_progid",             PGC_POSTMASTER,        &Syslog_progid,      "postgres", NULL},      #endif 
-- 
Larry Rosenman                      http://www.lerctr.org/~ler
Phone: +1 972-414-9812 (voice) Internet: ler@lerctr.org
US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749


Re: Syslog Facility Patch

From
Peter Eisentraut
Date:
Larry Rosenman writes:

> Is there a mechanism to "hear" the SIGHUP?

There currently isn't a way to have side effects when an option is
set.  Might be something for the future, but it doesn't seem so wildly
important.

-- 
Peter Eisentraut      peter_e@gmx.net       http://yi.org/peter-e/



Re: Syslog Facility Patch

From
Peter Eisentraut
Date:
Larry Rosenman writes:

> In looking at this some more, it appears that *SOMETHING* is not
> allowing messages from set_config_option() in
> /src/backend/utils/misc/guc.c out WHEN WE ARE DEALING WITH syslog type
> stuff and we are reading it from the postgresql.conf file.  I'm not
> sure how to deal with this..  I set syslog=2 then syslog_facility to 
> some invalid value, and all I get is the syntax error message, not the 
> "option rejects value" message. 

I can't reproduce that.  I set 'syslog_facility = local97' and got the
right error message.

-- 
Peter Eisentraut      peter_e@gmx.net       http://yi.org/peter-e/



Re: Syslog Facility Patch

From
Tom Lane
Date:
Peter Eisentraut <peter_e@gmx.net> writes:
> Larry Rosenman writes:
>> In looking at this some more, it appears that *SOMETHING* is not
>> allowing messages from set_config_option() in
>> /src/backend/utils/misc/guc.c out WHEN WE ARE DEALING WITH syslog type
>> stuff and we are reading it from the postgresql.conf file.  I'm not
>> sure how to deal with this..  I set syslog=2 then syslog_facility to 
>> some invalid value, and all I get is the syntax error message, not the 
>> "option rejects value" message. 

> I can't reproduce that.  I set 'syslog_facility = local97' and got the
> right error message.

I'm surprised you get any error message at all (as seen by a client,
that is, not as seen in the postmaster log).  AFAICT, backend libpq
is not fired up until well down inside PostmasterMain --- look at the
call to pq_init.  Until that's done, it's impossible to send error
messages to the client.  I've been meaning to look at whether the
pq_init call couldn't be moved up to before (instead of after) option
and switch processing ...
        regards, tom lane


Re: Syslog Facility Patch

From
Larry Rosenman
Date:
* Peter Eisentraut <peter_e@gmx.net> [001114 12:45]:
> Larry Rosenman writes:
> 
> > In looking at this some more, it appears that *SOMETHING* is not
> > allowing messages from set_config_option() in
> > /src/backend/utils/misc/guc.c out WHEN WE ARE DEALING WITH syslog type
> > stuff and we are reading it from the postgresql.conf file.  I'm not
> > sure how to deal with this..  I set syslog=2 then syslog_facility to 
> > some invalid value, and all I get is the syntax error message, not the 
> > "option rejects value" message. 
> 
> I can't reproduce that.  I set 'syslog_facility = local97' and got the
> right error message.
try setting it in postgresql.conf....


> 
> -- 
> Peter Eisentraut      peter_e@gmx.net       http://yi.org/peter-e/

-- 
Larry Rosenman                      http://www.lerctr.org/~ler
Phone: +1 972-414-9812 (voice) Internet: ler@lerctr.org
US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749


Re: Syslog Facility Patch

From
Tom Lane
Date:
I said:
> I'm surprised you get any error message at all (as seen by a client,
> that is, not as seen in the postmaster log).  AFAICT, backend libpq
> is not fired up until well down inside PostmasterMain --- look at the
> call to pq_init.

s/PostmasterMain/PostgresMain/ ...
        regards, tom lane


Re: Syslog Facility Patch

From
Peter Eisentraut
Date:
Larry Rosenman writes:

> > I can't reproduce that.  I set 'syslog_facility = local97' and got the
> > right error message.
> try setting it in postgresql.conf....

That's what I did.

-- 
Peter Eisentraut      peter_e@gmx.net       http://yi.org/peter-e/



Re: Syslog Facility Patch

From
Peter Eisentraut
Date:
Tom Lane writes:

> > I can't reproduce that.  I set 'syslog_facility = local97' and got the
> > right error message.
> 
> I'm surprised you get any error message at all (as seen by a client,
> that is, not as seen in the postmaster log).

I was talking about the postmaster log.  No clients involved.

-- 
Peter Eisentraut      peter_e@gmx.net       http://yi.org/peter-e/



Re: Syslog Facility Patch

From
Peter Eisentraut
Date:
Larry Rosenman writes:

> Here is a patch to change to PGC_POSTMASTER...

Thanks.  I polished things a bit and it works well for me now.

-- 
Peter Eisentraut      peter_e@gmx.net       http://yi.org/peter-e/



Re: Syslog Facility Patch

From
Larry Rosenman
Date:
* Peter Eisentraut <peter_e@gmx.net> [001114 13:18]:
> Larry Rosenman writes:
> 
> > > I can't reproduce that.  I set 'syslog_facility = local97' and got the
> > > right error message.
> > try setting it in postgresql.conf....
> 
> That's what I did.
Hmm.  Here is what I get: 
$ ../bin/pg_ctl -D ~/pg-test/data -o "-p 7777 -i" start
postmaster successfully started up.
$ FATAL 1:  postgresql.conf:17: syntax error

$
> 
> -- 
> Peter Eisentraut      peter_e@gmx.net       http://yi.org/peter-e/

-- 
Larry Rosenman                      http://www.lerctr.org/~ler
Phone: +1 972-414-9812 (voice) Internet: ler@lerctr.org
US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749


Re: Syslog Facility Patch

From
Peter Eisentraut
Date:
Larry Rosenman writes:

> * Peter Eisentraut <peter_e@gmx.net> [001114 13:18]:
> > Larry Rosenman writes:
> > 
> > > > I can't reproduce that.  I set 'syslog_facility = local97' and got the
> > > > right error message.
> > > try setting it in postgresql.conf....
> > 
> > That's what I did.
> Hmm.  Here is what I get: 
> $ ../bin/pg_ctl -D ~/pg-test/data -o "-p 7777 -i" start
> postmaster successfully started up.
> $ FATAL 1:  postgresql.conf:17: syntax error

Check that you have a newline at the end of the file.

-- 
Peter Eisentraut      peter_e@gmx.net       http://yi.org/peter-e/



Re: Syslog Facility Patch

From
Larry Rosenman
Date:
* Peter Eisentraut <peter_e@gmx.net> [001114 14:39]:
> Larry Rosenman writes:
> 
> > * Peter Eisentraut <peter_e@gmx.net> [001114 13:18]:
> > > Larry Rosenman writes:
> > > 
> > > > > I can't reproduce that.  I set 'syslog_facility = local97' and got the
> > > > > right error message.
> > > > try setting it in postgresql.conf....
> > > 
> > > That's what I did.
> > Hmm.  Here is what I get: 
> > $ ../bin/pg_ctl -D ~/pg-test/data -o "-p 7777 -i" start
> > postmaster successfully started up.
> > $ FATAL 1:  postgresql.conf:17: syntax error
> 
> Check that you have a newline at the end of the file.
I do.  If I put the correct value all works fine (I took the
sample and edited it).

"postgresql.conf" 25L, 685C [w]
Thanks for using Vim 507 . --Sven Guckes@vim.org!
$ pwd
/home/ler/pg-test/data
$ cd ..
$ bin/pg_ctl -D ./data -o "-p 7777 -i" start
postmaster successfully started up.
$ FATAL 1:  postgresql.conf:17: syntax error

$ cat data/postgresql.conf
#
# PostgreSQL configuration file
# -----------------------------
#
# This file consists of lines of the form
#
#   name = value
#
# (The `=' is optional.) White space is collapsed, comments are
# introduced by `#' anywhere on a line. The complete list of option
# names and allowed values can be found in the PostgreSQL
# documentation. Examples are:

log_connections = on
fsync = off
#max_backends = 64
syslog_facility = LOCAL5.3we4rwjtasrtuert
syslog_progid = pgtest
syslog=2
showportnumber = on

# Any option can also be given as a command line switch to the
# postmaster, e.g., `postmaster --log-connections=on'. Some options
# can be set at run-time with the `SET' SQL command.

$
> 
> -- 
> Peter Eisentraut      peter_e@gmx.net       http://yi.org/peter-e/

-- 
Larry Rosenman                      http://www.lerctr.org/~ler
Phone: +1 972-414-9812 (voice) Internet: ler@lerctr.org
US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749


Re: Syslog Facility Patch

From
Larry Rosenman
Date:
* Larry Rosenman <ler@lerctr.org> [001114 14:44]:
> * Peter Eisentraut <peter_e@gmx.net> [001114 14:39]:
> > Larry Rosenman writes:
> > 
> > > * Peter Eisentraut <peter_e@gmx.net> [001114 13:18]:
> > > > Larry Rosenman writes:
> > > > 
> > > > > > I can't reproduce that.  I set 'syslog_facility = local97' and got the
> > > > > > right error message.
> > > > > try setting it in postgresql.conf....
> > > > 
> > > > That's what I did.
> > > Hmm.  Here is what I get: 
> > > $ ../bin/pg_ctl -D ~/pg-test/data -o "-p 7777 -i" start
> > > postmaster successfully started up.
> > > $ FATAL 1:  postgresql.conf:17: syntax error
> > 
> > Check that you have a newline at the end of the file.
> I do.  If I put the correct value all works fine (I took the
> sample and edited it).
> 
> "postgresql.conf" 25L, 685C [w]
> Thanks for using Vim 507 . --Sven Guckes@vim.org!
> $ pwd
> /home/ler/pg-test/data
> $ cd ..
> $ bin/pg_ctl -D ./data -o "-p 7777 -i" start
> postmaster successfully started up.
> $ FATAL 1:  postgresql.conf:17: syntax error
> 
> $ cat data/postgresql.conf
> #
> # PostgreSQL configuration file
> # -----------------------------
> #
> # This file consists of lines of the form
> #
> #   name = value
> #
> # (The `=' is optional.) White space is collapsed, comments are
> # introduced by `#' anywhere on a line. The complete list of option
> # names and allowed values can be found in the PostgreSQL
> # documentation. Examples are:
> 
> log_connections = on
> fsync = off
> #max_backends = 64
> syslog_facility = LOCAL5.3we4rwjtasrtuert
> syslog_progid = pgtest
> syslog=2
> showportnumber = on
> 
> # Any option can also be given as a command line switch to the
> # postmaster, e.g., `postmaster --log-connections=on'. Some options
> # can be set at run-time with the `SET' SQL command.
> 
> $
> > 
> > -- 
> > Peter Eisentraut      peter_e@gmx.net       http://yi.org/peter-e/
Interestingly, on my FreeBSD box:
$ ../bin/pg_ctl -D ~/pg-test/data -o "-p 7777 -i" start
postmaster successfully started up.
$ FATAL 1:  invalid value for option 'syslog_facility':
'LOCAL112oieq4u2345'

$ uname -a
FreeBSD lerbsd.lerctr.org 4.2-BETA FreeBSD 4.2-BETA #82: Sun Nov 12
16:57:22 CST2000     ler@lerbsd.lerctr.org:/usr/src/sys/compile/LERBSD  i386
$

This looks like a portability issue.  The other stuff I sent was
from UnixWare 7.1.1 using native cc. 

LER

> 
> -- 
> Larry Rosenman                      http://www.lerctr.org/~ler
> Phone: +1 972-414-9812 (voice) Internet: ler@lerctr.org
> US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749
-- 
Larry Rosenman                      http://www.lerctr.org/~ler
Phone: +1 972-414-9812 (voice) Internet: ler@lerctr.org
US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749


Re: Syslog Facility Patch

From
Peter Eisentraut
Date:
Larry Rosenman writes:

> log_connections = on
> fsync = off
> #max_backends = 64
> syslog_facility = LOCAL5.3we4rwjtasrtuert

It's the dot.  The regular expression needs some work.  Make a note to
always test with identical values next time. :-)

> syslog_progid = pgtest
> syslog=2
> showportnumber = on

-- 
Peter Eisentraut      peter_e@gmx.net       http://yi.org/peter-e/



Re: Syslog Facility Patch

From
Larry Rosenman
Date:
* Peter Eisentraut <peter_e@gmx.net> [001114 16:03]:
> Larry Rosenman writes:
> 
> > log_connections = on
> > fsync = off
> > #max_backends = 64
> > syslog_facility = LOCAL5.3we4rwjtasrtuert
> 
> It's the dot.  The regular expression needs some work.  Make a note to
> always test with identical values next time. :-)
OK, so the parser needs help?  Can I try and fix it?  What DON'T we 
want guc-file.l to accept for a string?


> 
> > syslog_progid = pgtest
> > syslog=2
> > showportnumber = on
> 
> -- 
> Peter Eisentraut      peter_e@gmx.net       http://yi.org/peter-e/

-- 
Larry Rosenman                      http://www.lerctr.org/~ler
Phone: +1 972-414-9812 (voice) Internet: ler@lerctr.org
US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749


Re: Syslog Facility Patch

From
Larry Rosenman
Date:
* Larry Rosenman <ler@lerctr.org> [001114 16:06]:
> * Peter Eisentraut <peter_e@gmx.net> [001114 16:03]:
> > Larry Rosenman writes:
> > 
> > > log_connections = on
> > > fsync = off
> > > #max_backends = 64
> > > syslog_facility = LOCAL5.3we4rwjtasrtuert
> > 
> > It's the dot.  The regular expression needs some work.  Make a note to
> > always test with identical values next time. :-)
> OK, so the parser needs help?  Can I try and fix it?  What DON'T we 
> want guc-file.l to accept for a string?
Ok, so what I think(?) needs to happen is the FIXME: tag needs to be
handled.  We need to code a version of src/backend/parser/scansup.c
that doesn't use palloc, and also strips the apostrophes from the
front and end of the string?  This doesn't look that hard. Do I have 
"permission" to play with it, and submit a patch when I've got it
fixed? 

I ass/u/me we want to allow any of the 'C' escapes? or just
a-zA-Z0-9-. for a GUC_STRING? 
> 
> 
> > 
> > > syslog_progid = pgtest
> > > syslog=2
> > > showportnumber = on
> > 
> > -- 
> > Peter Eisentraut      peter_e@gmx.net       http://yi.org/peter-e/
> 
> -- 
> Larry Rosenman                      http://www.lerctr.org/~ler
> Phone: +1 972-414-9812 (voice) Internet: ler@lerctr.org
> US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749
-- 
Larry Rosenman                      http://www.lerctr.org/~ler
Phone: +1 972-414-9812 (voice) Internet: ler@lerctr.org
US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749


Re: Syslog Facility Patch

From
Larry Rosenman
Date:
* Larry Rosenman <ler@lerctr.org> [001114 16:56]:
> Ok, so what I think(?) needs to happen is the FIXME: tag needs to be
> handled.  We need to code a version of src/backend/parser/scansup.c
> that doesn't use palloc, and also strips the apostrophes from the
> front and end of the string?  This doesn't look that hard. Do I have 
> "permission" to play with it, and submit a patch when I've got it
> fixed? 
> 
> I ass/u/me we want to allow any of the 'C' escapes? or just
> a-zA-Z0-9-. for a GUC_STRING? 
Ok, baring objections, I'm going to code up a routine to put into
guc-file.l that removes the quotes/apostrophes from a GUC_STRING, and
matches for [-.a-zA-Z0-9] within the string.  We can tune more later. 

Probably won't get posted tonight, but in the next 48 hours. 

Larry
-- 
Larry Rosenman                      http://www.lerctr.org/~ler
Phone: +1 972-414-9812 (voice) Internet: ler@lerctr.org
US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749


Re: Syslog Facility Patch

From
Larry Rosenman
Date:
* Larry Rosenman <ler@lerctr.org> [001114 20:45]:
> * Larry Rosenman <ler@lerctr.org> [001114 16:56]:
> > Ok, so what I think(?) needs to happen is the FIXME: tag needs to be
> > handled.  We need to code a version of src/backend/parser/scansup.c
> > that doesn't use palloc, and also strips the apostrophes from the
> > front and end of the string?  This doesn't look that hard. Do I have 
> > "permission" to play with it, and submit a patch when I've got it
> > fixed? 
> > 
> > I ass/u/me we want to allow any of the 'C' escapes? or just
> > a-zA-Z0-9-. for a GUC_STRING? 
> Ok, baring objections, I'm going to code up a routine to put into
> guc-file.l that removes the quotes/apostrophes from a GUC_STRING, and
> matches for [-.a-zA-Z0-9] within the string.  We can tune more later. 
> 
> Probably won't get posted tonight, but in the next 48 hours. 
Ok, I changed my mind, and brute forced it.  Here's a patch that 
accepts either 'string' or "string", and then kills off the ' or ". 
Let me know if this violates style or portability guidelines. 
It depends on ANSI memmove(). 

Index: guc-file.l
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/utils/misc/guc-file.l,v
retrieving revision 1.4
diff -c -r1.4 guc-file.l
*** guc-file.l    2000/07/27 19:49:18    1.4
--- guc-file.l    2000/11/15 05:52:57
***************
*** 45,51 ****  /* prototype, so compiler is happy with our high warnings setting */ int GUC_yylex(void);
-  %}  SIGN            ("-"|"+")
--- 45,50 ----
***************
*** 69,76 ****  * work right. Now there are no string options, and if there were then  * the unquoted (`ID') tokens
shouldstill work. Of course this only  * affects the configuration file.  */
 
! STRING          \'([^'\n]|\\.)*'  %% 
--- 68,79 ----  * work right. Now there are no string options, and if there were then  * the unquoted (`ID') tokens
shouldstill work. Of course this only  * affects the configuration file.
 
+  * LER 14NOV2000: I set it up to accept either a quoted string or a string
+  * in apostrophes.  I then kill off the 1st and last characters.  There is 
+  * no special handling for doubled terminators or 'C' escapes. 
+  * this allows most other characters to be used.  */
! STRING          (\'|\")([^'"\n]|\\.)*(\'|\")  %% 
***************
*** 215,220 ****
--- 218,232 ----                 opt_value = strdup(yytext);                 if (opt_value == NULL)
gotoout_of_memory;
 
+         if (token == GUC_STRING)
+         {
+             /* remove the beginning and ending quote/apostrophe */
+             /* first: shift the whole shooting match down one
+              character */
+             memmove(opt_value,opt_value+1,strlen(opt_value)-1);
+             /* second: null out the 2 characters we shifted */
+                         opt_value[strlen(opt_value)-2]='\0';
+         }                 parse_state = 2;                 break; 
-- 
Larry Rosenman                      http://www.lerctr.org/~ler
Phone: +1 972-414-9812 (voice) Internet: ler@lerctr.org
US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749


Re: Syslog Facility Patch

From
Peter Eisentraut
Date:
Larry Rosenman writes:

> Ok, so what I think(?) needs to happen is the FIXME: tag needs to be
> handled.  We need to code a version of src/backend/parser/scansup.c
> that doesn't use palloc, and also strips the apostrophes from the
> front and end of the string?  This doesn't look that hard. Do I have 
> "permission" to play with it, and submit a patch when I've got it
> fixed? 

Some background information:  The current
 name = value

syntax is lexically compatible with the syntax of the SET command.  
Therefore you can't have "funny" characters in 'value' unless
single-quoted.

Now in the context of the config file this seems overly restrictive.  
Therefore I'd agree that we relax that a bit and allow more characters to
go into 'value' unquoted.  I'm not quite sure which, but to prevent
confusion I'd prefer no semicolons, whitespace, or equal signs, possibly
others.

This would require making 'value' a different token type from 'name',
because the latter should not accept these characters.

Additionally, the FIXME ought to be done.  I'd prefer it if it accepted
the exact same escapes and all as does the SQL parser/scanner.  So it
ought to be a copy and paste from scansup.c.  I'm not excited about
allowing double-quotes though.

-- 
Peter Eisentraut      peter_e@gmx.net       http://yi.org/peter-e/



Re: Syslog Facility Patch

From
Larry Rosenman
Date:
* Peter Eisentraut <peter_e@gmx.net> [001115 10:26]:
> Larry Rosenman writes:
> 
> > Ok, so what I think(?) needs to happen is the FIXME: tag needs to be
> > handled.  We need to code a version of src/backend/parser/scansup.c
> > that doesn't use palloc, and also strips the apostrophes from the
> > front and end of the string?  This doesn't look that hard. Do I have 
> > "permission" to play with it, and submit a patch when I've got it
> > fixed? 
> 
> Some background information:  The current
> 
>   name = value
> 
> syntax is lexically compatible with the syntax of the SET command.  
> Therefore you can't have "funny" characters in 'value' unless
> single-quoted.
I added period(.), hyphen(-), and underscore(_).
> 
> Now in the context of the config file this seems overly restrictive.  
> Therefore I'd agree that we relax that a bit and allow more characters to
> go into 'value' unquoted.  I'm not quite sure which, but to prevent
> confusion I'd prefer no semicolons, whitespace, or equal signs, possibly
> others.
> 
> This would require making 'value' a different token type from 'name',
> because the latter should not accept these characters.
done, as GUC_UNQUOTED_STRING.
> 
> Additionally, the FIXME ought to be done.  I'd prefer it if it accepted
> the exact same escapes and all as does the SQL parser/scanner.  So it
> ought to be a copy and paste from scansup.c.  I'm not excited about
> allowing double-quotes though.
Done.  Added as GUC_scanstr. 

Here is a patch.  Comments? 

Index: src/backend/utils/misc/guc-file.l
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/utils/misc/guc-file.l,v
retrieving revision 1.4
diff -c -r1.4 guc-file.l
*** src/backend/utils/misc/guc-file.l    2000/07/27 19:49:18    1.4
--- src/backend/utils/misc/guc-file.l    2000/11/15 18:13:20
***************
*** 16,21 ****
--- 16,22 ---- #include <sys/stat.h> #include <unistd.h> #include <errno.h>
+ #include <ctype.h>  #include "miscadmin.h" #include "storage/fd.h"
***************
*** 32,37 ****
--- 33,39 ----     GUC_INTEGER = 3,     GUC_REAL = 4,     GUC_EQUALS = 5,
+     GUC_UNQUOTED_STRING = 6,     GUC_EOL = 99,     GUC_ERROR = 100 };
***************
*** 45,51 ****  /* prototype, so compiler is happy with our high warnings setting */ int GUC_yylex(void);
!  %}  SIGN            ("-"|"+")
--- 47,53 ----  /* prototype, so compiler is happy with our high warnings setting */ int GUC_yylex(void);
! char *GUC_scanstr(char *); %}  SIGN            ("-"|"+")
***************
*** 69,76 ****  * work right. Now there are no string options, and if there were then  * the unquoted (`ID') tokens
shouldstill work. Of course this only  * affects the configuration file.  */
 
! STRING          \'([^'\n]|\\.)*'  %% 
--- 71,83 ----  * work right. Now there are no string options, and if there were then  * the unquoted (`ID') tokens
shouldstill work. Of course this only  * affects the configuration file.
 
+  * LER 14NOV2000: I set it up to accept either a quoted string or a string
+  * in apostrophes.  I then kill off the 1st and last characters.  There is 
+  * no special handling for doubled terminators or 'C' escapes. 
+  * this allows most other characters to be used.  */
! UNQUOTED_STRING {LETTER}({LETTER_OR_DIGIT}|[-._])*
! STRING          (\'|\")([^'"\n]|\\.)*(\'|\")  %% 
***************
*** 80,85 ****
--- 87,93 ----  {ID}            return GUC_ID; {STRING}        return GUC_STRING;
+ {UNQUOTED_STRING} return GUC_UNQUOTED_STRING; {INTEGER}       return GUC_INTEGER; {REAL}          return GUC_REAL; =
            return GUC_EQUALS;
 
***************
*** 210,220 ****                 if (token == GUC_EQUALS)                     token = yylex(); 
!                 if (token != GUC_ID && token != GUC_STRING && token != GUC_INTEGER && token != GUC_REAL)
      goto parse_error;                 opt_value = strdup(yytext);                 if (opt_value == NULL)
      goto out_of_memory;                 parse_state = 2;                 break; 
 
--- 218,239 ----                 if (token == GUC_EQUALS)                     token = yylex(); 
!                 if (token != GUC_ID && token != GUC_STRING && token != GUC_INTEGER && token != GUC_REAL && token !=
GUC_UNQUOTED_STRING)                    goto parse_error;                 opt_value = strdup(yytext);
if(opt_value == NULL)                     goto out_of_memory;
 
+         if (token == GUC_STRING)
+         {
+             /* remove the beginning and ending quote/apostrophe */
+             /* first: shift the whole shooting match down one
+              character */
+             memmove(opt_value,opt_value+1,strlen(opt_value)-1);
+             /* second: null out the 2 characters we shifted */
+                         opt_value[strlen(opt_value)-2]='\0';
+             /* do the escape thing.  free()'s the strdup above */
+             opt_value=GUC_scanstr(opt_value);
+         }                 parse_state = 2;                 break; 
***************
*** 283,286 ****
--- 302,400 ---- yywrap(void) {     return 1;
+ }
+ 
+ /* ----------------
+  *        scanstr
+  *
+  * if the string passed in has escaped codes, map the escape codes to actual
+  * chars
+  *
+  * the string returned is palloc'd and should eventually be pfree'd by the
+  * caller!
+  * ----------------
+  */
+ 
+ char *
+ GUC_scanstr(char *s)
+ {
+     char       *newStr;
+     int            len,
+                 i,
+                 j;
+ 
+     if (s == NULL || s[0] == '\0')
+     {
+         if (s != NULL) free (s);
+         return strdup("");
+ 
+     }
+     len = strlen(s);
+ 
+     newStr = malloc(len + 1);    /* string cannot get longer */
+ 
+     for (i = 0, j = 0; i < len; i++)
+     {
+         if (s[i] == '\'')
+         {
+ 
+             /*
+              * Note: if scanner is working right, unescaped quotes can
+              * only appear in pairs, so there should be another character.
+              */
+             i++;
+             newStr[j] = s[i];
+         }
+         else if (s[i] == '\\')
+         {
+             i++;
+             switch (s[i])
+             {
+                 case 'b':
+                     newStr[j] = '\b';
+                     break;
+                 case 'f':
+                     newStr[j] = '\f';
+                     break;
+                 case 'n':
+                     newStr[j] = '\n';
+                     break;
+                 case 'r':
+                     newStr[j] = '\r';
+                     break;
+                 case 't':
+                     newStr[j] = '\t';
+                     break;
+                 case '0':
+                 case '1':
+                 case '2':
+                 case '3':
+                 case '4':
+                 case '5':
+                 case '6':
+                 case '7':
+                     {
+                         int            k;
+                         long        octVal = 0;
+ 
+                         for (k = 0;
+                              s[i + k] >= '0' && s[i + k] <= '7' && k < 3;
+                              k++)
+                             octVal = (octVal << 3) + (s[i + k] - '0');
+                         i += k - 1;
+                         newStr[j] = ((char) octVal);
+                     }
+                     break;
+                 default:
+                     newStr[j] = s[i];
+                     break;
+             }                    /* switch */
+         }                        /* s[i] == '\\' */
+         else
+             newStr[j] = s[i];
+         j++;
+     }
+     newStr[j] = '\0';
+     free(s);
+     return newStr; }

-- 
Larry Rosenman                      http://www.lerctr.org/~ler
Phone: +1 972-414-9812 (voice) Internet: ler@lerctr.org
US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749


Re: Syslog Facility Patch

From
Peter Eisentraut
Date:
Larry Rosenman writes:

> > syntax is lexically compatible with the syntax of the SET command.  
> > Therefore you can't have "funny" characters in 'value' unless
> > single-quoted.
> I added period(.), hyphen(-), and underscore(_).

Probably '/' and ':' as well, for krb_server_keyfile.

> ! UNQUOTED_STRING {LETTER}({LETTER_OR_DIGIT}|[-._])*
> ! STRING          (\'|\")([^'"\n]|\\.)*(\'|\")

That will accept strings that start with one kind of quote and end with
another.  Please stick to single-quotes only, unless you want to make a
case for the double-quotes.

I'm also not quite sure about

> +         if (s[i] == '\'')
> +         {
> + 
> +             /*
> +              * Note: if scanner is working right, unescaped quotes can
> +              * only appear in pairs, so there should be another character.
> +              */
> +             i++;
> +             newStr[j] = s[i];
> +         }

The SQL scanner accepts 'foo''bar' as the SQL-approved method of escaping
quotes in quotes.  GUC doesn't do that (way too complicated for now), so
this probably needs to be adjusted.

Other than that, looks good.

-- 
Peter Eisentraut      peter_e@gmx.net       http://yi.org/peter-e/



Re: Syslog Facility Patch

From
Larry Rosenman
Date:
* Peter Eisentraut <peter_e@gmx.net> [001115 13:11]:
> Larry Rosenman writes:
> 
> > > syntax is lexically compatible with the syntax of the SET command.  
> > > Therefore you can't have "funny" characters in 'value' unless
> > > single-quoted.
> > I added period(.), hyphen(-), and underscore(_).
> 
> Probably '/' and ':' as well, for krb_server_keyfile.
Added. 
> 
> > ! UNQUOTED_STRING {LETTER}({LETTER_OR_DIGIT}|[-._])*
> > ! STRING          (\'|\")([^'"\n]|\\.)*(\'|\")
> 
> That will accept strings that start with one kind of quote and end with
> another.  Please stick to single-quotes only, unless you want to make a
> case for the double-quotes.
Done.  
> 
> I'm also not quite sure about
> 
> > +         if (s[i] == '\'')
> > +         {
> > + 
> > +             /*
> > +              * Note: if scanner is working right, unescaped quotes can
> > +              * only appear in pairs, so there should be another character.
> > +              */
> > +             i++;
> > +             newStr[j] = s[i];
> > +         }
> 
> The SQL scanner accepts 'foo''bar' as the SQL-approved method of escaping
> quotes in quotes.  GUC doesn't do that (way too complicated for now), so
> this probably needs to be adjusted.
Removed.  
> 
> Other than that, looks good.
I also added the token that caused the parse error to be printed out. 

I also added some whitespace on a couple of places that the lines
were getting, err, long. 

New Version:

Index: src/backend/utils/misc/guc-file.l
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/utils/misc/guc-file.l,v
retrieving revision 1.4
diff -c -r1.4 guc-file.l
*** src/backend/utils/misc/guc-file.l    2000/07/27 19:49:18    1.4
--- src/backend/utils/misc/guc-file.l    2000/11/15 19:34:54
***************
*** 16,21 ****
--- 16,22 ---- #include <sys/stat.h> #include <unistd.h> #include <errno.h>
+ #include <ctype.h>  #include "miscadmin.h" #include "storage/fd.h"
***************
*** 32,37 ****
--- 33,39 ----     GUC_INTEGER = 3,     GUC_REAL = 4,     GUC_EQUALS = 5,
+     GUC_UNQUOTED_STRING = 6,     GUC_EOL = 99,     GUC_ERROR = 100 };
***************
*** 45,51 ****  /* prototype, so compiler is happy with our high warnings setting */ int GUC_yylex(void);
!  %}  SIGN            ("-"|"+")
--- 47,53 ----  /* prototype, so compiler is happy with our high warnings setting */ int GUC_yylex(void);
! char *GUC_scanstr(char *); %}  SIGN            ("-"|"+")
***************
*** 61,77 **** LETTER_OR_DIGIT [A-Za-z_0-9\200-\377]  ID              {LETTER}{LETTER_OR_DIGIT}*
- /*
-  * FIXME: This string syntax is nice and all but of course the quotes
-  * need to be stripped before we can make any use of the string value.
-  * There is a function in parser/scansup.c that does this but it uses
-  * palloc and there might be a little more magic needed to get it to
-  * work right. Now there are no string options, and if there were then
-  * the unquoted (`ID') tokens should still work. Of course this only
-  * affects the configuration file.
-  */
- STRING          \'([^'\n]|\\.)*'  %%  \n              ConfigFileLineno++; return GUC_EOL;
--- 63,72 ---- LETTER_OR_DIGIT [A-Za-z_0-9\200-\377]  ID              {LETTER}{LETTER_OR_DIGIT}* 
+ UNQUOTED_STRING {LETTER}({LETTER_OR_DIGIT}|[-._:/×])*
+ STRING          \'([^'"\n]|\\.)*\'
+  %%  \n              ConfigFileLineno++; return GUC_EOL;
***************
*** 80,85 ****
--- 75,81 ----  {ID}            return GUC_ID; {STRING}        return GUC_STRING;
+ {UNQUOTED_STRING} return GUC_UNQUOTED_STRING; {INTEGER}       return GUC_INTEGER; {REAL}          return GUC_REAL; =
            return GUC_EQUALS;
 
***************
*** 139,145 ****     int elevel;     FILE * fp; 
!     Assert(context == PGC_POSTMASTER || context == PGC_BACKEND || context == PGC_SIGHUP);     Assert(DataDir);
elevel= (context == PGC_SIGHUP) ? DEBUG : ERROR; 
 
--- 135,142 ----     int elevel;     FILE * fp; 
!     Assert(context == PGC_POSTMASTER || context == PGC_BACKEND 
!         || context == PGC_SIGHUP);     Assert(DataDir);     elevel = (context == PGC_SIGHUP) ? DEBUG : ERROR; 
***************
*** 210,220 ****                 if (token == GUC_EQUALS)                     token = yylex(); 
!                 if (token != GUC_ID && token != GUC_STRING && token != GUC_INTEGER && token != GUC_REAL)
      goto parse_error;                 opt_value = strdup(yytext);                 if (opt_value == NULL)
      goto out_of_memory;                 parse_state = 2;                 break; 
 
--- 207,230 ----                 if (token == GUC_EQUALS)                     token = yylex(); 
!                 if (token != GUC_ID && token != GUC_STRING && 
!             token != GUC_INTEGER && token != GUC_REAL && 
!             token != GUC_UNQUOTED_STRING)                     goto parse_error;                 opt_value =
strdup(yytext);                if (opt_value == NULL)                     goto out_of_memory;
 
+         if (token == GUC_STRING)
+         {
+             /* remove the beginning and ending quote/apostrophe */
+             /* first: shift the whole shooting match down one
+              character */
+             memmove(opt_value,opt_value+1,strlen(opt_value)-1);
+             /* second: null out the 2 characters we shifted */
+                         opt_value[strlen(opt_value)-2]='\0';
+             /* do the escape thing.  free()'s the strdup above */
+             opt_value=GUC_scanstr(opt_value);
+         }                 parse_state = 2;                 break; 
***************
*** 266,272 ****     FreeFile(fp);     free(filename);     free_name_value_list(head);
!     elog(elevel, CONFIG_FILENAME ":%u: syntax error", ConfigFileLineno);     return;   out_of_memory:
--- 276,283 ----     FreeFile(fp);     free(filename);     free_name_value_list(head);
!     elog(elevel, CONFIG_FILENAME ":%u: syntax error, token=\"%s\"", 
!         ConfigFileLineno,yytext);     return;   out_of_memory:
***************
*** 283,286 ****
--- 294,382 ---- yywrap(void) {     return 1;
+ }
+ 
+ /* ----------------
+  *        scanstr
+  *
+  * if the string passed in has escaped codes, map the escape codes to actual
+  * chars
+  *
+  * the string returned is malloc'd and should eventually be free'd by the
+  * caller!
+  * ----------------
+  */
+ 
+ char *
+ GUC_scanstr(char *s)
+ {
+     char       *newStr;
+     int            len,
+                 i,
+                 j;
+ 
+     if (s == NULL || s[0] == '\0')
+     {
+         if (s != NULL) free (s);
+         return strdup("");
+ 
+     }
+     len = strlen(s);
+ 
+     newStr = malloc(len + 1);    /* string cannot get longer */
+ 
+     for (i = 0, j = 0; i < len; i++)
+     {
+         if (s[i] == '\\')
+         {
+             i++;
+             switch (s[i])
+             {
+                 case 'b':
+                     newStr[j] = '\b';
+                     break;
+                 case 'f':
+                     newStr[j] = '\f';
+                     break;
+                 case 'n':
+                     newStr[j] = '\n';
+                     break;
+                 case 'r':
+                     newStr[j] = '\r';
+                     break;
+                 case 't':
+                     newStr[j] = '\t';
+                     break;
+                 case '0':
+                 case '1':
+                 case '2':
+                 case '3':
+                 case '4':
+                 case '5':
+                 case '6':
+                 case '7':
+                     {
+                         int            k;
+                         long        octVal = 0;
+ 
+                         for (k = 0;
+                              s[i + k] >= '0' && s[i + k] <= '7' && k < 3;
+                              k++)
+                             octVal = (octVal << 3) + (s[i + k] - '0');
+                         i += k - 1;
+                         newStr[j] = ((char) octVal);
+                     }
+                     break;
+                 default:
+                     newStr[j] = s[i];
+                     break;
+                 }
+             }                    /* switch */
+         else
+             newStr[j] = s[i];
+         j++;
+     }
+     newStr[j] = '\0';
+     free(s);
+     return newStr; }
-- 
Larry Rosenman                      http://www.lerctr.org/~ler
Phone: +1 972-414-9812 (voice) Internet: ler@lerctr.org
US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749


Re: Syslog Facility Patch

From
Larry Rosenman
Date:
Here is one with a stray character removed. 


Index: src/backend/utils/misc/guc-file.l
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/utils/misc/guc-file.l,v
retrieving revision 1.4
diff -c -r1.4 guc-file.l
*** src/backend/utils/misc/guc-file.l    2000/07/27 19:49:18    1.4
--- src/backend/utils/misc/guc-file.l    2000/11/15 19:50:32
***************
*** 16,21 ****
--- 16,22 ---- #include <sys/stat.h> #include <unistd.h> #include <errno.h>
+ #include <ctype.h>  #include "miscadmin.h" #include "storage/fd.h"
***************
*** 32,37 ****
--- 33,39 ----     GUC_INTEGER = 3,     GUC_REAL = 4,     GUC_EQUALS = 5,
+     GUC_UNQUOTED_STRING = 6,     GUC_EOL = 99,     GUC_ERROR = 100 };
***************
*** 45,51 ****  /* prototype, so compiler is happy with our high warnings setting */ int GUC_yylex(void);
!  %}  SIGN            ("-"|"+")
--- 47,53 ----  /* prototype, so compiler is happy with our high warnings setting */ int GUC_yylex(void);
! char *GUC_scanstr(char *); %}  SIGN            ("-"|"+")
***************
*** 61,77 **** LETTER_OR_DIGIT [A-Za-z_0-9\200-\377]  ID              {LETTER}{LETTER_OR_DIGIT}*
- /*
-  * FIXME: This string syntax is nice and all but of course the quotes
-  * need to be stripped before we can make any use of the string value.
-  * There is a function in parser/scansup.c that does this but it uses
-  * palloc and there might be a little more magic needed to get it to
-  * work right. Now there are no string options, and if there were then
-  * the unquoted (`ID') tokens should still work. Of course this only
-  * affects the configuration file.
-  */
- STRING          \'([^'\n]|\\.)*'  %%  \n              ConfigFileLineno++; return GUC_EOL;
--- 63,72 ---- LETTER_OR_DIGIT [A-Za-z_0-9\200-\377]  ID              {LETTER}{LETTER_OR_DIGIT}* 
+ UNQUOTED_STRING {LETTER}({LETTER_OR_DIGIT}|[-._:/])*
+ STRING          \'([^'"\n]|\\.)*\'
+  %%  \n              ConfigFileLineno++; return GUC_EOL;
***************
*** 80,85 ****
--- 75,81 ----  {ID}            return GUC_ID; {STRING}        return GUC_STRING;
+ {UNQUOTED_STRING} return GUC_UNQUOTED_STRING; {INTEGER}       return GUC_INTEGER; {REAL}          return GUC_REAL; =
            return GUC_EQUALS;
 
***************
*** 139,145 ****     int elevel;     FILE * fp; 
!     Assert(context == PGC_POSTMASTER || context == PGC_BACKEND || context == PGC_SIGHUP);     Assert(DataDir);
elevel= (context == PGC_SIGHUP) ? DEBUG : ERROR; 
 
--- 135,142 ----     int elevel;     FILE * fp; 
!     Assert(context == PGC_POSTMASTER || context == PGC_BACKEND 
!         || context == PGC_SIGHUP);     Assert(DataDir);     elevel = (context == PGC_SIGHUP) ? DEBUG : ERROR; 
***************
*** 210,220 ****                 if (token == GUC_EQUALS)                     token = yylex(); 
!                 if (token != GUC_ID && token != GUC_STRING && token != GUC_INTEGER && token != GUC_REAL)
      goto parse_error;                 opt_value = strdup(yytext);                 if (opt_value == NULL)
      goto out_of_memory;                 parse_state = 2;                 break; 
 
--- 207,230 ----                 if (token == GUC_EQUALS)                     token = yylex(); 
!                 if (token != GUC_ID && token != GUC_STRING && 
!             token != GUC_INTEGER && token != GUC_REAL && 
!             token != GUC_UNQUOTED_STRING)                     goto parse_error;                 opt_value =
strdup(yytext);                if (opt_value == NULL)                     goto out_of_memory;
 
+         if (token == GUC_STRING)
+         {
+             /* remove the beginning and ending quote/apostrophe */
+             /* first: shift the whole shooting match down one
+              character */
+             memmove(opt_value,opt_value+1,strlen(opt_value)-1);
+             /* second: null out the 2 characters we shifted */
+                         opt_value[strlen(opt_value)-2]='\0';
+             /* do the escape thing.  free()'s the strdup above */
+             opt_value=GUC_scanstr(opt_value);
+         }                 parse_state = 2;                 break; 
***************
*** 266,272 ****     FreeFile(fp);     free(filename);     free_name_value_list(head);
!     elog(elevel, CONFIG_FILENAME ":%u: syntax error", ConfigFileLineno);     return;   out_of_memory:
--- 276,283 ----     FreeFile(fp);     free(filename);     free_name_value_list(head);
!     elog(elevel, CONFIG_FILENAME ":%u: syntax error, token=\"%s\"", 
!         ConfigFileLineno,yytext);     return;   out_of_memory:
***************
*** 283,286 ****
--- 294,382 ---- yywrap(void) {     return 1;
+ }
+ 
+ /* ----------------
+  *        scanstr
+  *
+  * if the string passed in has escaped codes, map the escape codes to actual
+  * chars
+  *
+  * the string returned is malloc'd and should eventually be free'd by the
+  * caller!
+  * ----------------
+  */
+ 
+ char *
+ GUC_scanstr(char *s)
+ {
+     char       *newStr;
+     int            len,
+                 i,
+                 j;
+ 
+     if (s == NULL || s[0] == '\0')
+     {
+         if (s != NULL) free (s);
+         return strdup("");
+ 
+     }
+     len = strlen(s);
+ 
+     newStr = malloc(len + 1);    /* string cannot get longer */
+ 
+     for (i = 0, j = 0; i < len; i++)
+     {
+         if (s[i] == '\\')
+         {
+             i++;
+             switch (s[i])
+             {
+                 case 'b':
+                     newStr[j] = '\b';
+                     break;
+                 case 'f':
+                     newStr[j] = '\f';
+                     break;
+                 case 'n':
+                     newStr[j] = '\n';
+                     break;
+                 case 'r':
+                     newStr[j] = '\r';
+                     break;
+                 case 't':
+                     newStr[j] = '\t';
+                     break;
+                 case '0':
+                 case '1':
+                 case '2':
+                 case '3':
+                 case '4':
+                 case '5':
+                 case '6':
+                 case '7':
+                     {
+                         int            k;
+                         long        octVal = 0;
+ 
+                         for (k = 0;
+                              s[i + k] >= '0' && s[i + k] <= '7' && k < 3;
+                              k++)
+                             octVal = (octVal << 3) + (s[i + k] - '0');
+                         i += k - 1;
+                         newStr[j] = ((char) octVal);
+                     }
+                     break;
+                 default:
+                     newStr[j] = s[i];
+                     break;
+                 }
+             }                    /* switch */
+         else
+             newStr[j] = s[i];
+         j++;
+     }
+     newStr[j] = '\0';
+     free(s);
+     return newStr; }
-- 
Larry Rosenman                      http://www.lerctr.org/~ler
Phone: +1 972-414-9812 (voice) Internet: ler@lerctr.org
US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749


Re: Syslog Facility Patch

From
Bruce Momjian
Date:
Applied.


> * Peter Eisentraut <peter_e@gmx.net> [001113 23:52]:
> > Okay, but you can't make these options PGC_SIGHUP unless you make sure to
> > close and re-open the syslog channel whenever these options
> > change.  Probably ought to be PGC_POSTMASTER.
> Here is a patch to change to PGC_POSTMASTER...
> 
> 
> Index: guc.c
> ===================================================================
> RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/utils/misc/guc.c,v
> retrieving revision 1.19
> diff -c -r1.19 guc.c
> *** guc.c    2000/11/14 01:15:02    1.19
> --- guc.c    2000/11/14 13:11:33
> ***************
> *** 309,317 ****
>       {"unix_socket_group",         PGC_POSTMASTER,       &Unix_socket_group,
>        "", NULL},
>   #ifdef ENABLE_SYSLOG
> !     {"syslog_facility",           PGC_SIGHUP,        &Syslog_facility, 
>       "LOCAL0", check_facility},     
> !     {"syslog_progid",             PGC_SIGHUP,        &Syslog_progid, 
>       "postgres", NULL},     
>   #endif
>   
> --- 309,317 ----
>       {"unix_socket_group",         PGC_POSTMASTER,       &Unix_socket_group,
>        "", NULL},
>   #ifdef ENABLE_SYSLOG
> !     {"syslog_facility",           PGC_POSTMASTER,        &Syslog_facility, 
>       "LOCAL0", check_facility},     
> !     {"syslog_progid",             PGC_POSTMASTER,        &Syslog_progid, 
>       "postgres", NULL},     
>   #endif
>   
> -- 
> Larry Rosenman                      http://www.lerctr.org/~ler
> Phone: +1 972-414-9812 (voice) Internet: ler@lerctr.org
> US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749
> 


--  Bruce Momjian                        |  http://candle.pha.pa.us pgman@candle.pha.pa.us               |  (610)
853-3000+  If your life is a hard drive,     |  830 Blythe Avenue +  Christ can be your backup.        |  Drexel Hill,
Pennsylvania19026
 


Re: Syslog Facility Patch

From
Bruce Momjian
Date:
Sorry, this was not applied.  Seems it is already fixed.



> * Peter Eisentraut <peter_e@gmx.net> [001113 23:52]:
> > Okay, but you can't make these options PGC_SIGHUP unless you make sure to
> > close and re-open the syslog channel whenever these options
> > change.  Probably ought to be PGC_POSTMASTER.
> Here is a patch to change to PGC_POSTMASTER...
> 
> 
> Index: guc.c
> ===================================================================
> RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/utils/misc/guc.c,v
> retrieving revision 1.19
> diff -c -r1.19 guc.c
> *** guc.c    2000/11/14 01:15:02    1.19
> --- guc.c    2000/11/14 13:11:33
> ***************
> *** 309,317 ****
>       {"unix_socket_group",         PGC_POSTMASTER,       &Unix_socket_group,
>        "", NULL},
>   #ifdef ENABLE_SYSLOG
> !     {"syslog_facility",           PGC_SIGHUP,        &Syslog_facility, 
>       "LOCAL0", check_facility},     
> !     {"syslog_progid",             PGC_SIGHUP,        &Syslog_progid, 
>       "postgres", NULL},     
>   #endif
>   
> --- 309,317 ----
>       {"unix_socket_group",         PGC_POSTMASTER,       &Unix_socket_group,
>        "", NULL},
>   #ifdef ENABLE_SYSLOG
> !     {"syslog_facility",           PGC_POSTMASTER,        &Syslog_facility, 
>       "LOCAL0", check_facility},     
> !     {"syslog_progid",             PGC_POSTMASTER,        &Syslog_progid, 
>       "postgres", NULL},     
>   #endif
>   
> -- 
> Larry Rosenman                      http://www.lerctr.org/~ler
> Phone: +1 972-414-9812 (voice) Internet: ler@lerctr.org
> US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749
> 


--  Bruce Momjian                        |  http://candle.pha.pa.us pgman@candle.pha.pa.us               |  (610)
853-3000+  If your life is a hard drive,     |  830 Blythe Avenue +  Christ can be your backup.        |  Drexel Hill,
Pennsylvania19026
 


Re: Syslog Facility Patch

From
Bruce Momjian
Date:
Applied.


> Here is one with a stray character removed. 
> 
> 
> Index: src/backend/utils/misc/guc-file.l
> ===================================================================
> RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/utils/misc/guc-file.l,v
> retrieving revision 1.4
> diff -c -r1.4 guc-file.l
> *** src/backend/utils/misc/guc-file.l    2000/07/27 19:49:18    1.4
> --- src/backend/utils/misc/guc-file.l    2000/11/15 19:50:32
> ***************
> *** 16,21 ****
> --- 16,22 ----
>   #include <sys/stat.h>
>   #include <unistd.h>
>   #include <errno.h>
> + #include <ctype.h>
>   
>   #include "miscadmin.h"
>   #include "storage/fd.h"
> ***************
> *** 32,37 ****
> --- 33,39 ----
>       GUC_INTEGER = 3,
>       GUC_REAL = 4,
>       GUC_EQUALS = 5,
> +     GUC_UNQUOTED_STRING = 6,
>       GUC_EOL = 99,
>       GUC_ERROR = 100
>   };
> ***************
> *** 45,51 ****
>   
>   /* prototype, so compiler is happy with our high warnings setting */
>   int GUC_yylex(void);
> ! 
>   %}
>   
>   SIGN            ("-"|"+")
> --- 47,53 ----
>   
>   /* prototype, so compiler is happy with our high warnings setting */
>   int GUC_yylex(void);
> ! char *GUC_scanstr(char *);
>   %}
>   
>   SIGN            ("-"|"+")
> ***************
> *** 61,77 ****
>   LETTER_OR_DIGIT [A-Za-z_0-9\200-\377]
>   
>   ID              {LETTER}{LETTER_OR_DIGIT}*
> - /*
> -  * FIXME: This string syntax is nice and all but of course the quotes
> -  * need to be stripped before we can make any use of the string value.
> -  * There is a function in parser/scansup.c that does this but it uses
> -  * palloc and there might be a little more magic needed to get it to
> -  * work right. Now there are no string options, and if there were then
> -  * the unquoted (`ID') tokens should still work. Of course this only
> -  * affects the configuration file.
> -  */
> - STRING          \'([^'\n]|\\.)*'
>   
>   %%
>   
>   \n              ConfigFileLineno++; return GUC_EOL;
> --- 63,72 ----
>   LETTER_OR_DIGIT [A-Za-z_0-9\200-\377]
>   
>   ID              {LETTER}{LETTER_OR_DIGIT}*
>   
> + UNQUOTED_STRING {LETTER}({LETTER_OR_DIGIT}|[-._:/])*
> + STRING          \'([^'"\n]|\\.)*\'
> + 
>   %%
>   
>   \n              ConfigFileLineno++; return GUC_EOL;
> ***************
> *** 80,85 ****
> --- 75,81 ----
>   
>   {ID}            return GUC_ID;
>   {STRING}        return GUC_STRING;
> + {UNQUOTED_STRING} return GUC_UNQUOTED_STRING;
>   {INTEGER}       return GUC_INTEGER;
>   {REAL}          return GUC_REAL;
>   =               return GUC_EQUALS;
> ***************
> *** 139,145 ****
>       int elevel;
>       FILE * fp;
>   
> !     Assert(context == PGC_POSTMASTER || context == PGC_BACKEND || context == PGC_SIGHUP);
>       Assert(DataDir);
>       elevel = (context == PGC_SIGHUP) ? DEBUG : ERROR;
>   
> --- 135,142 ----
>       int elevel;
>       FILE * fp;
>   
> !     Assert(context == PGC_POSTMASTER || context == PGC_BACKEND 
> !         || context == PGC_SIGHUP);
>       Assert(DataDir);
>       elevel = (context == PGC_SIGHUP) ? DEBUG : ERROR;
>   
> ***************
> *** 210,220 ****
>                   if (token == GUC_EQUALS)
>                       token = yylex();
>   
> !                 if (token != GUC_ID && token != GUC_STRING && token != GUC_INTEGER && token != GUC_REAL)
>                       goto parse_error;
>                   opt_value = strdup(yytext);
>                   if (opt_value == NULL)
>                       goto out_of_memory;
>                   parse_state = 2;
>                   break;
>   
> --- 207,230 ----
>                   if (token == GUC_EQUALS)
>                       token = yylex();
>   
> !                 if (token != GUC_ID && token != GUC_STRING && 
> !             token != GUC_INTEGER && token != GUC_REAL && 
> !             token != GUC_UNQUOTED_STRING)
>                       goto parse_error;
>                   opt_value = strdup(yytext);
>                   if (opt_value == NULL)
>                       goto out_of_memory;
> +         if (token == GUC_STRING)
> +         {
> +             /* remove the beginning and ending quote/apostrophe */
> +             /* first: shift the whole shooting match down one
> +              character */
> +             memmove(opt_value,opt_value+1,strlen(opt_value)-1);
> +             /* second: null out the 2 characters we shifted */
> +                         opt_value[strlen(opt_value)-2]='\0';
> +             /* do the escape thing.  free()'s the strdup above */
> +             opt_value=GUC_scanstr(opt_value);
> +         }
>                   parse_state = 2;
>                   break;
>   
> ***************
> *** 266,272 ****
>       FreeFile(fp);
>       free(filename);
>       free_name_value_list(head);
> !     elog(elevel, CONFIG_FILENAME ":%u: syntax error", ConfigFileLineno);
>       return;
>   
>    out_of_memory:
> --- 276,283 ----
>       FreeFile(fp);
>       free(filename);
>       free_name_value_list(head);
> !     elog(elevel, CONFIG_FILENAME ":%u: syntax error, token=\"%s\"", 
> !         ConfigFileLineno,yytext);
>       return;
>   
>    out_of_memory:
> ***************
> *** 283,286 ****
> --- 294,382 ----
>   yywrap(void)
>   {
>       return 1;
> + }
> + 
> + /* ----------------
> +  *        scanstr
> +  *
> +  * if the string passed in has escaped codes, map the escape codes to actual
> +  * chars
> +  *
> +  * the string returned is malloc'd and should eventually be free'd by the
> +  * caller!
> +  * ----------------
> +  */
> + 
> + char *
> + GUC_scanstr(char *s)
> + {
> +     char       *newStr;
> +     int            len,
> +                 i,
> +                 j;
> + 
> +     if (s == NULL || s[0] == '\0')
> +     {
> +         if (s != NULL) free (s);
> +         return strdup("");
> + 
> +     }
> +     len = strlen(s);
> + 
> +     newStr = malloc(len + 1);    /* string cannot get longer */
> + 
> +     for (i = 0, j = 0; i < len; i++)
> +     {
> +         if (s[i] == '\\')
> +         {
> +             i++;
> +             switch (s[i])
> +             {
> +                 case 'b':
> +                     newStr[j] = '\b';
> +                     break;
> +                 case 'f':
> +                     newStr[j] = '\f';
> +                     break;
> +                 case 'n':
> +                     newStr[j] = '\n';
> +                     break;
> +                 case 'r':
> +                     newStr[j] = '\r';
> +                     break;
> +                 case 't':
> +                     newStr[j] = '\t';
> +                     break;
> +                 case '0':
> +                 case '1':
> +                 case '2':
> +                 case '3':
> +                 case '4':
> +                 case '5':
> +                 case '6':
> +                 case '7':
> +                     {
> +                         int            k;
> +                         long        octVal = 0;
> + 
> +                         for (k = 0;
> +                              s[i + k] >= '0' && s[i + k] <= '7' && k < 3;
> +                              k++)
> +                             octVal = (octVal << 3) + (s[i + k] - '0');
> +                         i += k - 1;
> +                         newStr[j] = ((char) octVal);
> +                     }
> +                     break;
> +                 default:
> +                     newStr[j] = s[i];
> +                     break;
> +                 }
> +             }                    /* switch */
> +         else
> +             newStr[j] = s[i];
> +         j++;
> +     }
> +     newStr[j] = '\0';
> +     free(s);
> +     return newStr;
>   }
> -- 
> Larry Rosenman                      http://www.lerctr.org/~ler
> Phone: +1 972-414-9812 (voice) Internet: ler@lerctr.org
> US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749
> 


--  Bruce Momjian                        |  http://candle.pha.pa.us pgman@candle.pha.pa.us               |  (610)
853-3000+  If your life is a hard drive,     |  830 Blythe Avenue +  Christ can be your backup.        |  Drexel Hill,
Pennsylvania19026