develooper Front page | perl.perl5.porters | Postings from November 2002

PATCH (was: Re: [perl #18180] problem with sys:syslog on solaris 8 with perl 5.8.0)

Thread Previous
From:
Joost van Baal
Date:
November 25, 2002 10:03
Subject:
PATCH (was: Re: [perl #18180] problem with sys:syslog on solaris 8 with perl 5.8.0)
Message ID:
20021125163537.GC4745@banach.uvt.nl
Hi again Slaven,

On Sat, Nov 23, 2002 at 09:02:50PM +0100, Slaven Rezic wrote:
> Joost van Baal <J.E.vanBaal@uvt.nl> writes:
> > I've stumbled into the same problem Eric Duda reported:
> > 
> >  % uname -a
> >  SunOS 5.8 Generic_108528-17 sun4u sparc SUNW,Ultra-4
> >  % perl --version
> >  This is perl, v5.8.0 built for sun4-solaris
> > <snip>
> >  % perl -e 'use Sys::Syslog qw /setlogsock/ ; setlogsock(unix);'  echo
> >  unix passed to setlogsock, but path not available at -e line 1
> > 
> > and, to answer Slaven Rezic's question:
> > 
> >  % perl -MSys::Syslog -e 'warn Sys::Syslog::_PATH_LOG()'
> >  Warning: something's wrong at -e line 1.
> > 
> > I _do_ have:
> > 
> >  % ls -l /dev/log
> >  lrwxrwxrwx  1 root other 27 Nov  8 14:59 /dev/log -> ../devices/pseudo/log=
> > @0:log
> > 
> > Any fix for this?
> > 
> 
> Sys/Syslog's Makefile.PL has the following lines:
> 
>     # 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" : "";
> 
> Is the problem with the failing tests still true on Solaris? 

I don't really know how to find this out.  However, the machine
_does_ have a /dev/log and /dev/conslog character device.

lrwxrwxrwx   1 root     other         31 Nov  8 14:59 /dev/conslog -> ../devices/pseudo/log@0:conslog
lrwxrwxrwx   1 root     other         27 Nov  8 14:59 /dev/log -> ../devices/pseudo/log@0:log
crw-rw-rw-   1 root     sys       21,  0 Nov 25 17:17 /devices/pseudo/log@0:conslog
crw-r-----   1 root     sys       21,  5 Nov  8 14:58 /devices/pseudo/log@0:log

So, -c "/dev/log" and -c "/dev/conslog" succeed, -S "/dev/log" fails.

Supplying /dev/log yields:

 stream passed to setlogsock, but /dev/log is not writable at ../ext/Sys/Syslog/syslog.t line 46

Therefore, I've used /dev/conslog in Makefile.PL (see below).

> Can you
> remove the -S test and see if it would work:
> 
>     my $_PATH_LOG = "/dev/log";

I've edited /perl-5.8.0/ext/Sys/Syslog/Makefile.PL (

 ...erl-5.8.0/ext/Sys/Syslog% diff -u Makefile.PL.dist Makefile.PL
 --- Makefile.PL.dist    2002-06-01 19:03:10.000000000 +0200
 +++ Makefile.PL 2002-11-25 08:42:27.000000000 +0100
 @@ -14,7 +14,7 @@
  # 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 = "/dev/log";
  
  WriteConstants(
      NAME => 'Sys::Syslog',

) and rerun the perl build.  The 'make test' fails now: Running

 .../cpan/build/perl-5.8.0/t% ./perl ../ext/Sys/Syslog/syslog.t

yields

 1..6
 ok 1
 unix dgram connect: Socket operation on non-socket at ../ext/Sys/Syslog/syslog.t line 51
 not ok 2 #
 unix dgram connect: Socket operation on non-socket at ../ext/Sys/Syslog/syslog.t line 52
 not ok 3 # Socket operation on non-socket
 ok 4 # Skip: assuming syslog doesn't accept inet connections
 ok 5 # Skip: assuming syslog doesn't accept inet connections
 ok 6 # Skip: assuming syslog doesn't accept inet connections

Sys::Syslog does claim to support a streams character-device /dev/log ,
I believe.  (On my GNU/Linux system, /dev/log is a unix domain socket.)
(The working of the Solaris /dev/log is described in syslogd(1M) and
log(7D) from the Solaris documentation.)

Anyway, the following three patches got the stuff going for me:

I've hacked in syslog.t, Syslog.pm and Makefile.PL (all patches were
needed)

--- syslog.t.dist       2002-06-01 19:03:10.000000000 +0200
+++ syslog.t    2002-11-25 16:51:47.951082000 +0100
@@ -47,7 +47,12 @@
 
 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";
+        }
         print defined(eval { openlog('perl', 'ndelay', 'local0') }) ? "ok 2\n" : "not ok 2 # $!\n";
         print defined(eval { syslog('info', $test_string ) }) ? "ok 3\n" : "not ok 3 # $!\n";
     }


--- Syslog.pm.dist      2002-06-01 19:03:10.000000000 +0200
+++ Syslog.pm   2002-11-25 16:52:54.210793000 +0100
@@ -199,7 +199,13 @@
     if (ref $setsock eq 'ARRAY') {
        @connectMethods = @$setsock;
     } elsif (lc($setsock) eq 'stream') {
-       $syslog_path = '/dev/log' unless($syslog_path);
+        unless ($syslog_path) {
+           if (length _PATH_LOG()) {
+              $syslog_path = _PATH_LOG();
+            } else {
+              $syslog_path = '/dev/log';
+            }
+        }
        if (!-w $syslog_path) {
            carp "stream passed to setlogsock, but $syslog_path is not writable";
            return undef;


--- Makefile.PL.dist  2002-06-01 19:03:10.000000000 +0200
+++ Makefile.PL 2002-11-25 13:21:27.776837000 +0100
@@ -14,7 +14,21 @@
 # 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") {
+        # Most unixes have a unix domain socket /dev/log.
+       $_PATH_LOG = "/dev/log";
+} elsif (-c "/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',




This works fine: running

 % perl -e 'use Sys::Syslog qw /:DEFAULT setlogsock/ ; setlogsock(stream) ; openlog("perl", "ndelay", "local0") ; syslog("info", "foobar" ) ' ; echo

nicely prints

 <134>perl: foobar

in my /var/adm/messages.

I'm not sure wether the Syslog.pm patch is as it should be.  Should
_PATH_LOG() point to a socket always?  So, should I pass the
/dev/conslog name via another way?

Another thing: I've spent lots of wasted time before I've found  out hacking
in build/perl-5.8.0/ext/Sys/Syslog/* and running

 make
 cd ../../../t && ./perl ../ext/Sys/Syslog/syslog.t && cd -

in this directory is useless: the test inspects stuff in perl-5.8.0/lib
, not in perl-5.8.0/ext  :( .  It'd be nice if this got better
documented, or if the Sys::Syslog Makefile.PL got support for a proper
`make test' target, with the correct dependencies.  Even running `make
test' in perl-5.8.0/ failed to behave in a `least surprising' way.  I've
learned the hard way I had to manually copy stuff from
perl-5.8.0/ext/Sys/Syslog/ to perl-5.8.0/lib/Sys/ and
perl-5.8.0/lib/auto/Sys/Syslog/ .  But well, I guess you've heard this
before.

Anyway, it's working for me now.  Thanks a lot for maintaining Perl!

Bye,

Joost


-- 
Joost van Baal                                   http://www.uvt.nl/
                                                 Tilburg University
j.e.vanbaal@uvt.nl                                  The Netherlands



Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About