Syslog.pm and missing _PATH_LOG
authorUlrich Pfeifer <upf@de.uu.net>
Fri, 5 Sep 1997 00:00:00 +0000 (00:00 +0000)
committerTim Bunce <Tim.Bunce@ig.co.uk>
Fri, 5 Sep 1997 00:00:00 +0000 (00:00 +0000)
I just ran into a problem with Syslog.pm. I tried to install some
modules which did call Sys::Syslog::setlogsock('unix'). The following
connect fails because my syslog.ph does not define _PATH_LOG (This is
SunOS 5.5.1).

The easiest way to handle this would be to make setlogsock('unix') a
NOOP if _PATH_LOG is not defined. I am not advocating to ignore it
silently. But can we make setlogsock return a value indicating that
the operation did or did not work? It seems a little cleaner that to
force users to check for _PATH_LOG themselves?

p5p-msgid: p5iuw1cris.fsf@knowway.de.uu.net

lib/Sys/Syslog.pm

index f6d9c35..2790e48 100644 (file)
@@ -59,10 +59,11 @@ Sets log mask I<$mask_priority> and returns the old mask.
 Sets the socket type to be used for the next call to
 C<openlog()> or C<syslog()>.
  
-A value of 'unix' will connect to the UNIX domain socket returned
-by C<_PATH_LOG> in F<syslog.ph>.  A value of 'inet' will connect
-to an INET socket returned by getservbyname().
-Any other value croaks.
+A value of 'unix' will connect to the UNIX domain socket returned by
+C<_PATH_LOG> in F<syslog.ph>. If F<syslog.ph> fails to define
+C<_PATH_LOG>, C<setlogsock> returns C<undef>; otherwise a true value is
+returned. A value of 'inet' will connect to an INET socket returned by
+getservbyname().  Any other value croaks.
 
 The default is for the INET socket to be used.
 
@@ -135,12 +136,18 @@ sub setlogmask {
 sub setlogsock {
     local($setsock) = shift;
     if (lc($setsock) eq 'unix') {
+        if (defined &_PATH_LOG) {
+            $sock_unix = 1;
+        } else {
+            return;
+        }
         $sock_unix = 1;
     } elsif (lc($setsock) eq 'inet') {
         undef($sock_unix);
     } else {
         croak "Invalid argument passed to setlogsock; must be 'unix' or 'inet'";
     }
+    return 1;
 }
 
 sub syslog {