PATCH (was: Re: [perl #18180] problem with sys:syslog on solaris 8 with perl 5.8.0)
authorJoost van Baal <J.E.vanBaal@uvt.nl>
Mon, 25 Nov 2002 17:35:37 +0000 (18:35 +0100)
committerJarkko Hietaniemi <jhi@iki.fi>
Sun, 6 Apr 2003 18:14:44 +0000 (18:14 +0000)
Message-ID: <20021125163537.GC4745@banach.uvt.nl>

(The .pm patch modified a bit, and removed the false
 claim that _PATH_INFO would be coming from syslog.ph)

p4raw-id: //depot/perl@19151

ext/Sys/Syslog/Makefile.PL
ext/Sys/Syslog/Syslog.pm
ext/Sys/Syslog/syslog.t

index 5a5da6f..3315db2 100644 (file)
@@ -9,12 +9,20 @@ WriteMakefile(
     realclean => {FILES=> 'const-c.inc const-xs.inc'},
 );
 
-# We hope syslogd understands /dev/log.
-#
-# Solaris has a -c /dev/log, but the syslog.t #1 and #2 don't
-# seem to be happy if that's _PATH_LOG.
-#
-my $_PATH_LOG = -S "/dev/log" ? "/dev/log" : "";
+my $_PATH_LOG;
+
+if (-S "/dev/log" && -w "/dev/log") {
+        # Most unixes have a unix domain socket /dev/log.
+       $_PATH_LOG = "/dev/log";
+} elsif (-c "/dev/conslog" && -w "/dev/conslog") {
+        # SunOS 5.8 has a worldwritable /dev/conslog STREAMS log driver.
+        # The /dev/log STREAMS log driver on this platform has permissions
+        # and ownership `crw-r----- root sys'.  /dev/conslog has more liberal
+        # permissions.
+       $_PATH_LOG = "/dev/conslog";
+} else {
+       $_PATH_LOG = "";
+}
 
 WriteConstants(
     NAME => 'Sys::Syslog',
index e255067..0f3c7ba 100644 (file)
@@ -75,14 +75,16 @@ Sets the socket type to be used for the next call to
 C<openlog()> or C<syslog()> and returns TRUE on success,
 undef on failure.
 
-A value of 'unix' will connect to the UNIX domain socket returned by
-the C<_PATH_LOG> macro (if your system defines it) in F<syslog.ph>.  A
-value of 'stream' will connect to the stream indicated by the pathname
-provided as the optional second parameter.  A value of 'inet' will
-connect to an INET socket (either tcp or udp, tried in that order)
-returned by getservbyname(). 'tcp' and 'udp' can also be given as
-values. The value 'console' will send messages directly to the
-console, as for the 'cons' option in the logopts in openlog().
+A value of 'unix' will connect to the UNIX domain socket (in some
+systems a character special device) returned by the C<_PATH_LOG> macro
+(if your system defines it), or F</dev/log> or F</dev/conslog>,
+whatever is writable.  A value of 'stream' will connect to the stream
+indicated by the pathname provided as the optional second parameter.
+A value of 'inet' will connect to an INET socket (either tcp or udp,
+tried in that order) returned by getservbyname(). 'tcp' and 'udp' can
+also be given as values. The value 'console' will send messages
+directly to the console, as for the 'cons' option in the logopts in
+openlog().
 
 A reference to an array can also be passed as the first parameter.
 When this calling method is used, the array should contain a list of
@@ -190,7 +192,19 @@ sub setlogsock {
     if (ref $setsock eq 'ARRAY') {
        @connectMethods = @$setsock;
     } elsif (lc($setsock) eq 'stream') {
-       $syslog_path = '/dev/log' unless($syslog_path);
+       unless (defined $syslog_path) {
+           my @try = qw(/dev/log /dev/conslog);
+           if (length &_PATH_LOG) {
+               unshift @try, &_PATH_LOG;
+            }
+           for my $try (@try) {
+               if (-w $try) {
+                   $syslog_path = $try;
+                   last;
+               }
+           }
+           carp "stream passed to setlogsock, but could not find any device";
+        }
        if (!-w $syslog_path) {
            carp "stream passed to setlogsock, but $syslog_path is not writable";
            return undef;
index 72171f5..9caecb4 100755 (executable)
@@ -47,8 +47,12 @@ print "1..6\n";
 
 if (Sys::Syslog::_PATH_LOG()) {
     if (-e Sys::Syslog::_PATH_LOG()) {
-        print defined(eval { setlogsock('unix') })
-               ? "ok 1\n" : "not ok 1 # $!\n";
+        if ($^O =~ /^solaris$/) {
+            # we should check for stream support here, not for solaris
+            print defined(eval { setlogsock('stream') }) ? "ok 1\n" : "not ok 1 # $!\n";
+        } else { 
+            print defined(eval { setlogsock('unix') }) ? "ok 1\n" : "not ok 1 # $!\n";
+        }
         if (defined(eval { openlog('perl', 'ndelay', 'local0') })) {
            print "ok 2\n";
            print defined(eval { syslog('info', $test_string ) })