diff options
author | Simon Bertrang <simon@cvs.openbsd.org> | 2009-05-13 15:20:00 +0000 |
---|---|---|
committer | Simon Bertrang <simon@cvs.openbsd.org> | 2009-05-13 15:20:00 +0000 |
commit | 28486a36f90ba34eb4cb268361dec8c334650406 (patch) | |
tree | a847d2390f9d88a3316981755c5cca7376d8c398 | |
parent | 42bad70dad931800499736beae519d7793c3de45 (diff) |
update Sys::Syslog to CPAN version 0.27
testing by sthen@ and jasper@, thanks!
ok millert@, jasper@
-rw-r--r-- | gnu/usr.bin/perl/MANIFEST | 3 | ||||
-rw-r--r-- | gnu/usr.bin/perl/ext/Sys/Syslog/Changes | 159 | ||||
-rw-r--r-- | gnu/usr.bin/perl/ext/Sys/Syslog/Makefile.PL | 196 | ||||
-rw-r--r-- | gnu/usr.bin/perl/ext/Sys/Syslog/README | 31 | ||||
-rw-r--r-- | gnu/usr.bin/perl/ext/Sys/Syslog/Syslog.pm | 183 | ||||
-rw-r--r-- | gnu/usr.bin/perl/ext/Sys/Syslog/Syslog.xs | 629 | ||||
-rw-r--r-- | gnu/usr.bin/perl/ext/Sys/Syslog/eg/syslog.pl | 12 | ||||
-rw-r--r-- | gnu/usr.bin/perl/ext/Sys/Syslog/fallback/syslog.h | 111 | ||||
-rwxr-xr-x | gnu/usr.bin/perl/ext/Sys/Syslog/t/00-load.t | 11 | ||||
-rw-r--r-- | gnu/usr.bin/perl/ext/Sys/Syslog/t/portfs.t | 9 | ||||
-rw-r--r-- | gnu/usr.bin/perl/ext/Sys/Syslog/t/syslog.t | 323 |
11 files changed, 946 insertions, 721 deletions
diff --git a/gnu/usr.bin/perl/MANIFEST b/gnu/usr.bin/perl/MANIFEST index 26a68987bc3..b62491d512c 100644 --- a/gnu/usr.bin/perl/MANIFEST +++ b/gnu/usr.bin/perl/MANIFEST @@ -1080,8 +1080,10 @@ ext/Sys/Hostname/Hostname.xs Sys::Hostname extension external subroutines ext/Sys/Hostname/Makefile.PL Sys::Hostname extension makefile writer ext/Sys/Hostname/t/Hostname.t See if Sys::Hostname works ext/Sys/Syslog/Changes Changlog for Sys::Syslog +ext/Sys/Syslog/eg/syslog.pl Example for Sys::Syslog usage ext/Sys/Syslog/fallback/const-c.inc Sys::Syslog constants fallback file ext/Sys/Syslog/fallback/const-xs.inc Sys::Syslog constants fallback file +ext/Sys/Syslog/fallback/syslog.h Sys::Syslog constants fallback file ext/Sys/Syslog/Makefile.PL Sys::Syslog extension makefile writer ext/Sys/Syslog/README README for Sys::Syslog ext/Sys/Syslog/README.win32 README for Sys::Syslog on Windows @@ -1089,6 +1091,7 @@ ext/Sys/Syslog/Syslog.pm Sys::Syslog extension Perl module ext/Sys/Syslog/Syslog.xs Sys::Syslog extension external subroutines ext/Sys/Syslog/t/00-load.t test for Sys::Syslog ext/Sys/Syslog/t/constants.t test for Sys::Syslog +ext/Sys/Syslog/t/portfs.t test for Sys::Syslog ext/Sys/Syslog/t/syslog.t See if Sys::Syslog works ext/Sys/Syslog/win32/compile.pl Sys::Syslog extension Win32 related file ext/Sys/Syslog/win32/PerlLog_dll.uu Sys::Syslog extension Win32 related file diff --git a/gnu/usr.bin/perl/ext/Sys/Syslog/Changes b/gnu/usr.bin/perl/ext/Sys/Syslog/Changes index 0a0e15e1478..2f6653baa83 100644 --- a/gnu/usr.bin/perl/ext/Sys/Syslog/Changes +++ b/gnu/usr.bin/perl/ext/Sys/Syslog/Changes @@ -1,45 +1,172 @@ Revision history for Sys-Syslog -0.13 2006.01.11 +0.27 -- 2008.09.21 -- Sebastien Aperghis-Tramoni (SAPER) + [BUGFIX] Fixed compilation on Win32, thanks to Serguei Trouchelle. + Also added stubs so calling the XS functions will never fail. + [TESTS] t/pod.t now also uses Pod::Checker. + +0.26 -- 2008.06.16 -- Sebastien Aperghis-Tramoni (SAPER) + [BUGFIX] Make Sys::Syslog works with Perl 5.10.0 (because of + ExtUtils::Constant::ProxySubs). + [CODE] setlogsock() is now a little more strict about its arguments. + +0.25 -- 2008.05.17 -- Sebastien Aperghis-Tramoni (SAPER) + [BUGFIX] CPAN-RT#34691: Fixed an incorrect call to sysopen() which + prevented Sys::Syslog from working on some Solaris systems. + Thanks to Paul Townsend. + [BUGFIX] CPAN-RT#34753: Fixed a slowness introduced in v0.19 (which + was to work around OSX syslog own slowness). Thanks to Alex Efros. + [BUGFIX] CPAN-RT#35952: Fixed a bug with the "nofatal" option. + [BUGFIX] CPAN-RT#35189: Fixed a bug in xlate(). + [BUGFIX] Fixed build on Win32, thanks to Adam Kennedy. + [FEATURE] setlogsock() now interprets the second argument as the + hostname for network mechanisms. + [DIST] Add AUTHOR to WriteMakefile() in order to fix the META.yml + generated by ExtUtils::MakeMaker. + [TESTS] Improved t/pod.t with Pod::Checker. + +0.24 -- 2007.12.31 -- Sebastien Aperghis-Tramoni (SAPER) + [BUGFIX] CPANT-RT#32001: Skip the setlogsock('stream') tests when + /dev/log is unavailable (Brendan O'Dea). + +0.23 -- 2007.11.12 -- Sebastien Aperghis-Tramoni (SAPER) + [BUGFIX] Fixed a too liberal test in the "pipe" mechanism, thanks + to Jan Dubois. + [DIST] fallback/syslog.h was missing from MANIFEST (thanks to CPAN + Tester Matthew Musgrove). + [TESTS] Better handling of Perl 5.005, thanks to CPAN Tester Slaven Rezic. + +0.22 -- 2007.11.08 -- Sebastien Aperghis-Tramoni (SAPER) + [BUGFIX] CPAN-RT#29875: Added workaround SpamAssassin overzealous + logging features. + [FEATURE] Added support for PERROR option. + [FEATURE] Support for SYSLOG on z/OS, thanks to Chun Bing Ge. + [CODE] Prevent $@ from being visible outside the module, in trying + to address the problem reported in CPAN-RT#29875. + [DOC] CPAN-RT#29451: Add Copyright notice. Thanks to Allison Randal + for her advice. + [DOC] New speaking about Win32 API instead of Win32 operating system. + +0.21 -- 2007.09.14 -- Sebastien Aperghis-Tramoni (SAPER) + [BUGFIX] setlogsock(eventlog) returned true even when it shouldn't have. + [BUGFIX] CPAN-RT#24431: Added workaround for Mac OS X syslogd. + [FEATURE] Added "pipe" mechanism in order to support HP-UX named pipe. + Thanks to H.Merijn Brand and PROCURA. + [CODE] Sys::Syslog works again on Perl 5.005, thanks to Nicholas Clark. + +0.20 -- 2007.09.05 -- Sebastien Aperghis-Tramoni (SAPER) + [DOC] Added README.win32 which was missing in MANIFEST. + +0.19 -- 2007.09.05 -- Sebastien Aperghis-Tramoni (SAPER) + [BUGFIX] CPAN-RT#20635: Fix tests to avoid problems related to the + "stream" mechanism which occured on Debian and Cygwin. + [BUGFIX] CPAN-RT#20780: Facility could not be temporarily changed. + Also fixes the syslog() before openlog() bug. + [BUGFIX] CPAN-RT#21333: Makefile.PL now creates a typemap for Perl 5.6.1 + [BUGFIX] CPAN-RT#21516: disconnect_log() now correctly calls closelog_xs(). + [BUGFIX] CPAN-RT#21866: Silence warnings in openlog(). + [BUGFIX] CPAN-RT#25488: Silence warnings in disconnect_log(). + via syslog(). + [BUGFIX] Rewrote the constants generation code in order to provide + fallback value for non-standard macros. + [BUGFIX] Mark Blackman and Edmund von der Burg identified and fixed the + random failures appearing on OSX, caused by a UDP timeout. + [FEATURE] Added Win32 event log support thanks to Yves Orton. + [FEATURE] Added new macros from modern BSD and IRIX. + [FEATURE] Each non-standard macro now fall backs to a standard macro. + [CODE] Merged changes from Jerry D. Hedden to use ppport.h only when not + built from core distribution (blead@30657). + [TESTS] t/syslog.t now generates a more detailled TAP output. + [TESTS] Merged change blead@29176: suppress taint mode from t/constants.t + [TESTS] Added regression tests for CPAN-RT#21866 and #25488. + [EG] Added example script eg/syslog.pl + [DOC] CPAN-RT#26097: man pages were not installed. + [DOC] Added the Sys::Syslog Rules. + +0.18 -- 2006.08.28 -- Sebastien Aperghis-Tramoni (SAPER) + [BUGFIX] Rewrote the way the default identifiant is constructed. + [TESTS] CPAN-RT#20946: Removed the console mechanism from the main + test loop because writing to the console hangs on several systems. + [DOC] Added a note discouraging the use of setlogsock(). + +0.17 -- 2006.07.23 -- Sebastien Aperghis-Tramoni (SAPER) + [BUGFIX] CPAN-RT#20622, #20164: Fixed path handling in connect_unix(). + [CODE] Renamed some variables ($that is not a valid name), and removed + some dead code. + [CODE] Actually added the macros from Mac OS X that were announced in + the 0.14 version. + [DOC] CPAN-RT#20545: Rewrote the documentation about setlogsock(). + +0.16 -- 2006.06.20 -- Sebastien Aperghis-Tramoni (SAPER) + [BUGFIX] Perl-RT#20557: Save errno before trying to connect. + [FEATURE] Perl-RT#35406: Applied the patch proposed by Keisuke Hirata + for a more lax handling of "stream" or "unix" path. + [FEATURE] Now try the "native" mechanism first. + [TESTS] Silence warnings generated by t/syslog.t in Perl 5.8.8 and + later. + [DOC] Added documentation about the "native" mechanism. + [DOC] Now indicates whether tickets are from CPAN or Perl RT. + +0.15 -- 2006.06.10 -- Sebastien Aperghis-Tramoni (SAPER) + [FEATURE] CPAN-RT#17316: Added a "nofatal" option to openlog(). + [FEATURE] Sys::Syslog warnings can now be controled by the warnings + category of the same name. + [FEATURE] Added support for using the native C syslog(3) functions. + [CODE] Removed most "our" variables. + [CODE] Improved readability by removing cargo-cult brackets and + parentheses. + +0.14 -- 2006.05.25 -- Sebastien Aperghis-Tramoni (SAPER) + [BUGFIX] CPAN-RT#19259, #17518: Now allowing all levels and facilities. + [CODE] Removed useless "&". + [CODE] Improved readability by adding empty lines and reworking the + code here and there. + [CODE] Added new macros from Mac OS X. + [TESTS] Added more tests in order to increase coverage. + [DOC] CPAN-RT#19085: Corrected errors in the documentation for setlogmask(). + [DOC] Added several links to online manual pages, RFCs and articles. + [DOC] Corrected minor things in Changes. + +0.13 -- 2006.01.11 -- Sebastien Aperghis-Tramoni (SAPER) + [CODE] Applied Gisle Aas patch for a better handling of error messages, + then optimized it. [CODE] Merged blead@26768: If getservbyname fails tell what service the lookup attempt tried to use. [CODE] Merged blead@26769: suppress Sys::Hostname usage and directly use INADDR_LOOPBACK. [CODE] Merged blead@26772: $host needs to stay in case the user sets it. [CODE] Merged blead@26773: check that $syslog_path is a socket. - [TESTS] RT#16980 (Alan Burlison): Sys::Syslog blows up rather - spectacularly on Solaris. Corrected by previous patches. - [TESTS] Applied Gisle Aas patch for a better handling of error messages, - then optimized it. - [TESTS] RT#16974: Failed test in t/podspell. This test is now skipped. + [TESTS] CPAN-RT#16980: Sys::Syslog blows up rather spectacularly on + Solaris. Corrected by previous patches. + [TESTS] CPAN-RT#16974: Failed test in t/podspell. This test is now skipped. -0.12 2006.01.07 - [CODE] Merged some modifications from bleadperl. +0.12 -- 2006.01.07 -- Sebastien Aperghis-Tramoni (SAPER) [DOC] Added a link to an article about Sys::Syslog. + [TESTS] Merged some modifications from bleadperl. [TESTS] Removed optional dependency on Test::Exception. [TESTS] Improved t/constant.t [TESTS] Rewrote t/constants.t because future versions of ExtUtils::Constant will prevent the constant() function from being directly called. -0.11 2005.12.28 +0.11 -- 2005.12.28 -- Sebastien Aperghis-Tramoni (SAPER) [BUGFIX] setlogmask() now behaves like its C counterpart. - [CODE] Can now export and use the macros. - [CODE] Support for three Exporter tags. - [CODE] XSLoader is now optional. + [FEATURE] Can now export and use the macros. + [FEATURE] Support for three Exporter tags. + [FEATURE] XSLoader is now optional. [CODE] No longer "use"s Sys::Hostname as it was "require"d where needed. - [CODE] RT#16604: Use local timestamp. - [DIST] Merged change from blead@26343 + [CODE] CPAN-RT#16604: Use local timestamp. + [DIST] Merged blead@26343: Fix realclean target. [DOC] Improved documentation. [TESTS] Added more tests to t/syslog.t in order to increase code coverage. -0.10 2005.12.08 +0.10 -- 2005.12.08 -- Sebastien Aperghis-Tramoni (SAPER) [DOC] Improved documentation. [TESTS] Added -T to t/syslog.t [TESTS] Added t/constants.t to check the macros. [TESTS] Added t/distchk.t, t/podspell.t, t/podcover.t, t/portfs.t -0.09 2005.12.06 +0.09 -- 2005.12.06 -- Sebastien Aperghis-Tramoni (SAPER) [CODE] Now setlogsock() really croak(), as documented. [DIST] CPANized from blead@26281. [DIST] Modified Makefile.PL so that ExtUtils::Constant is conditionaly diff --git a/gnu/usr.bin/perl/ext/Sys/Syslog/Makefile.PL b/gnu/usr.bin/perl/ext/Sys/Syslog/Makefile.PL index e5edf3e1ba7..790853ce8ad 100644 --- a/gnu/usr.bin/perl/ext/Sys/Syslog/Makefile.PL +++ b/gnu/usr.bin/perl/ext/Sys/Syslog/Makefile.PL @@ -1,8 +1,196 @@ +use strict; +use Config; use ExtUtils::MakeMaker; +eval 'use ExtUtils::MakeMaker::Coverage'; +use File::Copy; +use File::Path; +use File::Spec; +require 5.005; + + +# create a typemap for Perl 5.6 +if ($] < 5.008) { + open(TYPEMAP, ">typemap") or die "fatal: can't write typemap: $!"; + print TYPEMAP "const char *\t\tT_PV\n"; + close(TYPEMAP); +} + +# create a lib/ dir in order to avoid warnings in Test::Distribution +mkdir "lib", 0755; + +# virtual paths given to EU::MM +my %virtual_path = ( 'Syslog.pm' => '$(INST_LIBDIR)/Syslog.pm' ); + +# detect when to use Win32::EvenLog +my (@extra_params, @extra_prereqs); +my $use_eventlog = eval "use Win32::EventLog; 1"; + +if ($use_eventlog) { + print " * Win32::EventLog detected.\n"; + my $name = "PerlLog"; + + push @extra_prereqs, + Win32 => 0, "Win32::TieRegistry" => 0, "Win32::EventLog" => 0; + + $virtual_path{'win32/Win32.pm' } = '$(INST_LIBDIR)/Syslog/Win32.pm'; + $virtual_path{'win32/PerlLog.dll'} = '$(INST_ARCHAUTODIR)/PerlLog.dll'; + + push @extra_params, CCFLAGS => "-Ifallback"; + + # recreate the DLL from its uuencoded form if it's not here + if (! -f File::Spec->catfile("win32", "$name.dll")) { + # read the uuencoded data + open(UU, '<' . File::Spec->catfile("win32", "$name\_dll.uu")) + or die "fatal: Can't read file '$name\_dll.uu': $!"; + my $uudata = do { local $/; <UU> }; + close(UU); + + # write the DLL + open(DLL, '>' . File::Spec->catfile("win32", "$name.dll")) + or die "fatal: Can't write DLL '$name.dll': $!"; + binmode(DLL); + print DLL unpack "u", $uudata; + close(DLL); + } +} +elsif ($^O =~ /Win32/) { + print <<"NOTICE" + *** You're running on a Win32 system, but you lack the Win32::EventLog\a + *** module, part of the libwin32 distribution. Although Sys::Syslog can + *** be used without Win32::EventLog, it won't be very useful except for + *** sending remote syslog messages. If you want to log messages on the + *** local host as well, please install libwin32 then Sys::Syslog again. +NOTICE +} + +# detect when being built in Perl core +if (grep { $_ eq 'PERL_CORE=1' } @ARGV) { + push @extra_params, + MAN3PODS => {}; # Pods will be built by installman. +} +else { + push @extra_params, + DEFINE => '-DUSE_PPPORT_H'; +} + +# on pre-5.6 Perls, add warnings::compat to the prereq modules +push @extra_prereqs, "warnings::compat" => "0.06" if $] < 5.006; WriteMakefile( - NAME => 'Sys::Syslog', - VERSION_FROM => 'Syslog.pm', - MAN3PODS => {}, # Pods will be built by installman. - XSPROTOARG => '-noprototypes', + NAME => 'Sys::Syslog', + LICENSE => 'perl', + AUTHOR => 'Sebastien Aperghis-Tramoni <sebastien@aperghis.net>', + VERSION_FROM => 'Syslog.pm', + ABSTRACT_FROM => 'Syslog.pm', + INSTALLDIRS => 'perl', + XSPROTOARG => '-noprototypes', + PM => \%virtual_path, + PREREQ_PM => { + # run prereqs + 'Carp' => 0, + 'Fcntl' => 0, + 'File::Basename' => 0, + 'File::Spec' => 0, + 'POSIX' => 0, + 'Socket' => 0, + 'XSLoader' => 0, + @extra_prereqs, + + # build/test prereqs + 'Test::More' => 0, + }, + PL_FILES => {}, + dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', }, + clean => { FILES => 'Sys-Syslog-*' }, + realclean => { FILES => 'lib const-c.inc const-xs.inc macros.all ' + .'PerlLog.h typemap *.bak *.bin *.rc win32/PerlLog_dll' }, + @extra_params ); + + +# find a default value for _PATH_LOG +my $_PATH_LOG; + +if (-c "/dev/conslog" and -w _) { + # 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"; +} +elsif (-S "/var/run/syslog" and -w _) { + # Mac OS X puts it at a different path. + $_PATH_LOG = "/var/run/syslog"; +} +elsif (-p "/dev/log" and -w _) { + # On HP-UX, /dev/log isn't a unix domain socket but a named pipe. + $_PATH_LOG = "/dev/log"; +} +elsif ((-S "/dev/log" or -c _) and -w _) { + # Most unixes have a unix domain socket /dev/log. + $_PATH_LOG = "/dev/log"; +} +else { + $_PATH_LOG = ""; +} + + +# if possible, generate the code that handles the constants with +# ExtUtils::Constant, otherwise use cached copy in fallback/ +if(eval {require ExtUtils::Constant; 1}) { + my @levels = qw( + LOG_ALERT LOG_CRIT LOG_DEBUG LOG_EMERG LOG_ERR + LOG_INFO LOG_NOTICE LOG_WARNING + ); + + my @facilities = ( + # standard facilities + qw( + LOG_AUTH LOG_AUTHPRIV LOG_CRON LOG_DAEMON LOG_FTP LOG_KERN + LOG_LOCAL0 LOG_LOCAL1 LOG_LOCAL2 LOG_LOCAL3 LOG_LOCAL4 + LOG_LOCAL5 LOG_LOCAL6 LOG_LOCAL7 LOG_LPR LOG_MAIL LOG_NEWS + LOG_SYSLOG LOG_USER LOG_UUCP + ), + # Mac OS X specific facilities + { name => "LOG_INSTALL", type => "IV", default => [ "IV", "LOG_USER" ] }, + { name => "LOG_LAUNCHD", type => "IV", default => [ "IV", "LOG_DAEMON"] }, + { name => "LOG_NETINFO", type => "IV", default => [ "IV", "LOG_DAEMON"] }, + { name => "LOG_RAS", type => "IV", default => [ "IV", "LOG_AUTH" ] }, + { name => "LOG_REMOTEAUTH", type => "IV", default => [ "IV", "LOG_AUTH" ] }, + # modern BSD specific facilities + { name => "LOG_CONSOLE", type => "IV", default => [ "IV", "LOG_USER" ] }, + { name => "LOG_NTP", type => "IV", default => [ "IV", "LOG_DAEMON"] }, + { name => "LOG_SECURITY", type => "IV", default => [ "IV", "LOG_AUTH" ] }, + # IRIX specific facilities + { name => "LOG_AUDIT", type => "IV", default => [ "IV", "LOG_AUTH" ] }, + { name => "LOG_LFMT", type => "IV", default => [ "IV", "LOG_USER" ] }, + ); + + my @options = qw( + LOG_CONS LOG_PID LOG_NDELAY LOG_NOWAIT LOG_ODELAY LOG_PERROR + ); + + my @others_macros = ( + qw(LOG_FACMASK), + { name => "_PATH_LOG", type => "PV", default => [ "PV", qq("$_PATH_LOG") ] }, + { name => "LOG_PRIMASK", type => "IV", default => [ "IV", 7] }, + { name => "LOG_NFACILITIES", type => "IV", default => [ "IV", scalar @facilities] }, + ); + + ExtUtils::Constant::WriteConstants( + NAME => 'Sys::Syslog', + NAMES => [ @levels, @facilities, @options, @others_macros ], + ($] > 5.009002 ? (PROXYSUBS => 1) : ()), + ); + + my @names = map { ref $_ ? $_->{name} : $_ } @levels, @facilities, @options; + open(MACROS, '>macros.all') or warn "warning: Can't write 'macros.all': $!\n"; + print MACROS join $/, @names; + close(MACROS); +} +else { + foreach my $file ('const-c.inc', 'const-xs.inc') { + my $fallback = File::Spec->catfile('fallback', $file); + copy($fallback, $file) or die "fatal: Can't copy $fallback to $file: $!"; + } +} diff --git a/gnu/usr.bin/perl/ext/Sys/Syslog/README b/gnu/usr.bin/perl/ext/Sys/Syslog/README index 0d468645ee5..68bf1b69e0e 100644 --- a/gnu/usr.bin/perl/ext/Sys/Syslog/README +++ b/gnu/usr.bin/perl/ext/Sys/Syslog/README @@ -19,24 +19,18 @@ INSTALLATION $ make test $ make install - A ANSI-compliant compiler is required to compile the extension. + An ANSI-compliant compiler is required to compile the extension. - Sys::Syslog has been tested by the author on the following systems, + Sys::Syslog should work on any Perl since 5.6.0. This module has + been tested by the author on the following Perl and system versions but is likely to run on many more: - - Linux 2.6, gcc 3.4.1 - - FreeBSD 4.7, gcc 2.95.4 - - Mac OS X 10.4, gcc 4.0.1 - - Sys::Syslog should on any Perl since 5.6.0. This module has been - tested by the author to check that it works with the following - versions ot Perl: - - - Perl 5.6.2 i686-linux (custom build) - - Perl 5.8.5 i386-linux-thread-multi (vendor build) - - Perl 5.6.1 i386-freebsd (custom build) - - Perl 5.8.7 i386-freebsd (custom build) - - Perl 5.8.6 darwin-thread-multi-2level (vendor build) + Perl Architecture GCC + ----------------------------------------------------- + 5.6.2 i686-linux 3.4.1 + 5.8.5 i386-linux-thread-multi 3.4.1 + 5.8.8 i386-freebsd-64int 3.4.4 + 5.8.6 darwin-thread-multi-2level (PowerPC) 4.0.1 See also the corresponding CPAN Testers page: http://testers.cpan.org/show/Sys-Syslog.html @@ -52,7 +46,10 @@ SUPPORT AND DOCUMENTATION You can also look for information at: Search CPAN - http://search.cpan.org/dist/Sys-Syslog + http://search.cpan.org/dist/Sys-Syslog/ + + Kobes' CPAN Search + http://cpan.uwinnipeg.ca/dist/Sys-Syslog CPAN Request Tracker: http://rt.cpan.org/NoAuth/Bugs.html?Dist=Sys-Syslog @@ -66,5 +63,7 @@ SUPPORT AND DOCUMENTATION COPYRIGHT AND LICENCE + Copyright (C) 1990-2008 by Larry Wall and others. + This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. diff --git a/gnu/usr.bin/perl/ext/Sys/Syslog/Syslog.pm b/gnu/usr.bin/perl/ext/Sys/Syslog/Syslog.pm index 899f25b86b8..002e6e4f16e 100644 --- a/gnu/usr.bin/perl/ext/Sys/Syslog/Syslog.pm +++ b/gnu/usr.bin/perl/ext/Sys/Syslog/Syslog.pm @@ -1,16 +1,17 @@ package Sys::Syslog; use strict; +use warnings; use warnings::register; use Carp; +use Exporter (); use Fcntl qw(O_WRONLY); use File::Basename; use POSIX qw(strftime setlocale LC_TIME); use Socket ':all'; require 5.005; -require Exporter; { no strict 'vars'; - $VERSION = '0.22'; + $VERSION = '0.27'; @ISA = qw(Exporter); %EXPORT_TAGS = ( @@ -76,6 +77,11 @@ require Exporter; # use vars qw($host); # host to send syslog messages to (see notes at end) +# +# Prototypes +# +sub silent_eval (&); + # # Global variables # @@ -85,6 +91,7 @@ my $syslog_send; # coderef of the function used to send messages my $syslog_path = undef; # syslog path for "stream" and "unix" mechanisms my $syslog_xobj = undef; # if defined, holds the external object used to send messages my $transmit_ok = 0; # flag to indicate if the last message was transmited +my $sock_timeout = 0; # socket timeout, see below my $current_proto = undef; # current mechanism used to transmit messages my $ident = ''; # identifiant prepended to each message $facility = ''; # current facility @@ -105,15 +112,12 @@ if ($^O =~ /^(freebsd|linux)$/) { @connectMethods = grep { $_ ne 'udp' } @connectMethods; } +# And on Win32 systems, we try to use the native mechanism for this +# platform, the events logger, available through Win32::EventLog. EVENTLOG: { - # use EventLog on Win32 my $is_Win32 = $^O =~ /Win32/i; - # some applications are trying to be too smart - # yes I'm speaking of YOU, SpamAssassin, grr.. - local($SIG{__DIE__}, $SIG{__WARN__}, $@); - - if (eval "use Sys::Syslog::Win32; 1") { + if (can_load("Sys::Syslog::Win32")) { unshift @connectMethods, 'eventlog'; } elsif ($is_Win32) { @@ -124,6 +128,18 @@ EVENTLOG: { my @defaultMethods = @connectMethods; my @fallbackMethods = (); +# The timeout in connection_ok() was pushed up to 0.25 sec in +# Sys::Syslog v0.19 in order to address a heisenbug on MacOSX: +# http://london.pm.org/pipermail/london.pm/Week-of-Mon-20061211/005961.html +# +# However, this also had the effect of slowing this test for +# all other operating systems, which apparently impacted some +# users (cf. CPAN-RT #34753). So, in order to make everybody +# happy, the timeout is now zero by default on all systems +# except on OSX where it is set to 250 msec, and can be set +# with the infamous setlogsock() function. +$sock_timeout = 0.25 if $^O =~ /darwin/; + # coderef for a nicer handling of errors my $err_sub = $options{nofatal} ? \&warnings::warnif : \&croak; @@ -155,7 +171,7 @@ sub openlog { $options{$opt} = 1 if exists $options{$opt} } - $err_sub = $options{nofatal} ? \&warnings::warnif : \&croak; + $err_sub = delete $options{nofatal} ? \&warnings::warnif : \&croak; return 1 unless $options{ndelay}; connect_log(); } @@ -172,8 +188,18 @@ sub setlogmask { } sub setlogsock { - my $setsock = shift; - $syslog_path = shift; + my ($setsock, $setpath, $settime) = @_; + + # check arguments + my $diag_invalid_arg + = "Invalid argument passed to setlogsock; must be 'stream', 'pipe', " + . "'unix', 'native', 'eventlog', 'tcp', 'udp' or 'inet'"; + croak $diag_invalid_arg unless defined $setsock; + croak "Invalid number of arguments" unless @_ >= 1 and @_ <= 3; + + $syslog_path = $setpath if defined $setpath; + $sock_timeout = $settime if defined $settime; + disconnect_log() if $connected; $transmit_ok = 0; @fallbackMethods = (); @@ -221,7 +247,7 @@ sub setlogsock { } elsif (lc $setsock eq 'pipe') { for my $path ($syslog_path, &_PATH_LOG, "/dev/log") { - next unless defined $path and length $path and -w $path; + next unless defined $path and length $path and -p $path and -w _; $syslog_path = $path; last } @@ -237,7 +263,7 @@ sub setlogsock { @connectMethods = qw(native); } elsif (lc $setsock eq 'eventlog') { - if (eval "use Win32::EventLog; 1") { + if (can_load("Win32::EventLog")) { @connectMethods = qw(eventlog); } else { warnings::warnif "eventlog passed to setlogsock, but no Win32 API available"; @@ -248,6 +274,7 @@ sub setlogsock { } elsif (lc $setsock eq 'tcp') { if (getservbyname('syslog', 'tcp') || getservbyname('syslogng', 'tcp')) { @connectMethods = qw(tcp); + $host = $syslog_path; } else { warnings::warnif "tcp passed to setlogsock, but tcp service unavailable"; return undef; @@ -256,6 +283,7 @@ sub setlogsock { } elsif (lc $setsock eq 'udp') { if (getservbyname('syslog', 'udp')) { @connectMethods = qw(udp); + $host = $syslog_path; } else { warnings::warnif "udp passed to setlogsock, but udp service unavailable"; return undef; @@ -268,8 +296,7 @@ sub setlogsock { @connectMethods = qw(console); } else { - croak "Invalid argument passed to setlogsock; must be 'stream', 'pipe', ", - "'unix', 'native', 'eventlog', 'tcp', 'udp' or 'inet'" + croak $diag_invalid_arg } return 1; @@ -293,25 +320,29 @@ sub syslog { croak "syslog: expecting argument \$priority" unless defined $priority; croak "syslog: expecting argument \$format" unless defined $mask; + croak "syslog: invalid level/facility: $priority" if $priority =~ /^-\d+$/; @words = split(/\W+/, $priority, 2); # Allow "level" or "level|facility". undef $numpri; undef $numfac; - foreach (@words) { - $num = xlate($_); # Translate word to number. - if ($num < 0) { - croak "syslog: invalid level/facility: $_" - } - elsif ($num <= &LOG_PRIMASK) { - croak "syslog: too many levels given: $_" if defined $numpri; - $numpri = $num; - return 0 unless LOG_MASK($numpri) & $maskpri; - } - else { - croak "syslog: too many facilities given: $_" if defined $numfac; - $facility = $_; - $numfac = $num; - } + for my $word (@words) { + next if length $word == 0; + + $num = xlate($word); # Translate word to number. + + if ($num < 0) { + croak "syslog: invalid level/facility: $word" + } + elsif ($num <= &LOG_PRIMASK) { + croak "syslog: too many levels given: $word" if defined $numpri; + $numpri = $num; + return 0 unless LOG_MASK($numpri) & $maskpri; + } + else { + croak "syslog: too many facilities given: $word" if defined $numfac; + $facility = $word; + $numfac = $num; + } } croak "syslog: level must be given" unless defined $numpri; @@ -464,14 +495,28 @@ sub _syslog_send_native { # private function to translate names to numeric values # sub xlate { - my($name) = @_; + my ($name) = @_; + return $name+0 if $name =~ /^\s*\d+\s*$/; $name = uc $name; $name = "LOG_$name" unless $name =~ /^LOG_/; - $name = "Sys::Syslog::$name"; - # Can't have just eval { &$name } || -1 because some LOG_XXX may be zero. - my $value = eval { no strict 'refs'; &$name }; - $@ = ""; + + # ExtUtils::Constant 0.20 introduced a new way to implement + # constants, called ProxySubs. When it was used to generate + # the C code, the constant() function no longer returns the + # correct value. Therefore, we first try a direct call to + # constant(), and if the value is an error we try to call the + # constant by its full name. + my $value = constant($name); + + if (index($value, "not a valid") >= 0) { + $name = "Sys::Syslog::$name"; + $value = eval { no strict "refs"; &$name }; + $value = $@ unless defined $value; + } + + $value = -1 if index($value, "not a valid") >= 0; + return defined $value ? $value : -1; } @@ -546,11 +591,10 @@ sub connect_tcp { } setsockopt(SYSLOG, SOL_SOCKET, SO_KEEPALIVE, 1); - if (eval { IPPROTO_TCP() }) { + if (silent_eval { IPPROTO_TCP() }) { # These constants don't exist in 5.005. They were added in 1999 setsockopt(SYSLOG, IPPROTO_TCP(), TCP_NODELAY(), 1); } - $@ = ""; if (!connect(SYSLOG, $addr)) { push @$errs, "tcp connect: $!"; return 0; @@ -619,7 +663,7 @@ sub connect_stream { push @$errs, "stream $syslog_path is not writable"; return 0; } - if (!sysopen(SYSLOG, $syslog_path, 0400, O_WRONLY)) { + if (!sysopen(SYSLOG, $syslog_path, O_WRONLY, 0400)) { push @$errs, "stream can't open $syslog_path: $!"; return 0; } @@ -697,12 +741,7 @@ sub connect_native { $logopt += xlate($opt) if $options{$opt} } - eval { openlog_xs($ident, $logopt, xlate($facility)) }; - if ($@) { - push @$errs, $@; - return 0; - } - + openlog_xs($ident, $logopt, xlate($facility)); $syslog_send = \&_syslog_send_native; return 1; @@ -741,7 +780,7 @@ sub connection_ok { my $rin = ''; vec($rin, fileno(SYSLOG), 1) = 1; - my $ret = select $rin, undef, $rin, 0.25; + my $ret = select $rin, undef, $rin, $sock_timeout; return ($ret ? 0 : 1); } @@ -761,7 +800,26 @@ sub disconnect_log { return close SYSLOG; } -1; + +# +# Wrappers around eval() that makes sure that nobody, and I say NOBODY, +# ever knows that I wanted to test if something was here or not. +# It is needed because some applications are trying to be too smart, +# do it wrong, and it ends up in EPIC FAIL. +# Yes I'm speaking of YOU, SpamAssassin. +# +sub silent_eval (&) { + local($SIG{__DIE__}, $SIG{__WARN__}, $@); + return eval { $_[0]->() } +} + +sub can_load { + local($SIG{__DIE__}, $SIG{__WARN__}, $@); + return eval "use $_[0]; 1" +} + + +"Eighth Rule: read the documentation." __END__ @@ -771,7 +829,7 @@ Sys::Syslog - Perl interface to the UNIX syslog(3) calls =head1 VERSION -Version 0.22 +Version 0.27 =head1 SYNOPSIS @@ -965,6 +1023,8 @@ Log all messages up to debug: =item B<setlogsock($sock_type, $stream_location)> (added in Perl 5.004_02) +=item B<setlogsock($sock_type, $stream_location, $sock_timeout)> (added in 0.25) + Sets the socket type to be used for the next call to C<openlog()> or C<syslog()> and returns true on success, C<undef> on failure. The available mechanisms are: @@ -984,15 +1044,18 @@ added in C<Sys::Syslog> 0.19). =item * C<"tcp"> - connect to a TCP socket, on the C<syslog/tcp> or C<syslogng/tcp> -service. +service. If defined, the second parameter is used as a hostname to connect to. =item * C<"udp"> - connect to a UDP socket, on the C<syslog/udp> service. +If defined, the second parameter is used as a hostname to connect to, +and the third parameter as the timeout used to check for UDP response. =item * -C<"inet"> - connect to an INET socket, either TCP or UDP, tried in that order. +C<"inet"> - connect to an INET socket, either TCP or UDP, tried in that +order. If defined, the second parameter is used as a hostname to connect to. =item * @@ -1026,7 +1089,8 @@ 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 mechanisms which are attempted in order. -The default is to try C<native>, C<tcp>, C<udp>, C<unix>, C<stream>, C<console>. +The default is to try C<native>, C<tcp>, C<udp>, C<unix>, C<pipe>, C<stream>, +C<console>. Under systems with the Win32 API, C<eventlog> will be added as the first mechanism to try if C<Win32::EventLog> is available. @@ -1113,8 +1177,7 @@ Example of use of C<%m>: Log to UDP port on C<$remotehost> instead of logging locally: - setlogsock('udp'); - $Sys::Syslog::host = $remotehost; + setlogsock("udp", $remotehost); openlog($program, 'ndelay', 'user'); syslog('info', 'something happened over here'); @@ -1342,16 +1405,19 @@ GNU C Library documentation on syslog, L<http://www.gnu.org/software/libc/manual/html_node/Syslog.html> Solaris 10 documentation on syslog, -L<http://docs.sun.com/app/docs/doc/816-5168/6mbb3hruo?a=view> +L<http://docs.sun.com/app/docs/doc/816-5168/syslog-3c?a=view> -IRIX 6.4 documentation on syslog, -L<http://techpubs.sgi.com/library/tpl/cgi-bin/getdoc.cgi?coll=0640&db=man&fname=3c+syslog> +Mac OS X documentation on syslog, +L<http://developer.apple.com/documentation/Darwin/Reference/ManPages/man3/syslog.3.html> + +IRIX 6.5 documentation on syslog, +L<http://techpubs.sgi.com/library/tpl/cgi-bin/getdoc.cgi?coll=0650&db=man&fname=3c+syslog> AIX 5L 5.3 documentation on syslog, L<http://publib.boulder.ibm.com/infocenter/pseries/v5r3/index.jsp?topic=/com.ibm.aix.basetechref/doc/basetrf2/syslog.htm> HP-UX 11i documentation on syslog, -L<http://docs.hp.com/en/B9106-90010/syslog.3C.html> +L<http://docs.hp.com/en/B2355-60130/syslog.3C.html> Tru64 5.1 documentation on syslog, L<http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/V51_HTML/MAN/MAN3/0193____.HTM> @@ -1455,7 +1521,7 @@ L<http://perldoc.perl.org/Sys/Syslog.html> =head1 COPYRIGHT -Copyright (C) 1990-2007 by Larry Wall and others. +Copyright (C) 1990-2008 by Larry Wall and others. =head1 LICENSE @@ -1518,6 +1584,9 @@ of a bug in Sys::Syslog back then? Links ----- +Linux Fast-STREAMS +- L<http://www.openss7.org/streams.html> + II12021: SYSLOGD HOWTO TCPIPINFO (z/OS, OS/390, MVS) - L<http://www-1.ibm.com/support/docview.wss?uid=isg1II12021> diff --git a/gnu/usr.bin/perl/ext/Sys/Syslog/Syslog.xs b/gnu/usr.bin/perl/ext/Sys/Syslog/Syslog.xs index f0573b8109a..704ed9e7780 100644 --- a/gnu/usr.bin/perl/ext/Sys/Syslog/Syslog.xs +++ b/gnu/usr.bin/perl/ext/Sys/Syslog/Syslog.xs @@ -1,560 +1,34 @@ +#if defined(_WIN32) +# include <windows.h> +#endif + #include "EXTERN.h" #include "perl.h" #include "XSUB.h" - -#ifdef I_SYSLOG -#include <syslog.h> -#endif - -static double -constant_LOG_NO(char *name, int len) -{ - switch (name[6 + 0]) { - case 'T': - if (strEQ(name + 6, "TICE")) { /* LOG_NO removed */ -#ifdef LOG_NOTICE - return LOG_NOTICE; -#else - goto not_there; -#endif - } - case 'W': - if (strEQ(name + 6, "WAIT")) { /* LOG_NO removed */ -#ifdef LOG_NOWAIT - return LOG_NOWAIT; -#else - goto not_there; -#endif - } - } - errno = EINVAL; - return 0; - -not_there: - errno = ENOENT; - return 0; -} - -static double -constant_LOG_N(char *name, int len) -{ - switch (name[5 + 0]) { - case 'D': - if (strEQ(name + 5, "DELAY")) { /* LOG_N removed */ -#ifdef LOG_NDELAY - return LOG_NDELAY; -#else - goto not_there; -#endif - } - case 'E': - if (strEQ(name + 5, "EWS")) { /* LOG_N removed */ -#ifdef LOG_NEWS - return LOG_NEWS; -#else - goto not_there; -#endif - } - case 'F': - if (strEQ(name + 5, "FACILITIES")) { /* LOG_N removed */ -#ifdef LOG_NFACILITIES - return LOG_NFACILITIES; -#else - goto not_there; -#endif - } - case 'O': - return constant_LOG_NO(name, len); - } - errno = EINVAL; - return 0; - -not_there: - errno = ENOENT; - return 0; -} - -static double -constant_LOG_P(char *name, int len) -{ - switch (name[5 + 0]) { - case 'I': - if (strEQ(name + 5, "ID")) { /* LOG_P removed */ -#ifdef LOG_PID - return LOG_PID; -#else - goto not_there; -#endif - } - case 'R': - if (strEQ(name + 5, "RIMASK")) { /* LOG_P removed */ -#ifdef LOG_PRIMASK - return LOG_PRIMASK; -#else - goto not_there; -#endif - } - } - errno = EINVAL; - return 0; - -not_there: - errno = ENOENT; - return 0; -} - -static double -constant_LOG_AU(char *name, int len) -{ - if (6 + 2 >= len ) { - errno = EINVAL; - return 0; - } - switch (name[6 + 2]) { - case '\0': - if (strEQ(name + 6, "TH")) { /* LOG_AU removed */ -#ifdef LOG_AUTH - return LOG_AUTH; -#else - goto not_there; -#endif - } - case 'P': - if (strEQ(name + 6, "THPRIV")) { /* LOG_AU removed */ -#ifdef LOG_AUTHPRIV - return LOG_AUTHPRIV; -#else - goto not_there; -#endif - } - } - errno = EINVAL; - return 0; - -not_there: - errno = ENOENT; - return 0; -} - -static double -constant_LOG_A(char *name, int len) -{ - switch (name[5 + 0]) { - case 'L': - if (strEQ(name + 5, "LERT")) { /* LOG_A removed */ -#ifdef LOG_ALERT - return LOG_ALERT; -#else - goto not_there; +#ifdef USE_PPPORT_H +# include "ppport.h" #endif - } - case 'U': - return constant_LOG_AU(name, len); - } - errno = EINVAL; - return 0; -not_there: - errno = ENOENT; - return 0; -} - -static double -constant_LOG_CR(char *name, int len) -{ - switch (name[6 + 0]) { - case 'I': - if (strEQ(name + 6, "IT")) { /* LOG_CR removed */ -#ifdef LOG_CRIT - return LOG_CRIT; -#else - goto not_there; -#endif - } - case 'O': - if (strEQ(name + 6, "ON")) { /* LOG_CR removed */ -#ifdef LOG_CRON - return LOG_CRON; -#else - goto not_there; -#endif - } - } - errno = EINVAL; - return 0; - -not_there: - errno = ENOENT; - return 0; -} - -static double -constant_LOG_C(char *name, int len) -{ - switch (name[5 + 0]) { - case 'O': - if (strEQ(name + 5, "ONS")) { /* LOG_C removed */ -#ifdef LOG_CONS - return LOG_CONS; -#else - goto not_there; -#endif - } - case 'R': - return constant_LOG_CR(name, len); - } - errno = EINVAL; - return 0; - -not_there: - errno = ENOENT; - return 0; -} - -static double -constant_LOG_D(char *name, int len) -{ - switch (name[5 + 0]) { - case 'A': - if (strEQ(name + 5, "AEMON")) { /* LOG_D removed */ -#ifdef LOG_DAEMON - return LOG_DAEMON; -#else - goto not_there; -#endif - } - case 'E': - if (strEQ(name + 5, "EBUG")) { /* LOG_D removed */ -#ifdef LOG_DEBUG - return LOG_DEBUG; -#else - goto not_there; -#endif - } - } - errno = EINVAL; - return 0; - -not_there: - errno = ENOENT; - return 0; -} - -static double -constant_LOG_U(char *name, int len) -{ - switch (name[5 + 0]) { - case 'S': - if (strEQ(name + 5, "SER")) { /* LOG_U removed */ -#ifdef LOG_USER - return LOG_USER; -#else - goto not_there; -#endif - } - case 'U': - if (strEQ(name + 5, "UCP")) { /* LOG_U removed */ -#ifdef LOG_UUCP - return LOG_UUCP; -#else - goto not_there; +#ifndef HAVE_SYSLOG +#define HAVE_SYSLOG 1 #endif - } - } - errno = EINVAL; - return 0; -not_there: - errno = ENOENT; - return 0; -} - -static double -constant_LOG_E(char *name, int len) -{ - switch (name[5 + 0]) { - case 'M': - if (strEQ(name + 5, "MERG")) { /* LOG_E removed */ -#ifdef LOG_EMERG - return LOG_EMERG; -#else - goto not_there; -#endif - } - case 'R': - if (strEQ(name + 5, "RR")) { /* LOG_E removed */ -#ifdef LOG_ERR - return LOG_ERR; +#if defined(_WIN32) && !defined(__CYGWIN__) +# undef HAVE_SYSLOG +# include "fallback/syslog.h" #else - goto not_there; +# if defined(I_SYSLOG) || PATCHLEVEL < 6 +# include <syslog.h> +# endif #endif - } - } - errno = EINVAL; - return 0; - -not_there: - errno = ENOENT; - return 0; -} -static double -constant_LOG_F(char *name, int len) -{ - switch (name[5 + 0]) { - case 'A': - if (strEQ(name + 5, "ACMASK")) { /* LOG_F removed */ -#ifdef LOG_FACMASK - return LOG_FACMASK; -#else - goto not_there; -#endif - } - case 'T': - if (strEQ(name + 5, "TP")) { /* LOG_F removed */ -#ifdef LOG_FTP - return LOG_FTP; -#else - goto not_there; -#endif - } - } - errno = EINVAL; - return 0; - -not_there: - errno = ENOENT; - return 0; -} - -static double -constant_LOG_LO(char *name, int len) -{ - if (6 + 3 >= len ) { - errno = EINVAL; - return 0; - } - switch (name[6 + 3]) { - case '0': - if (strEQ(name + 6, "CAL0")) { /* LOG_LO removed */ -#ifdef LOG_LOCAL0 - return LOG_LOCAL0; -#else - goto not_there; -#endif - } - case '1': - if (strEQ(name + 6, "CAL1")) { /* LOG_LO removed */ -#ifdef LOG_LOCAL1 - return LOG_LOCAL1; -#else - goto not_there; -#endif - } - case '2': - if (strEQ(name + 6, "CAL2")) { /* LOG_LO removed */ -#ifdef LOG_LOCAL2 - return LOG_LOCAL2; -#else - goto not_there; -#endif - } - case '3': - if (strEQ(name + 6, "CAL3")) { /* LOG_LO removed */ -#ifdef LOG_LOCAL3 - return LOG_LOCAL3; -#else - goto not_there; -#endif - } - case '4': - if (strEQ(name + 6, "CAL4")) { /* LOG_LO removed */ -#ifdef LOG_LOCAL4 - return LOG_LOCAL4; -#else - goto not_there; -#endif - } - case '5': - if (strEQ(name + 6, "CAL5")) { /* LOG_LO removed */ -#ifdef LOG_LOCAL5 - return LOG_LOCAL5; -#else - goto not_there; -#endif - } - case '6': - if (strEQ(name + 6, "CAL6")) { /* LOG_LO removed */ -#ifdef LOG_LOCAL6 - return LOG_LOCAL6; -#else - goto not_there; -#endif - } - case '7': - if (strEQ(name + 6, "CAL7")) { /* LOG_LO removed */ -#ifdef LOG_LOCAL7 - return LOG_LOCAL7; -#else - goto not_there; -#endif - } - } - errno = EINVAL; - return 0; - -not_there: - errno = ENOENT; - return 0; -} - -static double -constant_LOG_L(char *name, int len) -{ - switch (name[5 + 0]) { - case 'F': - if (strEQ(name + 5, "FMT")) { /* LOG_L removed */ -#ifdef LOG_LFMT - return LOG_LFMT; -#else - goto not_there; -#endif - } - case 'O': - return constant_LOG_LO(name, len); - case 'P': - if (strEQ(name + 5, "PR")) { /* LOG_L removed */ -#ifdef LOG_LPR - return LOG_LPR; -#else - goto not_there; -#endif - } - } - errno = EINVAL; - return 0; - -not_there: - errno = ENOENT; - return 0; -} - -static double -constant(char *name, int len) -{ - errno = 0; - if (0 + 4 >= len ) { - errno = EINVAL; - return 0; - } - switch (name[0 + 4]) { - case 'A': - if (!strnEQ(name + 0,"LOG_", 4)) - break; - return constant_LOG_A(name, len); - case 'C': - if (!strnEQ(name + 0,"LOG_", 4)) - break; - return constant_LOG_C(name, len); - case 'D': - if (!strnEQ(name + 0,"LOG_", 4)) - break; - return constant_LOG_D(name, len); - case 'E': - if (!strnEQ(name + 0,"LOG_", 4)) - break; - return constant_LOG_E(name, len); - case 'F': - if (!strnEQ(name + 0,"LOG_", 4)) - break; - return constant_LOG_F(name, len); - case 'I': - if (strEQ(name + 0, "LOG_INFO")) { /* removed */ -#ifdef LOG_INFO - return LOG_INFO; -#else - goto not_there; -#endif - } - case 'K': - if (strEQ(name + 0, "LOG_KERN")) { /* removed */ -#ifdef LOG_KERN - return LOG_KERN; -#else - goto not_there; -#endif - } - case 'L': - if (!strnEQ(name + 0,"LOG_", 4)) - break; - return constant_LOG_L(name, len); - case 'M': - if (strEQ(name + 0, "LOG_MAIL")) { /* removed */ -#ifdef LOG_MAIL - return LOG_MAIL; -#else - goto not_there; -#endif - } - case 'N': - if (!strnEQ(name + 0,"LOG_", 4)) - break; - return constant_LOG_N(name, len); - case 'O': - if (strEQ(name + 0, "LOG_ODELAY")) { /* removed */ -#ifdef LOG_ODELAY - return LOG_ODELAY; -#else - goto not_there; -#endif - } - case 'P': - if (!strnEQ(name + 0,"LOG_", 4)) - break; - return constant_LOG_P(name, len); - case 'S': - if (strEQ(name + 0, "LOG_SYSLOG")) { /* removed */ -#ifdef LOG_SYSLOG - return LOG_SYSLOG; -#else - goto not_there; -#endif - } - case 'U': - if (!strnEQ(name + 0,"LOG_", 4)) - break; - return constant_LOG_U(name, len); - case 'W': - if (strEQ(name + 0, "LOG_WARNING")) { /* removed */ -#ifdef LOG_WARNING - return LOG_WARNING; -#else - goto not_there; -#endif - } - } - errno = EINVAL; - return 0; - -not_there: - errno = ENOENT; - return 0; -} +static SV *ident_svptr; +#include "const-c.inc" MODULE = Sys::Syslog PACKAGE = Sys::Syslog -char * -_PATH_LOG() - CODE: -#ifdef _PATH_LOG - RETVAL = _PATH_LOG; -#else - croak("Your vendor has not defined the Sys::Syslog macro _PATH_LOG"); - RETVAL = NULL; -#endif - OUTPUT: - RETVAL +INCLUDE: const-xs.inc int LOG_FAC(p) @@ -627,16 +101,71 @@ LOG_UPTO(pri) OUTPUT: RETVAL +#ifdef HAVE_SYSLOG -double -constant(sv) +void +openlog_xs(ident, option, facility) + INPUT: + SV* ident + int option + int facility PREINIT: - STRLEN len; + STRLEN len; + char* ident_pv; + CODE: + ident_svptr = newSVsv(ident); + ident_pv = SvPV(ident_svptr, len); + openlog(ident_pv, option, facility); + +void +syslog_xs(priority, message) + INPUT: + int priority + const char * message + CODE: + syslog(priority, "%s", message); + +int +setlogmask_xs(mask) INPUT: - SV * sv - char * s = SvPV(sv, len); + int mask CODE: - RETVAL = constant(s,len); + RETVAL = setlogmask(mask); OUTPUT: - RETVAL + RETVAL + +void +closelog_xs() + CODE: + closelog(); + if (SvREFCNT(ident_svptr)) + SvREFCNT_dec(ident_svptr); + +#else /* HAVE_SYSLOG */ + +void +openlog_xs(ident, option, facility) + INPUT: + SV* ident + int option + int facility + CODE: + +void +syslog_xs(priority, message) + INPUT: + int priority + const char * message + CODE: + +int +setlogmask_xs(mask) + INPUT: + int mask + CODE: + +void +closelog_xs() + CODE: +#endif /* HAVE_SYSLOG */ diff --git a/gnu/usr.bin/perl/ext/Sys/Syslog/eg/syslog.pl b/gnu/usr.bin/perl/ext/Sys/Syslog/eg/syslog.pl new file mode 100644 index 00000000000..394b6bc6048 --- /dev/null +++ b/gnu/usr.bin/perl/ext/Sys/Syslog/eg/syslog.pl @@ -0,0 +1,12 @@ +#!/usr/bin/perl +use strict; +use Sys::Syslog; + +die "usage: $0 facility/priority message\n" unless @ARGV; + +my ($facility, $priority) = split '/', shift; +my $message = join ' ', @ARGV; + +openlog($0, "ndelay,pid", $facility) or die "fatal: can't open syslog: $!\n"; +syslog($priority, "%s", $message); +closelog(); diff --git a/gnu/usr.bin/perl/ext/Sys/Syslog/fallback/syslog.h b/gnu/usr.bin/perl/ext/Sys/Syslog/fallback/syslog.h new file mode 100644 index 00000000000..ac20dabbccc --- /dev/null +++ b/gnu/usr.bin/perl/ext/Sys/Syslog/fallback/syslog.h @@ -0,0 +1,111 @@ +/* + * Copyright (c) 1982, 1986, 1988, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)syslog.h 8.1 (Berkeley) 6/2/93 + */ + +#ifndef _SYS_SYSLOG_H +#define _SYS_SYSLOG_H 1 + +#define _PATH_LOG "" + +/* + * priorities/facilities are encoded into a single 32-bit quantity, where the + * bottom 3 bits are the priority (0-7) and the top 28 bits are the facility + * (0-big number). Both the priorities and the facilities map roughly + * one-to-one to strings in the syslogd(8) source code. This mapping is + * included in this file. + * + * priorities (these are ordered) + */ +#define LOG_EMERG 0 /* system is unusable */ +#define LOG_ALERT 1 /* action must be taken immediately */ +#define LOG_CRIT 2 /* critical conditions */ +#define LOG_ERR 3 /* error conditions */ +#define LOG_WARNING 4 /* warning conditions */ +#define LOG_NOTICE 5 /* normal but significant condition */ +#define LOG_INFO 6 /* informational */ +#define LOG_DEBUG 7 /* debug-level messages */ + +#define LOG_PRIMASK 0x07 /* mask to extract priority part (internal) */ + /* extract priority */ +#define LOG_PRI(p) ((p) & LOG_PRIMASK) +#define LOG_MAKEPRI(fac, pri) (((fac) << 3) | (pri)) + +/* facility codes */ +#define LOG_KERN (0<<3) /* kernel messages */ +#define LOG_USER (1<<3) /* random user-level messages */ +#define LOG_MAIL (2<<3) /* mail system */ +#define LOG_DAEMON (3<<3) /* system daemons */ +#define LOG_AUTH (4<<3) /* security/authorization messages */ +#define LOG_SYSLOG (5<<3) /* messages generated internally by syslogd */ +#define LOG_LPR (6<<3) /* line printer subsystem */ +#define LOG_NEWS (7<<3) /* network news subsystem */ +#define LOG_UUCP (8<<3) /* UUCP subsystem */ +#define LOG_CRON (9<<3) /* clock daemon */ +#define LOG_AUTHPRIV (10<<3) /* security/authorization messages (private) */ +#define LOG_FTP (11<<3) /* ftp daemon */ +#define LOG_NETINFO (12<<3) /* NetInfo */ +#define LOG_REMOTEAUTH (13<<3) /* remote authentication/authorization */ +#define LOG_INSTALL (14<<3) /* installer subsystem */ +#define LOG_RAS (15<<3) /* Remote Access Service (VPN / PPP) */ +#define LOG_LOCAL0 (16<<3) /* reserved for local use */ +#define LOG_LOCAL1 (17<<3) /* reserved for local use */ +#define LOG_LOCAL2 (18<<3) /* reserved for local use */ +#define LOG_LOCAL3 (19<<3) /* reserved for local use */ +#define LOG_LOCAL4 (20<<3) /* reserved for local use */ +#define LOG_LOCAL5 (21<<3) /* reserved for local use */ +#define LOG_LOCAL6 (22<<3) /* reserved for local use */ +#define LOG_LOCAL7 (23<<3) /* reserved for local use */ +#define LOG_LAUNCHD (24<<3) /* launchd - general bootstrap daemon */ + +#define LOG_NFACILITIES 25 /* current number of facilities */ +#define LOG_FACMASK 0x03f8 /* mask to extract facility part */ + /* facility of pri */ +#define LOG_FAC(p) (((p) & LOG_FACMASK) >> 3) + +/* + * arguments to setlogmask. + */ +#define LOG_MASK(pri) (1 << (pri)) /* mask for one priority */ +#define LOG_UPTO(pri) ((1 << ((pri)+1)) - 1) /* all priorities through pri */ + +/* + * Option flags for openlog. + * + * LOG_ODELAY no longer does anything. + * LOG_NDELAY is the inverse of what it used to be. + */ +#define LOG_PID 0x01 /* log the pid with each message */ +#define LOG_CONS 0x02 /* log on the console if errors in sending */ +#define LOG_ODELAY 0x04 /* delay open until first syslog() (default) */ +#define LOG_NDELAY 0x08 /* don't delay open */ +#define LOG_NOWAIT 0x10 /* don't wait for console forks: DEPRECATED */ +#define LOG_PERROR 0x20 /* log to stderr as well */ + +#endif /* sys/syslog.h */ diff --git a/gnu/usr.bin/perl/ext/Sys/Syslog/t/00-load.t b/gnu/usr.bin/perl/ext/Sys/Syslog/t/00-load.t index 35d90426801..bbf22894576 100755 --- a/gnu/usr.bin/perl/ext/Sys/Syslog/t/00-load.t +++ b/gnu/usr.bin/perl/ext/Sys/Syslog/t/00-load.t @@ -1,9 +1,8 @@ -#!perl -T - +#!perl -wT +use strict; use Test::More tests => 1; -BEGIN { - use_ok( 'Sys::Syslog' ); -} +use_ok( 'Sys::Syslog' ); -#diag( "Testing Sys::Syslog $Sys::Syslog::VERSION, Perl $], $^X" ); +diag( "Testing Sys::Syslog $Sys::Syslog::VERSION, Perl $], $^X" ) + unless $ENV{PERL_CORE}; diff --git a/gnu/usr.bin/perl/ext/Sys/Syslog/t/portfs.t b/gnu/usr.bin/perl/ext/Sys/Syslog/t/portfs.t new file mode 100644 index 00000000000..43419cd3ad5 --- /dev/null +++ b/gnu/usr.bin/perl/ext/Sys/Syslog/t/portfs.t @@ -0,0 +1,9 @@ +#!perl -wT +use strict; +use Test::More; + +plan skip_all => "Test::Portability::Files required for testing filenames portability" + unless eval "use Test::Portability::Files; 1"; + +# run the selected tests +run_tests(); diff --git a/gnu/usr.bin/perl/ext/Sys/Syslog/t/syslog.t b/gnu/usr.bin/perl/ext/Sys/Syslog/t/syslog.t index 8f038d31fb9..56a83c74ef0 100644 --- a/gnu/usr.bin/perl/ext/Sys/Syslog/t/syslog.t +++ b/gnu/usr.bin/perl/ext/Sys/Syslog/t/syslog.t @@ -1,94 +1,273 @@ -#!./perl +#!perl -T BEGIN { - chdir 't' if -d 't'; - @INC = '../lib'; - require Config; import Config; - if ($Config{'extensions'} !~ /\bSyslog\b/) { - print "1..0 # Skip: Sys::Syslog was not built\n"; - exit 0; - } - if ($Config{'extensions'} !~ /\bSocket\b/) { - print "1..0 # Skip: Socket was not built\n"; - exit 0; + if ($ENV{PERL_CORE}) { + chdir 't'; + @INC = '../lib'; } +} - require Socket; +use strict; +use Config; +use File::Spec; +use Test::More; - # This code inspired by Sys::Syslog::connect(): - require Sys::Hostname; - my ($host_uniq) = Sys::Hostname::hostname(); - my ($host) = $host_uniq =~ /([A-Za-z0-9_.-]+)/; +# we enable all Perl warnings, but we don't "use warnings 'all'" because +# we want to disable the warnings generated by Sys::Syslog +no warnings; +use warnings qw(closure deprecated exiting glob io misc numeric once overflow + pack portable recursion redefine regexp severe signal substr + syntax taint uninitialized unpack untie utf8 void); - if (! defined Socket::inet_aton($host)) { - print "1..0 # Skip: Can't lookup $host\n"; - exit 0; - } +# if someone is using warnings::compat, the previous trick won't work, so we +# must manually disable warnings +$^W = 0 if $] < 5.006; + +my $is_Win32 = $^O =~ /win32/i; +my $is_Cygwin = $^O =~ /cygwin/i; + +# if testing in core, check that the module is at least available +if ($ENV{PERL_CORE}) { + plan skip_all => "Sys::Syslog was not build" + unless $Config{'extensions'} =~ /\bSyslog\b/; } -BEGIN { - eval {require Sys::Syslog} or do { - if ($@ =~ /Your vendor has not/) { - print "1..0 # Skip: missing macros\n"; - exit 0; +# we also need Socket +plan skip_all => "Socket was not build" + unless $Config{'extensions'} =~ /\bSocket\b/; + +my $tests; +plan tests => $tests; + +# any remaining warning should be severly punished +BEGIN { eval "use Test::NoWarnings"; $tests = $@ ? 0 : 1; } + +BEGIN { $tests += 1 } +# ok, now loads them +eval 'use Socket'; +use_ok('Sys::Syslog', ':standard', ':extended', ':macros'); + +BEGIN { $tests += 1 } +# check that the documented functions are correctly provided +can_ok( 'Sys::Syslog' => qw(openlog syslog syslog setlogmask setlogsock closelog) ); + + +BEGIN { $tests += 1 } +# check the diagnostics +# setlogsock() +eval { setlogsock() }; +like( $@, qr/^Invalid argument passed to setlogsock/, + "calling setlogsock() with no argument" ); + +BEGIN { $tests += 3 } +# syslog() +eval { syslog() }; +like( $@, qr/^syslog: expecting argument \$priority/, + "calling syslog() with no argument" ); + +eval { syslog(undef) }; +like( $@, qr/^syslog: expecting argument \$priority/, + "calling syslog() with one undef argument" ); + +eval { syslog('') }; +like( $@, qr/^syslog: expecting argument \$format/, + "calling syslog() with one empty argument" ); + + +my $test_string = "uid $< is testing Perl $] syslog(3) capabilities"; +my $r = 0; + +BEGIN { $tests += 8 } +# try to open a syslog using a Unix or stream socket +SKIP: { + skip "can't connect to Unix socket: _PATH_LOG unavailable", 8 + unless -e Sys::Syslog::_PATH_LOG(); + + # The only known $^O eq 'svr4' that needs this is NCR MP-RAS, + # but assuming 'stream' in SVR4 is probably not that bad. + my $sock_type = $^O =~ /^(solaris|irix|svr4|powerux)$/ ? 'stream' : 'unix'; + + eval { setlogsock($sock_type) }; + is( $@, '', "setlogsock() called with '$sock_type'" ); + TODO: { + local $TODO = "minor bug"; + ok( $r, "setlogsock() should return true: '$r'" ); + } + + # open syslog with a "local0" facility + SKIP: { + # openlog() + $r = eval { openlog('perl', 'ndelay', 'local0') } || 0; + skip "can't connect to syslog", 6 if $@ =~ /^no connection to syslog available/; + is( $@, '', "openlog() called with facility 'local0'" ); + ok( $r, "openlog() should return true: '$r'" ); + + # syslog() + $r = eval { syslog('info', "$test_string by connecting to a $sock_type socket") } || 0; + is( $@, '', "syslog() called with level 'info'" ); + ok( $r, "syslog() should return true: '$r'" ); + + # closelog() + $r = eval { closelog() } || 0; + is( $@, '', "closelog()" ); + ok( $r, "closelog() should return true: '$r'" ); } - } } -use Sys::Syslog qw(:DEFAULT setlogsock); -# Test this to 1 if your syslog accepts udp connections. -# Most don't (or at least shouldn't) -my $Test_Syslog_INET = 0; +BEGIN { $tests += 22 * 8 } +# try to open a syslog using all the available connection methods +my @passed = (); +for my $sock_type (qw(native eventlog unix pipe stream inet tcp udp)) { + SKIP: { + skip "the 'stream' mechanism because a previous mechanism with similar interface succeeded", 22 + if $sock_type eq 'stream' and grep {/pipe|unix/} @passed; + + # setlogsock() called with an arrayref + $r = eval { setlogsock([$sock_type]) } || 0; + skip "can't use '$sock_type' socket", 22 unless $r; + is( $@, '', "[$sock_type] setlogsock() called with ['$sock_type']" ); + ok( $r, "[$sock_type] setlogsock() should return true: '$r'" ); + + # setlogsock() called with a single argument + $r = eval { setlogsock($sock_type) } || 0; + skip "can't use '$sock_type' socket", 20 unless $r; + is( $@, '', "[$sock_type] setlogsock() called with '$sock_type'" ); + ok( $r, "[$sock_type] setlogsock() should return true: '$r'" ); -my $test_string = "uid $< is testing perl $] syslog capabilities"; + # openlog() without option NDELAY + $r = eval { openlog('perl', '', 'local0') } || 0; + skip "can't connect to syslog", 18 if $@ =~ /^no connection to syslog available/; + is( $@, '', "[$sock_type] openlog() called with facility 'local0' and without option 'ndelay'" ); + ok( $r, "[$sock_type] openlog() should return true: '$r'" ); -print "1..6\n"; + # openlog() with the option NDELAY + $r = eval { openlog('perl', 'ndelay', 'local0') } || 0; + skip "can't connect to syslog", 16 if $@ =~ /^no connection to syslog available/; + is( $@, '', "[$sock_type] openlog() called with facility 'local0' with option 'ndelay'" ); + ok( $r, "[$sock_type] openlog() should return true: '$r'" ); -if (Sys::Syslog::_PATH_LOG()) { - if (-e Sys::Syslog::_PATH_LOG()) { - # The only known $^O eq 'svr4' that needs this is NCR MP-RAS, - # but assuming 'stream' in SVR4 is probably not that bad. - if ($^O =~ /^(solaris|irix|svr4|powerux)$/) { - # we should check for stream support here, not for solaris/irix - 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"; + # syslog() with negative level, should fail + $r = eval { syslog(-1, "$test_string by connecting to a $sock_type socket") } || 0; + like( $@, '/^syslog: invalid level\/facility: /', "[$sock_type] syslog() called with level -1" ); + ok( !$r, "[$sock_type] syslog() should return false: '$r'" ); + + # syslog() with invalid level, should fail + $r = eval { syslog("plonk", "$test_string by connecting to a $sock_type socket") } || 0; + like( $@, '/^syslog: invalid level\/facility: /', "[$sock_type] syslog() called with level plonk" ); + ok( !$r, "[$sock_type] syslog() should return false: '$r'" ); + + # syslog() with levels "info" and "notice" (as a strings), should fail + $r = eval { syslog('info,notice', "$test_string by connecting to a $sock_type socket") } || 0; + like( $@, '/^syslog: too many levels given: notice/', "[$sock_type] syslog() called with level 'info,notice'" ); + ok( !$r, "[$sock_type] syslog() should return false: '$r'" ); + + # syslog() with facilities "local0" and "local1" (as a strings), should fail + $r = eval { syslog('local0,local1', "$test_string by connecting to a $sock_type socket") } || 0; + like( $@, '/^syslog: too many facilities given: local1/', "[$sock_type] syslog() called with level 'local0,local1'" ); + ok( !$r, "[$sock_type] syslog() should return false: '$r'" ); + + # syslog() with level "info" (as a string), should pass + $r = eval { syslog('info', "$test_string by connecting to a $sock_type socket") } || 0; + is( $@, '', "[$sock_type] syslog() called with level 'info' (string)" ); + ok( $r, "[$sock_type] syslog() should return true: '$r'" ); + + # syslog() with level "info" (as a macro), should pass + { local $! = 1; + $r = eval { syslog(LOG_INFO(), "$test_string by connecting to a $sock_type socket, setting a fake errno: %m") } || 0; } - if (defined(eval { openlog('perl', 'ndelay', 'local0') })) { - print "ok 2\n"; - print defined(eval { syslog('info', $test_string ) }) - ? "ok 3\n" : "not ok 3 # $!\n"; - } else { - if ($@ =~ /no connection to syslog available/) { - print "ok 2 # Skip: syslogd not running\n"; - } else { - print "not ok 2 # $@\n"; - } - print "ok 3 # Skip: openlog failed\n"; - } - } else { - for (1..3) { - print - "ok $_ # Skip: file ", - Sys::Syslog::_PATH_LOG(), - " does not exist\n"; + is( $@, '', "[$sock_type] syslog() called with level 'info' (macro)" ); + ok( $r, "[$sock_type] syslog() should return true: '$r'" ); + + push @passed, $sock_type; + + SKIP: { + skip "skipping closelog() tests for 'console'", 2 if $sock_type eq 'console'; + # closelog() + $r = eval { closelog() } || 0; + is( $@, '', "[$sock_type] closelog()" ); + ok( $r, "[$sock_type] closelog() should return true: '$r'" ); } } } -else { - for (1..3) { print "ok $_ # Skip: _PATH_LOG unavailable\n" } -} -if( $Test_Syslog_INET ) { - print defined(eval { setlogsock('inet') }) ? "ok 4\n" - : "not ok 4\n"; - print defined(eval { openlog('perl', 'ndelay', 'local0') }) ? "ok 5\n" - : "not ok 5 # $!\n"; - print defined(eval { syslog('info', $test_string ) }) ? "ok 6\n" - : "not ok 6 # $!\n"; + +BEGIN { $tests += 10 } +SKIP: { + skip "not testing setlogsock('stream') on Win32", 10 if $is_Win32; + skip "the 'unix' mechanism works, so the tests will likely fail with the 'stream' mechanism", 10 + if grep {/unix/} @passed; + + skip "not testing setlogsock('stream'): _PATH_LOG unavailable", 10 + unless -e Sys::Syslog::_PATH_LOG(); + + # setlogsock() with "stream" and an undef path + $r = eval { setlogsock("stream", undef ) } || ''; + is( $@, '', "setlogsock() called, with 'stream' and an undef path" ); + if ($is_Cygwin) { + if (-x "/usr/sbin/syslog-ng") { + ok( $r, "setlogsock() on Cygwin with syslog-ng should return true: '$r'" ); + } + else { + ok( !$r, "setlogsock() on Cygwin without syslog-ng should return false: '$r'" ); + } + } + else { + ok( $r, "setlogsock() should return true: '$r'" ); + } + + # setlogsock() with "stream" and an empty path + $r = eval { setlogsock("stream", '' ) } || ''; + is( $@, '', "setlogsock() called, with 'stream' and an empty path" ); + ok( !$r, "setlogsock() should return false: '$r'" ); + + # setlogsock() with "stream" and /dev/null + $r = eval { setlogsock("stream", '/dev/null' ) } || ''; + is( $@, '', "setlogsock() called, with 'stream' and '/dev/null'" ); + ok( $r, "setlogsock() should return true: '$r'" ); + + # setlogsock() with "stream" and a non-existing file + $r = eval { setlogsock("stream", 'test.log' ) } || ''; + is( $@, '', "setlogsock() called, with 'stream' and 'test.log' (file does not exist)" ); + ok( !$r, "setlogsock() should return false: '$r'" ); + + # setlogsock() with "stream" and a local file + SKIP: { + my $logfile = "test.log"; + open(LOG, ">$logfile") or skip "can't create file '$logfile': $!", 2; + close(LOG); + $r = eval { setlogsock("stream", $logfile ) } || ''; + is( $@, '', "setlogsock() called, with 'stream' and '$logfile' (file exists)" ); + ok( $r, "setlogsock() should return true: '$r'" ); + unlink($logfile); + } } -else { - print "ok $_ # Skip: assuming syslog doesn't accept inet connections\n" - foreach (4..6); + + +BEGIN { $tests += 3 + 4 * 3 } +# setlogmask() +{ + my $oldmask = 0; + + $oldmask = eval { setlogmask(0) } || 0; + is( $@, '', "setlogmask() called with a null mask" ); + $r = eval { setlogmask(0) } || 0; + is( $@, '', "setlogmask() called with a null mask (second time)" ); + is( $r, $oldmask, "setlogmask() must return the same mask as previous call"); + + my @masks = ( + LOG_MASK(LOG_ERR()), + ~LOG_MASK(LOG_INFO()), + LOG_MASK(LOG_CRIT()) | LOG_MASK(LOG_ERR()) | LOG_MASK(LOG_WARNING()), + ); + + for my $newmask (@masks) { + $r = eval { setlogmask($newmask) } || 0; + is( $@, '', "setlogmask() called with a new mask" ); + is( $r, $oldmask, "setlogmask() must return the same mask as previous call"); + $r = eval { setlogmask(0) } || 0; + is( $@, '', "setlogmask() called with a null mask" ); + is( $r, $newmask, "setlogmask() must return the new mask"); + setlogmask($oldmask); + } } |