home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / perl / 5.10.0 / Sys / Syslog.pm < prev   
Encoding:
Perl POD Document  |  2009-06-26  |  38.4 KB  |  1,532 lines

  1. package Sys::Syslog;
  2. use strict;
  3. use warnings::register;
  4. use Carp;
  5. use Fcntl qw(O_WRONLY);
  6. use File::Basename;
  7. use POSIX qw(strftime setlocale LC_TIME);
  8. use Socket ':all';
  9. require 5.005;
  10. require Exporter;
  11.  
  12. {   no strict 'vars';
  13.     $VERSION = '0.22';
  14.     @ISA = qw(Exporter);
  15.  
  16.     %EXPORT_TAGS = (
  17.         standard => [qw(openlog syslog closelog setlogmask)],
  18.         extended => [qw(setlogsock)],
  19.         macros => [
  20.             # levels
  21.             qw(
  22.                 LOG_ALERT LOG_CRIT LOG_DEBUG LOG_EMERG LOG_ERR 
  23.                 LOG_INFO LOG_NOTICE LOG_WARNING
  24.             ), 
  25.  
  26.             # standard facilities
  27.             qw(
  28.                 LOG_AUTH LOG_AUTHPRIV LOG_CRON LOG_DAEMON LOG_FTP LOG_KERN
  29.                 LOG_LOCAL0 LOG_LOCAL1 LOG_LOCAL2 LOG_LOCAL3 LOG_LOCAL4
  30.                 LOG_LOCAL5 LOG_LOCAL6 LOG_LOCAL7 LOG_LPR LOG_MAIL LOG_NEWS
  31.                 LOG_SYSLOG LOG_USER LOG_UUCP
  32.             ),
  33.             # Mac OS X specific facilities
  34.             qw( LOG_INSTALL LOG_LAUNCHD LOG_NETINFO LOG_RAS LOG_REMOTEAUTH ),
  35.             # modern BSD specific facilities
  36.             qw( LOG_CONSOLE LOG_NTP LOG_SECURITY ),
  37.             # IRIX specific facilities
  38.             qw( LOG_AUDIT LOG_LFMT ),
  39.  
  40.             # options
  41.             qw(
  42.                 LOG_CONS LOG_PID LOG_NDELAY LOG_NOWAIT LOG_ODELAY LOG_PERROR 
  43.             ), 
  44.  
  45.             # others macros
  46.             qw(
  47.                 LOG_FACMASK LOG_NFACILITIES LOG_PRIMASK 
  48.                 LOG_MASK LOG_UPTO
  49.             ), 
  50.         ],
  51.     );
  52.  
  53.     @EXPORT = (
  54.         @{$EXPORT_TAGS{standard}}, 
  55.     );
  56.  
  57.     @EXPORT_OK = (
  58.         @{$EXPORT_TAGS{extended}}, 
  59.         @{$EXPORT_TAGS{macros}}, 
  60.     );
  61.  
  62.     eval {
  63.         require XSLoader;
  64.         XSLoader::load('Sys::Syslog', $VERSION);
  65.         1
  66.     } or do {
  67.         require DynaLoader;
  68.         push @ISA, 'DynaLoader';
  69.         bootstrap Sys::Syslog $VERSION;
  70.     };
  71. }
  72.  
  73.  
  74. # Public variables
  75. use vars qw($host);             # host to send syslog messages to (see notes at end)
  76.  
  77. # Global variables
  78. use vars qw($facility);
  79. my $connected = 0;              # flag to indicate if we're connected or not
  80. my $syslog_send;                # coderef of the function used to send messages
  81. my $syslog_path = undef;        # syslog path for "stream" and "unix" mechanisms
  82. my $syslog_xobj = undef;        # if defined, holds the external object used to send messages
  83. my $transmit_ok = 0;            # flag to indicate if the last message was transmited
  84. my $current_proto = undef;      # current mechanism used to transmit messages
  85. my $ident = '';                 # identifiant prepended to each message
  86. $facility = '';                 # current facility
  87. my $maskpri = LOG_UPTO(&LOG_DEBUG);     # current log mask
  88.  
  89. my %options = (
  90.     ndelay  => 0, 
  91.     nofatal => 0, 
  92.     nowait  => 0, 
  93.     perror  => 0, 
  94.     pid     => 0, 
  95. );
  96.  
  97. # Default is now to first use the native mechanism, so Perl programs 
  98. # behave like other normal Unix programs, then try other mechanisms.
  99. my @connectMethods = qw(native tcp udp unix pipe stream console);
  100. if ($^O =~ /^(freebsd|linux)$/) {
  101.     @connectMethods = grep { $_ ne 'udp' } @connectMethods;
  102. }
  103.  
  104. EVENTLOG: {
  105.     # use EventLog on Win32
  106.     my $is_Win32 = $^O =~ /Win32/i;
  107.  
  108.     # some applications are trying to be too smart
  109.     # yes I'm speaking of YOU, SpamAssassin, grr..
  110.     local($SIG{__DIE__}, $SIG{__WARN__}, $@);
  111.  
  112.     if (eval "use Sys::Syslog::Win32; 1") {
  113.         unshift @connectMethods, 'eventlog';
  114.     }
  115.     elsif ($is_Win32) {
  116.         warn $@;
  117.     }
  118. }
  119.  
  120. my @defaultMethods = @connectMethods;
  121. my @fallbackMethods = ();
  122.  
  123. # coderef for a nicer handling of errors
  124. my $err_sub = $options{nofatal} ? \&warnings::warnif : \&croak;
  125.  
  126.  
  127. sub AUTOLOAD {
  128.     # This AUTOLOAD is used to 'autoload' constants from the constant()
  129.     # XS function.
  130.     no strict 'vars';
  131.     my $constname;
  132.     ($constname = $AUTOLOAD) =~ s/.*:://;
  133.     croak "Sys::Syslog::constant() not defined" if $constname eq 'constant';
  134.     my ($error, $val) = constant($constname);
  135.     croak $error if $error;
  136.     no strict 'refs';
  137.     *$AUTOLOAD = sub { $val };
  138.     goto &$AUTOLOAD;
  139. }
  140.  
  141.  
  142. sub openlog {
  143.     ($ident, my $logopt, $facility) = @_;
  144.  
  145.     # default values
  146.     $ident    ||= basename($0) || getlogin() || getpwuid($<) || 'syslog';
  147.     $logopt   ||= '';
  148.     $facility ||= LOG_USER();
  149.  
  150.     for my $opt (split /\b/, $logopt) {
  151.         $options{$opt} = 1 if exists $options{$opt}
  152.     }
  153.  
  154.     $err_sub = $options{nofatal} ? \&warnings::warnif : \&croak;
  155.     return 1 unless $options{ndelay};
  156.     connect_log();
  157.  
  158. sub closelog {
  159.     $facility = $ident = '';
  160.     disconnect_log();
  161.  
  162. sub setlogmask {
  163.     my $oldmask = $maskpri;
  164.     $maskpri = shift unless $_[0] == 0;
  165.     $oldmask;
  166. }
  167.  
  168. sub setlogsock {
  169.     my $setsock = shift;
  170.     $syslog_path = shift;
  171.     disconnect_log() if $connected;
  172.     $transmit_ok = 0;
  173.     @fallbackMethods = ();
  174.     @connectMethods = @defaultMethods;
  175.  
  176.     if (ref $setsock eq 'ARRAY') {
  177.     @connectMethods = @$setsock;
  178.  
  179.     } elsif (lc $setsock eq 'stream') {
  180.     if (not defined $syslog_path) {
  181.         my @try = qw(/dev/log /dev/conslog);
  182.  
  183.             if (length &_PATH_LOG) {        # Undefined _PATH_LOG is "".
  184.         unshift @try, &_PATH_LOG;
  185.             }
  186.  
  187.         for my $try (@try) {
  188.         if (-w $try) {
  189.             $syslog_path = $try;
  190.             last;
  191.         }
  192.         }
  193.  
  194.             if (not defined $syslog_path) {
  195.                 warnings::warnif "stream passed to setlogsock, but could not find any device";
  196.                 return undef
  197.             }
  198.         }
  199.  
  200.     if (not -w $syslog_path) {
  201.             warnings::warnif "stream passed to setlogsock, but $syslog_path is not writable";
  202.         return undef;
  203.     } else {
  204.             @connectMethods = qw(stream);
  205.     }
  206.  
  207.     } elsif (lc $setsock eq 'unix') {
  208.         if (length _PATH_LOG() || (defined $syslog_path && -w $syslog_path)) {
  209.         $syslog_path = _PATH_LOG() unless defined $syslog_path;
  210.             @connectMethods = qw(unix);
  211.         } else {
  212.             warnings::warnif 'unix passed to setlogsock, but path not available';
  213.         return undef;
  214.         }
  215.  
  216.     } elsif (lc $setsock eq 'pipe') {
  217.         for my $path ($syslog_path, &_PATH_LOG, "/dev/log") {
  218.             next unless defined $path and length $path and -w $path;
  219.             $syslog_path = $path;
  220.             last
  221.         }
  222.  
  223.         if (not $syslog_path) {
  224.             warnings::warnif "pipe passed to setlogsock, but path not available";
  225.             return undef
  226.         }
  227.  
  228.         @connectMethods = qw(pipe);
  229.  
  230.     } elsif (lc $setsock eq 'native') {
  231.         @connectMethods = qw(native);
  232.  
  233.     } elsif (lc $setsock eq 'eventlog') {
  234.         if (eval "use Win32::EventLog; 1") {
  235.             @connectMethods = qw(eventlog);
  236.         } else {
  237.             warnings::warnif "eventlog passed to setlogsock, but no Win32 API available";
  238.             $@ = "";
  239.             return undef;
  240.         }
  241.  
  242.     } elsif (lc $setsock eq 'tcp') {
  243.     if (getservbyname('syslog', 'tcp') || getservbyname('syslogng', 'tcp')) {
  244.             @connectMethods = qw(tcp);
  245.     } else {
  246.             warnings::warnif "tcp passed to setlogsock, but tcp service unavailable";
  247.         return undef;
  248.     }
  249.  
  250.     } elsif (lc $setsock eq 'udp') {
  251.     if (getservbyname('syslog', 'udp')) {
  252.             @connectMethods = qw(udp);
  253.     } else {
  254.             warnings::warnif "udp passed to setlogsock, but udp service unavailable";
  255.         return undef;
  256.     }
  257.  
  258.     } elsif (lc $setsock eq 'inet') {
  259.     @connectMethods = ( 'tcp', 'udp' );
  260.  
  261.     } elsif (lc $setsock eq 'console') {
  262.     @connectMethods = qw(console);
  263.  
  264.     } else {
  265.         croak "Invalid argument passed to setlogsock; must be 'stream', 'pipe', ",
  266.               "'unix', 'native', 'eventlog', 'tcp', 'udp' or 'inet'"
  267.     }
  268.  
  269.     return 1;
  270. }
  271.  
  272. sub syslog {
  273.     my $priority = shift;
  274.     my $mask = shift;
  275.     my ($message, $buf);
  276.     my (@words, $num, $numpri, $numfac, $sum);
  277.     my $failed = undef;
  278.     my $fail_time = undef;
  279.     my $error = $!;
  280.  
  281.     # if $ident is undefined, it means openlog() wasn't previously called
  282.     # so do it now in order to have sensible defaults
  283.     openlog() unless $ident;
  284.  
  285.     local $facility = $facility;    # may need to change temporarily.
  286.  
  287.     croak "syslog: expecting argument \$priority" unless defined $priority;
  288.     croak "syslog: expecting argument \$format"   unless defined $mask;
  289.  
  290.     @words = split(/\W+/, $priority, 2);    # Allow "level" or "level|facility".
  291.     undef $numpri;
  292.     undef $numfac;
  293.  
  294.     foreach (@words) {
  295.     $num = xlate($_);            # Translate word to number.
  296.     if ($num < 0) {
  297.         croak "syslog: invalid level/facility: $_"
  298.     }
  299.     elsif ($num <= &LOG_PRIMASK) {
  300.         croak "syslog: too many levels given: $_" if defined $numpri;
  301.         $numpri = $num;
  302.         return 0 unless LOG_MASK($numpri) & $maskpri;
  303.     }
  304.     else {
  305.         croak "syslog: too many facilities given: $_" if defined $numfac;
  306.         $facility = $_;
  307.         $numfac = $num;
  308.     }
  309.     }
  310.  
  311.     croak "syslog: level must be given" unless defined $numpri;
  312.  
  313.     if (not defined $numfac) {  # Facility not specified in this call.
  314.     $facility = 'user' unless $facility;
  315.     $numfac = xlate($facility);
  316.     }
  317.  
  318.     connect_log() unless $connected;
  319.  
  320.     if ($mask =~ /%m/) {
  321.         # escape percent signs for sprintf()
  322.         $error =~ s/%/%%/g if @_;
  323.         # replace %m with $error, if preceded by an even number of percent signs
  324.         $mask =~ s/(?<!%)((?:%%)*)%m/$1$error/g;
  325.     }
  326.  
  327.     $mask .= "\n" unless $mask =~ /\n$/;
  328.     $message = @_ ? sprintf($mask, @_) : $mask;
  329.  
  330.     # See CPAN-RT#24431. Opened on Apple Radar as bug #4944407 on 2007.01.21
  331.     # Supposedly resolved on Leopard.
  332.     chomp $message if $^O =~ /darwin/;
  333.  
  334.     if ($current_proto eq 'native') {
  335.         $buf = $message;
  336.     }
  337.     elsif ($current_proto eq 'eventlog') {
  338.         $buf = $message;
  339.     }
  340.     else {
  341.         my $whoami = $ident;
  342.         $whoami .= "[$$]" if $options{pid};
  343.  
  344.         $sum = $numpri + $numfac;
  345.         my $oldlocale = setlocale(LC_TIME);
  346.         setlocale(LC_TIME, 'C');
  347.         my $timestamp = strftime "%b %e %T", localtime;
  348.         setlocale(LC_TIME, $oldlocale);
  349.         $buf = "<$sum>$timestamp $whoami: $message\0";
  350.     }
  351.  
  352.     # handle PERROR option
  353.     # "native" mechanism already handles it by itself
  354.     if ($options{perror} and $current_proto ne 'native') {
  355.         chomp $message;
  356.         my $whoami = $ident;
  357.         $whoami .= "[$$]" if $options{pid};
  358.         print STDERR "$whoami: $message\n";
  359.     }
  360.  
  361.     # it's possible that we'll get an error from sending
  362.     # (e.g. if method is UDP and there is no UDP listener,
  363.     # then we'll get ECONNREFUSED on the send). So what we
  364.     # want to do at this point is to fallback onto a different
  365.     # connection method.
  366.     while (scalar @fallbackMethods || $syslog_send) {
  367.     if ($failed && (time - $fail_time) > 60) {
  368.         # it's been a while... maybe things have been fixed
  369.         @fallbackMethods = ();
  370.         disconnect_log();
  371.         $transmit_ok = 0; # make it look like a fresh attempt
  372.         connect_log();
  373.         }
  374.  
  375.     if ($connected && !connection_ok()) {
  376.         # Something was OK, but has now broken. Remember coz we'll
  377.         # want to go back to what used to be OK.
  378.         $failed = $current_proto unless $failed;
  379.         $fail_time = time;
  380.         disconnect_log();
  381.     }
  382.  
  383.     connect_log() unless $connected;
  384.     $failed = undef if ($current_proto && $failed && $current_proto eq $failed);
  385.  
  386.     if ($syslog_send) {
  387.             if ($syslog_send->($buf, $numpri, $numfac)) {
  388.         $transmit_ok++;
  389.         return 1;
  390.         }
  391.         # typically doesn't happen, since errors are rare from write().
  392.         disconnect_log();
  393.     }
  394.     }
  395.     # could not send, could not fallback onto a working
  396.     # connection method. Lose.
  397.     return 0;
  398. }
  399.  
  400. sub _syslog_send_console {
  401.     my ($buf) = @_;
  402.     chop($buf); # delete the NUL from the end
  403.     # The console print is a method which could block
  404.     # so we do it in a child process and always return success
  405.     # to the caller.
  406.     if (my $pid = fork) {
  407.  
  408.     if ($options{nowait}) {
  409.         return 1;
  410.     } else {
  411.         if (waitpid($pid, 0) >= 0) {
  412.             return ($? >> 8);
  413.         } else {
  414.         # it's possible that the caller has other
  415.         # plans for SIGCHLD, so let's not interfere
  416.         return 1;
  417.         }
  418.     }
  419.     } else {
  420.         if (open(CONS, ">/dev/console")) {
  421.         my $ret = print CONS $buf . "\r";  # XXX: should this be \x0A ?
  422.         exit $ret if defined $pid;
  423.         close CONS;
  424.     }
  425.     exit if defined $pid;
  426.     }
  427. }
  428.  
  429. sub _syslog_send_stream {
  430.     my ($buf) = @_;
  431.     # XXX: this only works if the OS stream implementation makes a write 
  432.     # look like a putmsg() with simple header. For instance it works on 
  433.     # Solaris 8 but not Solaris 7.
  434.     # To be correct, it should use a STREAMS API, but perl doesn't have one.
  435.     return syswrite(SYSLOG, $buf, length($buf));
  436. }
  437.  
  438. sub _syslog_send_pipe {
  439.     my ($buf) = @_;
  440.     return print SYSLOG $buf;
  441. }
  442.  
  443. sub _syslog_send_socket {
  444.     my ($buf) = @_;
  445.     return syswrite(SYSLOG, $buf, length($buf));
  446.     #return send(SYSLOG, $buf, 0);
  447. }
  448.  
  449. sub _syslog_send_native {
  450.     my ($buf, $numpri) = @_;
  451.     syslog_xs($numpri, $buf);
  452.     return 1;
  453. }
  454.  
  455.  
  456. # xlate()
  457. # -----
  458. # private function to translate names to numeric values
  459. sub xlate {
  460.     my($name) = @_;
  461.     return $name+0 if $name =~ /^\s*\d+\s*$/;
  462.     $name = uc $name;
  463.     $name = "LOG_$name" unless $name =~ /^LOG_/;
  464.     $name = "Sys::Syslog::$name";
  465.     # Can't have just eval { &$name } || -1 because some LOG_XXX may be zero.
  466.     my $value = eval { no strict 'refs'; &$name };
  467.     $@ = "";
  468.     return defined $value ? $value : -1;
  469. }
  470.  
  471.  
  472. # connect_log()
  473. # -----------
  474. # This function acts as a kind of front-end: it tries to connect to 
  475. # a syslog service using the selected methods, trying each one in the 
  476. # selected order. 
  477. sub connect_log {
  478.     @fallbackMethods = @connectMethods unless scalar @fallbackMethods;
  479.  
  480.     if ($transmit_ok && $current_proto) {
  481.         # Retry what we were on, because it has worked in the past.
  482.     unshift(@fallbackMethods, $current_proto);
  483.     }
  484.  
  485.     $connected = 0;
  486.     my @errs = ();
  487.     my $proto = undef;
  488.  
  489.     while ($proto = shift @fallbackMethods) {
  490.     no strict 'refs';
  491.     my $fn = "connect_$proto";
  492.     $connected = &$fn(\@errs) if defined &$fn;
  493.     last if $connected;
  494.     }
  495.  
  496.     $transmit_ok = 0;
  497.     if ($connected) {
  498.     $current_proto = $proto;
  499.         my ($old) = select(SYSLOG); $| = 1; select($old);
  500.     } else {
  501.     @fallbackMethods = ();
  502.         $err_sub->(join "\n\t- ", "no connection to syslog available", @errs);
  503.         return undef;
  504.     }
  505. }
  506.  
  507. sub connect_tcp {
  508.     my ($errs) = @_;
  509.  
  510.     my $tcp = getprotobyname('tcp');
  511.     if (!defined $tcp) {
  512.     push @$errs, "getprotobyname failed for tcp";
  513.     return 0;
  514.     }
  515.  
  516.     my $syslog = getservbyname('syslog', 'tcp');
  517.     $syslog = getservbyname('syslogng', 'tcp') unless defined $syslog;
  518.     if (!defined $syslog) {
  519.     push @$errs, "getservbyname failed for syslog/tcp and syslogng/tcp";
  520.     return 0;
  521.     }
  522.  
  523.     my $addr;
  524.     if (defined $host) {
  525.         $addr = inet_aton($host);
  526.         if (!$addr) {
  527.         push @$errs, "can't lookup $host";
  528.         return 0;
  529.     }
  530.     } else {
  531.         $addr = INADDR_LOOPBACK;
  532.     }
  533.     $addr = sockaddr_in($syslog, $addr);
  534.  
  535.     if (!socket(SYSLOG, AF_INET, SOCK_STREAM, $tcp)) {
  536.     push @$errs, "tcp socket: $!";
  537.     return 0;
  538.     }
  539.  
  540.     setsockopt(SYSLOG, SOL_SOCKET, SO_KEEPALIVE, 1);
  541.     if (eval { IPPROTO_TCP() }) {
  542.         # These constants don't exist in 5.005. They were added in 1999
  543.         setsockopt(SYSLOG, IPPROTO_TCP(), TCP_NODELAY(), 1);
  544.     }
  545.     $@ = "";
  546.     if (!connect(SYSLOG, $addr)) {
  547.     push @$errs, "tcp connect: $!";
  548.     return 0;
  549.     }
  550.  
  551.     $syslog_send = \&_syslog_send_socket;
  552.  
  553.     return 1;
  554. }
  555.  
  556. sub connect_udp {
  557.     my ($errs) = @_;
  558.  
  559.     my $udp = getprotobyname('udp');
  560.     if (!defined $udp) {
  561.     push @$errs, "getprotobyname failed for udp";
  562.     return 0;
  563.     }
  564.  
  565.     my $syslog = getservbyname('syslog', 'udp');
  566.     if (!defined $syslog) {
  567.     push @$errs, "getservbyname failed for syslog/udp";
  568.     return 0;
  569.     }
  570.  
  571.     my $addr;
  572.     if (defined $host) {
  573.         $addr = inet_aton($host);
  574.         if (!$addr) {
  575.         push @$errs, "can't lookup $host";
  576.         return 0;
  577.     }
  578.     } else {
  579.         $addr = INADDR_LOOPBACK;
  580.     }
  581.     $addr = sockaddr_in($syslog, $addr);
  582.  
  583.     if (!socket(SYSLOG, AF_INET, SOCK_DGRAM, $udp)) {
  584.     push @$errs, "udp socket: $!";
  585.     return 0;
  586.     }
  587.     if (!connect(SYSLOG, $addr)) {
  588.     push @$errs, "udp connect: $!";
  589.     return 0;
  590.     }
  591.  
  592.     # We want to check that the UDP connect worked. However the only
  593.     # way to do that is to send a message and see if an ICMP is returned
  594.     _syslog_send_socket("");
  595.     if (!connection_ok()) {
  596.     push @$errs, "udp connect: nobody listening";
  597.     return 0;
  598.     }
  599.  
  600.     $syslog_send = \&_syslog_send_socket;
  601.  
  602.     return 1;
  603. }
  604.  
  605. sub connect_stream {
  606.     my ($errs) = @_;
  607.     # might want syslog_path to be variable based on syslog.h (if only
  608.     # it were in there!)
  609.     $syslog_path = '/dev/conslog' unless defined $syslog_path; 
  610.     if (!-w $syslog_path) {
  611.     push @$errs, "stream $syslog_path is not writable";
  612.     return 0;
  613.     }
  614.     if (!sysopen(SYSLOG, $syslog_path, 0400, O_WRONLY)) {
  615.     push @$errs, "stream can't open $syslog_path: $!";
  616.     return 0;
  617.     }
  618.     $syslog_send = \&_syslog_send_stream;
  619.     return 1;
  620. }
  621.  
  622. sub connect_pipe {
  623.     my ($errs) = @_;
  624.  
  625.     $syslog_path ||= &_PATH_LOG || "/dev/log";
  626.  
  627.     if (not -w $syslog_path) {
  628.         push @$errs, "$syslog_path is not writable";
  629.         return 0;
  630.     }
  631.  
  632.     if (not open(SYSLOG, ">$syslog_path")) {
  633.         push @$errs, "can't write to $syslog_path: $!";
  634.         return 0;
  635.     }
  636.  
  637.     $syslog_send = \&_syslog_send_pipe;
  638.  
  639.     return 1;
  640. }
  641.  
  642. sub connect_unix {
  643.     my ($errs) = @_;
  644.  
  645.     $syslog_path ||= _PATH_LOG() if length _PATH_LOG();
  646.  
  647.     if (not defined $syslog_path) {
  648.         push @$errs, "_PATH_LOG not available in syslog.h and no user-supplied socket path";
  649.     return 0;
  650.     }
  651.  
  652.     if (not (-S $syslog_path or -c _)) {
  653.         push @$errs, "$syslog_path is not a socket";
  654.     return 0;
  655.     }
  656.  
  657.     my $addr = sockaddr_un($syslog_path);
  658.     if (!$addr) {
  659.     push @$errs, "can't locate $syslog_path";
  660.     return 0;
  661.     }
  662.     if (!socket(SYSLOG, AF_UNIX, SOCK_STREAM, 0)) {
  663.         push @$errs, "unix stream socket: $!";
  664.     return 0;
  665.     }
  666.  
  667.     if (!connect(SYSLOG, $addr)) {
  668.         if (!socket(SYSLOG, AF_UNIX, SOCK_DGRAM, 0)) {
  669.         push @$errs, "unix dgram socket: $!";
  670.         return 0;
  671.     }
  672.         if (!connect(SYSLOG, $addr)) {
  673.         push @$errs, "unix dgram connect: $!";
  674.         return 0;
  675.     }
  676.     }
  677.  
  678.     $syslog_send = \&_syslog_send_socket;
  679.  
  680.     return 1;
  681. }
  682.  
  683. sub connect_native {
  684.     my ($errs) = @_;
  685.     my $logopt = 0;
  686.  
  687.     # reconstruct the numeric equivalent of the options
  688.     for my $opt (keys %options) {
  689.         $logopt += xlate($opt) if $options{$opt}
  690.     }
  691.  
  692.     eval { openlog_xs($ident, $logopt, xlate($facility)) };
  693.     if ($@) {
  694.         push @$errs, $@;
  695.         return 0;
  696.     }
  697.  
  698.     $syslog_send = \&_syslog_send_native;
  699.  
  700.     return 1;
  701. }
  702.  
  703. sub connect_eventlog {
  704.     my ($errs) = @_;
  705.  
  706.     $syslog_xobj = Sys::Syslog::Win32::_install();
  707.     $syslog_send = \&Sys::Syslog::Win32::_syslog_send;
  708.  
  709.     return 1;
  710. }
  711.  
  712. sub connect_console {
  713.     my ($errs) = @_;
  714.     if (!-w '/dev/console') {
  715.     push @$errs, "console is not writable";
  716.     return 0;
  717.     }
  718.     $syslog_send = \&_syslog_send_console;
  719.     return 1;
  720. }
  721.  
  722. # To test if the connection is still good, we need to check if any
  723. # errors are present on the connection. The errors will not be raised
  724. # by a write. Instead, sockets are made readable and the next read
  725. # would cause the error to be returned. Unfortunately the syslog 
  726. # 'protocol' never provides anything for us to read. But with 
  727. # judicious use of select(), we can see if it would be readable...
  728. sub connection_ok {
  729.     return 1 if defined $current_proto and (
  730.         $current_proto eq 'native' or $current_proto eq 'console'
  731.         or $current_proto eq 'eventlog'
  732.     );
  733.  
  734.     my $rin = '';
  735.     vec($rin, fileno(SYSLOG), 1) = 1;
  736.     my $ret = select $rin, undef, $rin, 0;
  737.     return ($ret ? 0 : 1);
  738. }
  739.  
  740. sub disconnect_log {
  741.     $connected = 0;
  742.     $syslog_send = undef;
  743.  
  744.     if (defined $current_proto and $current_proto eq 'native') {
  745.         closelog_xs();
  746.         return 1;
  747.     }
  748.     elsif (defined $current_proto and $current_proto eq 'eventlog') {
  749.         $syslog_xobj->Close();
  750.         return 1;
  751.     }
  752.  
  753.     return close SYSLOG;
  754. }
  755.  
  756. 1;
  757.  
  758. __END__
  759.  
  760. =head1 NAME
  761.  
  762. Sys::Syslog - Perl interface to the UNIX syslog(3) calls
  763.  
  764. =head1 VERSION
  765.  
  766. Version 0.22
  767.  
  768. =head1 SYNOPSIS
  769.  
  770.     use Sys::Syslog;                          # all except setlogsock(), or:
  771.     use Sys::Syslog qw(:DEFAULT setlogsock);  # default set, plus setlogsock()
  772.     use Sys::Syslog qw(:standard :macros);    # standard functions, plus macros
  773.  
  774.     openlog $ident, $logopt, $facility;       # don't forget this
  775.     syslog $priority, $format, @args;
  776.     $oldmask = setlogmask $mask_priority;
  777.     closelog;
  778.  
  779.  
  780. =head1 DESCRIPTION
  781.  
  782. C<Sys::Syslog> is an interface to the UNIX C<syslog(3)> program.
  783. Call C<syslog()> with a string priority and a list of C<printf()> args
  784. just like C<syslog(3)>.
  785.  
  786. You can find a kind of FAQ in L<"THE RULES OF SYS::SYSLOG">.  Please read 
  787. it before coding, and again before asking questions. 
  788.  
  789.  
  790. =head1 EXPORTS
  791.  
  792. C<Sys::Syslog> exports the following C<Exporter> tags: 
  793.  
  794. =over 4
  795.  
  796. =item *
  797.  
  798. C<:standard> exports the standard C<syslog(3)> functions: 
  799.  
  800.     openlog closelog setlogmask syslog
  801.  
  802. =item *
  803.  
  804. C<:extended> exports the Perl specific functions for C<syslog(3)>: 
  805.  
  806.     setlogsock
  807.  
  808. =item *
  809.  
  810. C<:macros> exports the symbols corresponding to most of your C<syslog(3)> 
  811. macros and the C<LOG_UPTO()> and C<LOG_MASK()> functions. 
  812. See L<"CONSTANTS"> for the supported constants and their meaning. 
  813.  
  814. =back
  815.  
  816. By default, C<Sys::Syslog> exports the symbols from the C<:standard> tag. 
  817.  
  818.  
  819. =head1 FUNCTIONS
  820.  
  821. =over 4
  822.  
  823. =item B<openlog($ident, $logopt, $facility)>
  824.  
  825. Opens the syslog.
  826. C<$ident> is prepended to every message.  C<$logopt> contains zero or
  827. more of the options detailed below.  C<$facility> specifies the part 
  828. of the system to report about, for example C<LOG_USER> or C<LOG_LOCAL0>:
  829. see L<"Facilities"> for a list of well-known facilities, and your 
  830. C<syslog(3)> documentation for the facilities available in your system. 
  831. Check L<"SEE ALSO"> for useful links. Facility can be given as a string 
  832. or a numeric macro. 
  833.  
  834. This function will croak if it can't connect to the syslog daemon.
  835.  
  836. Note that C<openlog()> now takes three arguments, just like C<openlog(3)>.
  837.  
  838. B<You should use C<openlog()> before calling C<syslog()>.>
  839.  
  840. B<Options>
  841.  
  842. =over 4
  843.  
  844. =item *
  845.  
  846. C<cons> - This option is ignored, since the failover mechanism will drop 
  847. down to the console automatically if all other media fail.
  848.  
  849. =item *
  850.  
  851. C<ndelay> - Open the connection immediately (normally, the connection is
  852. opened when the first message is logged).
  853.  
  854. =item *
  855.  
  856. C<nofatal> - When set to true, C<openlog()> and C<syslog()> will only 
  857. emit warnings instead of dying if the connection to the syslog can't 
  858. be established. 
  859.  
  860. =item *
  861.  
  862. C<nowait> - Don't wait for child processes that may have been created 
  863. while logging the message.  (The GNU C library does not create a child
  864. process, so this option has no effect on Linux.)
  865.  
  866. =item *
  867.  
  868. C<perror> - Write the message to standard error output as well to the
  869. system log.
  870.  
  871. =item *
  872.  
  873. C<pid> - Include PID with each message.
  874.  
  875. =back
  876.  
  877. B<Examples>
  878.  
  879. Open the syslog with options C<ndelay> and C<pid>, and with facility C<LOCAL0>: 
  880.  
  881.     openlog($name, "ndelay,pid", "local0");
  882.  
  883. Same thing, but this time using the macro corresponding to C<LOCAL0>: 
  884.  
  885.     openlog($name, "ndelay,pid", LOG_LOCAL0);
  886.  
  887.  
  888. =item B<syslog($priority, $message)>
  889.  
  890. =item B<syslog($priority, $format, @args)>
  891.  
  892. If C<$priority> permits, logs C<$message> or C<sprintf($format, @args)>
  893. with the addition that C<%m> in $message or C<$format> is replaced with
  894. C<"$!"> (the latest error message). 
  895.  
  896. C<$priority> can specify a level, or a level and a facility.  Levels and 
  897. facilities can be given as strings or as macros.  When using the C<eventlog>
  898. mechanism, priorities C<DEBUG> and C<INFO> are mapped to event type 
  899. C<informational>, C<NOTICE> and C<WARNIN> to C<warning> and C<ERR> to 
  900. C<EMERG> to C<error>.
  901.  
  902. If you didn't use C<openlog()> before using C<syslog()>, C<syslog()> will 
  903. try to guess the C<$ident> by extracting the shortest prefix of 
  904. C<$format> that ends in a C<":">.
  905.  
  906. B<Examples>
  907.  
  908.     syslog("info", $message);           # informational level
  909.     syslog(LOG_INFO, $message);         # informational level
  910.  
  911.     syslog("info|local0", $message);        # information level, Local0 facility
  912.     syslog(LOG_INFO|LOG_LOCAL0, $message);  # information level, Local0 facility
  913.  
  914. =over 4
  915.  
  916. =item B<Note>
  917.  
  918. C<Sys::Syslog> version v0.07 and older passed the C<$message> as the 
  919. formatting string to C<sprintf()> even when no formatting arguments
  920. were provided.  If the code calling C<syslog()> might execute with 
  921. older versions of this module, make sure to call the function as
  922. C<syslog($priority, "%s", $message)> instead of C<syslog($priority,
  923. $message)>.  This protects against hostile formatting sequences that
  924. might show up if $message contains tainted data.
  925.  
  926. =back
  927.  
  928.  
  929. =item B<setlogmask($mask_priority)>
  930.  
  931. Sets the log mask for the current process to C<$mask_priority> and 
  932. returns the old mask.  If the mask argument is 0, the current log mask 
  933. is not modified.  See L<"Levels"> for the list of available levels. 
  934. You can use the C<LOG_UPTO()> function to allow all levels up to a 
  935. given priority (but it only accept the numeric macros as arguments).
  936.  
  937. B<Examples>
  938.  
  939. Only log errors: 
  940.  
  941.     setlogmask( LOG_MASK(LOG_ERR) );
  942.  
  943. Log everything except informational messages: 
  944.  
  945.     setlogmask( ~(LOG_MASK(LOG_INFO)) );
  946.  
  947. Log critical messages, errors and warnings: 
  948.  
  949.     setlogmask( LOG_MASK(LOG_CRIT) | LOG_MASK(LOG_ERR) | LOG_MASK(LOG_WARNING) );
  950.  
  951. Log all messages up to debug: 
  952.  
  953.     setlogmask( LOG_UPTO(LOG_DEBUG) );
  954.  
  955.  
  956. =item B<setlogsock($sock_type)>
  957.  
  958. =item B<setlogsock($sock_type, $stream_location)> (added in Perl 5.004_02)
  959.  
  960. Sets the socket type to be used for the next call to
  961. C<openlog()> or C<syslog()> and returns true on success,
  962. C<undef> on failure. The available mechanisms are: 
  963.  
  964. =over
  965.  
  966. =item *
  967.  
  968. C<"native"> - use the native C functions from your C<syslog(3)> library
  969. (added in C<Sys::Syslog> 0.15).
  970.  
  971. =item *
  972.  
  973. C<"eventlog"> - send messages to the Win32 events logger (Win32 only; 
  974. added in C<Sys::Syslog> 0.19).
  975.  
  976. =item *
  977.  
  978. C<"tcp"> - connect to a TCP socket, on the C<syslog/tcp> or C<syslogng/tcp> 
  979. service. 
  980.  
  981. =item *
  982.  
  983. C<"udp"> - connect to a UDP socket, on the C<syslog/udp> service.
  984.  
  985. =item *
  986.  
  987. C<"inet"> - connect to an INET socket, either TCP or UDP, tried in that order. 
  988.  
  989. =item *
  990.  
  991. C<"unix"> - connect to a UNIX domain socket (in some systems a character 
  992. special device).  The name of that socket is the second parameter or, if 
  993. you omit the second parameter, the value returned by the C<_PATH_LOG> macro 
  994. (if your system defines it), or F</dev/log> or F</dev/conslog>, whatever is 
  995. writable.  
  996.  
  997. =item *
  998.  
  999. C<"stream"> - connect to the stream indicated by the pathname provided as 
  1000. the optional second parameter, or, if omitted, to F</dev/conslog>. 
  1001. For example Solaris and IRIX system may prefer C<"stream"> instead of C<"unix">. 
  1002.  
  1003. =item *
  1004.  
  1005. C<"pipe"> - connect to the named pipe indicated by the pathname provided as 
  1006. the optional second parameter, or, if omitted, to the value returned by 
  1007. the C<_PATH_LOG> macro (if your system defines it), or F</dev/log>
  1008. (added in C<Sys::Syslog> 0.21).
  1009.  
  1010. =item *
  1011.  
  1012. C<"console"> - send messages directly to the console, as for the C<"cons"> 
  1013. option of C<openlog()>.
  1014.  
  1015. =back
  1016.  
  1017. A reference to an array can also be passed as the first parameter.
  1018. When this calling method is used, the array should contain a list of
  1019. mechanisms which are attempted in order.
  1020.  
  1021. The default is to try C<native>, C<tcp>, C<udp>, C<unix>, C<stream>, C<console>.
  1022. Under systems with the Win32 API, C<eventlog> will be added as the first 
  1023. mechanism to try if C<Win32::EventLog> is available.
  1024.  
  1025. Giving an invalid value for C<$sock_type> will C<croak>.
  1026.  
  1027. B<Examples>
  1028.  
  1029. Select the UDP socket mechanism: 
  1030.  
  1031.     setlogsock("udp");
  1032.  
  1033. Select the native, UDP socket then UNIX domain socket mechanisms: 
  1034.  
  1035.     setlogsock(["native", "udp", "unix"]);
  1036.  
  1037. =over
  1038.  
  1039. =item B<Note>
  1040.  
  1041. Now that the "native" mechanism is supported by C<Sys::Syslog> and selected 
  1042. by default, the use of the C<setlogsock()> function is discouraged because 
  1043. other mechanisms are less portable across operating systems.  Authors of 
  1044. modules and programs that use this function, especially its cargo-cult form 
  1045. C<setlogsock("unix")>, are advised to remove any occurence of it unless they 
  1046. specifically want to use a given mechanism (like TCP or UDP to connect to 
  1047. a remote host).
  1048.  
  1049. =back
  1050.  
  1051. =item B<closelog()>
  1052.  
  1053. Closes the log file and returns true on success.
  1054.  
  1055. =back
  1056.  
  1057.  
  1058. =head1 THE RULES OF SYS::SYSLOG
  1059.  
  1060. I<The First Rule of Sys::Syslog is:>
  1061. You do not call C<setlogsock>.
  1062.  
  1063. I<The Second Rule of Sys::Syslog is:>
  1064. You B<do not> call C<setlogsock>.
  1065.  
  1066. I<The Third Rule of Sys::Syslog is:>
  1067. The program crashes, C<die>s, calls C<closelog>, the log is over.
  1068.  
  1069. I<The Fourth Rule of Sys::Syslog is:>
  1070. One facility, one priority.
  1071.  
  1072. I<The Fifth Rule of Sys::Syslog is:>
  1073. One log at a time.
  1074.  
  1075. I<The Sixth Rule of Sys::Syslog is:>
  1076. No C<syslog> before C<openlog>.
  1077.  
  1078. I<The Seventh Rule of Sys::Syslog is:>
  1079. Logs will go on as long as they have to. 
  1080.  
  1081. I<The Eighth, and Final Rule of Sys::Syslog is:>
  1082. If this is your first use of Sys::Syslog, you must read the doc.
  1083.  
  1084.  
  1085. =head1 EXAMPLES
  1086.  
  1087. An example:
  1088.  
  1089.     openlog($program, 'cons,pid', 'user');
  1090.     syslog('info', '%s', 'this is another test');
  1091.     syslog('mail|warning', 'this is a better test: %d', time);
  1092.     closelog();
  1093.  
  1094.     syslog('debug', 'this is the last test');
  1095.  
  1096. Another example:
  1097.  
  1098.     openlog("$program $$", 'ndelay', 'user');
  1099.     syslog('notice', 'fooprogram: this is really done');
  1100.  
  1101. Example of use of C<%m>:
  1102.  
  1103.     $! = 55;
  1104.     syslog('info', 'problem was %m');   # %m == $! in syslog(3)
  1105.  
  1106. Log to UDP port on C<$remotehost> instead of logging locally:
  1107.  
  1108.     setlogsock('udp');
  1109.     $Sys::Syslog::host = $remotehost;
  1110.     openlog($program, 'ndelay', 'user');
  1111.     syslog('info', 'something happened over here');
  1112.  
  1113.  
  1114. =head1 CONSTANTS
  1115.  
  1116. =head2 Facilities
  1117.  
  1118. =over 4
  1119.  
  1120. =item *
  1121.  
  1122. C<LOG_AUDIT> - audit daemon (IRIX); falls back to C<LOG_AUTH>
  1123.  
  1124. =item *
  1125.  
  1126. C<LOG_AUTH> - security/authorization messages
  1127.  
  1128. =item *
  1129.  
  1130. C<LOG_AUTHPRIV> - security/authorization messages (private)
  1131.  
  1132. =item *
  1133.  
  1134. C<LOG_CONSOLE> - C</dev/console> output (FreeBSD); falls back to C<LOG_USER>
  1135.  
  1136. =item *
  1137.  
  1138. C<LOG_CRON> - clock daemons (B<cron> and B<at>)
  1139.  
  1140. =item *
  1141.  
  1142. C<LOG_DAEMON> - system daemons without separate facility value
  1143.  
  1144. =item *
  1145.  
  1146. C<LOG_FTP> - FTP daemon
  1147.  
  1148. =item *
  1149.  
  1150. C<LOG_KERN> - kernel messages
  1151.  
  1152. =item *
  1153.  
  1154. C<LOG_INSTALL> - installer subsystem (Mac OS X); falls back to C<LOG_USER>
  1155.  
  1156. =item *
  1157.  
  1158. C<LOG_LAUNCHD> - launchd - general bootstrap daemon (Mac OS X);
  1159. falls back to C<LOG_DAEMON>
  1160.  
  1161. =item *
  1162.  
  1163. C<LOG_LFMT> - logalert facility; falls back to C<LOG_USER>
  1164.  
  1165. =item *
  1166.  
  1167. C<LOG_LOCAL0> through C<LOG_LOCAL7> - reserved for local use
  1168.  
  1169. =item *
  1170.  
  1171. C<LOG_LPR> - line printer subsystem
  1172.  
  1173. =item *
  1174.  
  1175. C<LOG_MAIL> - mail subsystem
  1176.  
  1177. =item *
  1178.  
  1179. C<LOG_NETINFO> - NetInfo subsystem (Mac OS X); falls back to C<LOG_DAEMON>
  1180.  
  1181. =item *
  1182.  
  1183. C<LOG_NEWS> - USENET news subsystem
  1184.  
  1185. =item *
  1186.  
  1187. C<LOG_NTP> - NTP subsystem (FreeBSD, NetBSD); falls back to C<LOG_DAEMON>
  1188.  
  1189. =item *
  1190.  
  1191. C<LOG_RAS> - Remote Access Service (VPN / PPP) (Mac OS X);
  1192. falls back to C<LOG_AUTH>
  1193.  
  1194. =item *
  1195.  
  1196. C<LOG_REMOTEAUTH> - remote authentication/authorization (Mac OS X);
  1197. falls back to C<LOG_AUTH>
  1198.  
  1199. =item *
  1200.  
  1201. C<LOG_SECURITY> - security subsystems (firewalling, etc.) (FreeBSD);
  1202. falls back to C<LOG_AUTH>
  1203.  
  1204. =item *
  1205.  
  1206. C<LOG_SYSLOG> - messages generated internally by B<syslogd>
  1207.  
  1208. =item *
  1209.  
  1210. C<LOG_USER> (default) - generic user-level messages
  1211.  
  1212. =item *
  1213.  
  1214. C<LOG_UUCP> - UUCP subsystem
  1215.  
  1216. =back
  1217.  
  1218.  
  1219. =head2 Levels
  1220.  
  1221. =over 4
  1222.  
  1223. =item *
  1224.  
  1225. C<LOG_EMERG> - system is unusable
  1226.  
  1227. =item *
  1228.  
  1229. C<LOG_ALERT> - action must be taken immediately
  1230.  
  1231. =item *
  1232.  
  1233. C<LOG_CRIT> - critical conditions
  1234.  
  1235. =item *
  1236.  
  1237. C<LOG_ERR> - error conditions
  1238.  
  1239. =item *
  1240.  
  1241. C<LOG_WARNING> - warning conditions
  1242.  
  1243. =item *
  1244.  
  1245. C<LOG_NOTICE> - normal, but significant, condition
  1246.  
  1247. =item *
  1248.  
  1249. C<LOG_INFO> - informational message
  1250.  
  1251. =item *
  1252.  
  1253. C<LOG_DEBUG> - debug-level message
  1254.  
  1255. =back
  1256.  
  1257.  
  1258. =head1 DIAGNOSTICS
  1259.  
  1260. =over
  1261.  
  1262. =item C<Invalid argument passed to setlogsock>
  1263.  
  1264. B<(F)> You gave C<setlogsock()> an invalid value for C<$sock_type>. 
  1265.  
  1266. =item C<eventlog passed to setlogsock, but no Win32 API available>
  1267.  
  1268. B<(W)> You asked C<setlogsock()> to use the Win32 event logger but the 
  1269. operating system running the program isn't Win32 or does not provides Win32
  1270. compatible facilities.
  1271.  
  1272. =item C<no connection to syslog available>
  1273.  
  1274. B<(F)> C<syslog()> failed to connect to the specified socket.
  1275.  
  1276. =item C<stream passed to setlogsock, but %s is not writable>
  1277.  
  1278. B<(W)> You asked C<setlogsock()> to use a stream socket, but the given 
  1279. path is not writable. 
  1280.  
  1281. =item C<stream passed to setlogsock, but could not find any device>
  1282.  
  1283. B<(W)> You asked C<setlogsock()> to use a stream socket, but didn't 
  1284. provide a path, and C<Sys::Syslog> was unable to find an appropriate one.
  1285.  
  1286. =item C<tcp passed to setlogsock, but tcp service unavailable>
  1287.  
  1288. B<(W)> You asked C<setlogsock()> to use a TCP socket, but the service 
  1289. is not available on the system. 
  1290.  
  1291. =item C<syslog: expecting argument %s>
  1292.  
  1293. B<(F)> You forgot to give C<syslog()> the indicated argument.
  1294.  
  1295. =item C<syslog: invalid level/facility: %s>
  1296.  
  1297. B<(F)> You specified an invalid level or facility.
  1298.  
  1299. =item C<syslog: too many levels given: %s>
  1300.  
  1301. B<(F)> You specified too many levels. 
  1302.  
  1303. =item C<syslog: too many facilities given: %s>
  1304.  
  1305. B<(F)> You specified too many facilities. 
  1306.  
  1307. =item C<syslog: level must be given>
  1308.  
  1309. B<(F)> You forgot to specify a level.
  1310.  
  1311. =item C<udp passed to setlogsock, but udp service unavailable>
  1312.  
  1313. B<(W)> You asked C<setlogsock()> to use a UDP socket, but the service 
  1314. is not available on the system. 
  1315.  
  1316. =item C<unix passed to setlogsock, but path not available>
  1317.  
  1318. B<(W)> You asked C<setlogsock()> to use a UNIX socket, but C<Sys::Syslog> 
  1319. was unable to find an appropriate an appropriate device.
  1320.  
  1321. =back
  1322.  
  1323.  
  1324. =head1 SEE ALSO
  1325.  
  1326. =head2 Manual Pages
  1327.  
  1328. L<syslog(3)>
  1329.  
  1330. SUSv3 issue 6, IEEE Std 1003.1, 2004 edition, 
  1331. L<http://www.opengroup.org/onlinepubs/000095399/basedefs/syslog.h.html>
  1332.  
  1333. GNU C Library documentation on syslog, 
  1334. L<http://www.gnu.org/software/libc/manual/html_node/Syslog.html>
  1335.  
  1336. Solaris 10 documentation on syslog, 
  1337. L<http://docs.sun.com/app/docs/doc/816-5168/6mbb3hruo?a=view>
  1338.  
  1339. IRIX 6.4 documentation on syslog,
  1340. L<http://techpubs.sgi.com/library/tpl/cgi-bin/getdoc.cgi?coll=0640&db=man&fname=3c+syslog>
  1341.  
  1342. AIX 5L 5.3 documentation on syslog, 
  1343. L<http://publib.boulder.ibm.com/infocenter/pseries/v5r3/index.jsp?topic=/com.ibm.aix.basetechref/doc/basetrf2/syslog.htm>
  1344.  
  1345. HP-UX 11i documentation on syslog, 
  1346. L<http://docs.hp.com/en/B9106-90010/syslog.3C.html>
  1347.  
  1348. Tru64 5.1 documentation on syslog, 
  1349. L<http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/V51_HTML/MAN/MAN3/0193____.HTM>
  1350.  
  1351. Stratus VOS 15.1, 
  1352. L<http://stratadoc.stratus.com/vos/15.1.1/r502-01/wwhelp/wwhimpl/js/html/wwhelp.htm?context=r502-01&file=ch5r502-01bi.html>
  1353.  
  1354. =head2 RFCs
  1355.  
  1356. I<RFC 3164 - The BSD syslog Protocol>, L<http://www.faqs.org/rfcs/rfc3164.html>
  1357. -- Please note that this is an informational RFC, and therefore does not 
  1358. specify a standard of any kind.
  1359.  
  1360. I<RFC 3195 - Reliable Delivery for syslog>, L<http://www.faqs.org/rfcs/rfc3195.html>
  1361.  
  1362. =head2 Articles
  1363.  
  1364. I<Syslogging with Perl>, L<http://lexington.pm.org/meetings/022001.html>
  1365.  
  1366. =head2 Event Log
  1367.  
  1368. Windows Event Log,
  1369. L<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wes/wes/windows_event_log.asp>
  1370.  
  1371.  
  1372. =head1 AUTHORS & ACKNOWLEDGEMENTS
  1373.  
  1374. Tom Christiansen E<lt>F<tchrist (at) perl.com>E<gt> and Larry Wall
  1375. E<lt>F<larry (at) wall.org>E<gt>.
  1376.  
  1377. UNIX domain sockets added by Sean Robinson
  1378. E<lt>F<robinson_s (at) sc.maricopa.edu>E<gt> with support from Tim Bunce 
  1379. E<lt>F<Tim.Bunce (at) ig.co.uk>E<gt> and the C<perl5-porters> mailing list.
  1380.  
  1381. Dependency on F<syslog.ph> replaced with XS code by Tom Hughes
  1382. E<lt>F<tom (at) compton.nu>E<gt>.
  1383.  
  1384. Code for C<constant()>s regenerated by Nicholas Clark E<lt>F<nick (at) ccl4.org>E<gt>.
  1385.  
  1386. Failover to different communication modes by Nick Williams
  1387. E<lt>F<Nick.Williams (at) morganstanley.com>E<gt>.
  1388.  
  1389. Extracted from core distribution for publishing on the CPAN by 
  1390. SE<eacute>bastien Aperghis-Tramoni E<lt>sebastien (at) aperghis.netE<gt>.
  1391.  
  1392. XS code for using native C functions borrowed from C<L<Unix::Syslog>>, 
  1393. written by Marcus Harnisch E<lt>F<marcus.harnisch (at) gmx.net>E<gt>.
  1394.  
  1395. Yves Orton suggested and helped for making C<Sys::Syslog> use the native 
  1396. event logger under Win32 systems.
  1397.  
  1398. Jerry D. Hedden and Reini Urban provided greatly appreciated help to 
  1399. debug and polish C<Sys::Syslog> under Cygwin.
  1400.  
  1401.  
  1402. =head1 BUGS
  1403.  
  1404. Please report any bugs or feature requests to
  1405. C<bug-sys-syslog (at) rt.cpan.org>, or through the web interface at
  1406. L<http://rt.cpan.org/Public/Dist/Display.html?Name=Sys-Syslog>.
  1407. I will be notified, and then you'll automatically be notified of progress on
  1408. your bug as I make changes.
  1409.  
  1410.  
  1411. =head1 SUPPORT
  1412.  
  1413. You can find documentation for this module with the perldoc command.
  1414.  
  1415.     perldoc Sys::Syslog
  1416.  
  1417. You can also look for information at:
  1418.  
  1419. =over 4
  1420.  
  1421. =item * AnnoCPAN: Annotated CPAN documentation
  1422.  
  1423. L<http://annocpan.org/dist/Sys-Syslog>
  1424.  
  1425. =item * CPAN Ratings
  1426.  
  1427. L<http://cpanratings.perl.org/d/Sys-Syslog>
  1428.  
  1429. =item * RT: CPAN's request tracker
  1430.  
  1431. L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Sys-Syslog>
  1432.  
  1433. =item * Search CPAN
  1434.  
  1435. L<http://search.cpan.org/dist/Sys-Syslog/>
  1436.  
  1437. =item * Kobes' CPAN Search
  1438.  
  1439. L<http://cpan.uwinnipeg.ca/dist/Sys-Syslog>
  1440.  
  1441. =item * Perl Documentation
  1442.  
  1443. L<http://perldoc.perl.org/Sys/Syslog.html>
  1444.  
  1445. =back
  1446.  
  1447.  
  1448. =head1 COPYRIGHT
  1449.  
  1450. Copyright (C) 1990-2007 by Larry Wall and others.
  1451.  
  1452.  
  1453. =head1 LICENSE
  1454.  
  1455. This program is free software; you can redistribute it and/or modify it
  1456. under the same terms as Perl itself.
  1457.  
  1458. =cut
  1459.  
  1460. =begin comment
  1461.  
  1462. Notes for the future maintainer (even if it's still me..)
  1463. - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1464.  
  1465. Using Google Code Search, I search who on Earth was relying on $host being 
  1466. public. It found 5 hits: 
  1467.  
  1468. * First was inside Indigo Star Perl2exe documentation. Just an old version 
  1469. of Sys::Syslog. 
  1470.  
  1471.  
  1472. * One real hit was inside DalWeathDB, a weather related program. It simply 
  1473. does a 
  1474.  
  1475.     $Sys::Syslog::host = '127.0.0.1';
  1476.  
  1477. - L<http://www.gallistel.net/nparker/weather/code/>
  1478.  
  1479.  
  1480. * Two hits were in TPC, a fax server thingy. It does a 
  1481.  
  1482.     $Sys::Syslog::host = $TPC::LOGHOST;
  1483.  
  1484. but also has this strange piece of code:
  1485.  
  1486.     # work around perl5.003 bug
  1487.     sub Sys::Syslog::hostname {}
  1488.  
  1489. I don't know what bug the author referred to.
  1490.  
  1491. - L<http://www.tpc.int/>
  1492. - L<ftp://ftp.tpc.int/tpc/server/UNIX/>
  1493. - L<ftp://ftp-usa.tpc.int/pub/tpc/server/UNIX/>
  1494.  
  1495.  
  1496. * Last hit was in Filefix, which seems to be a FIDOnet mail program (!).
  1497. This one does not use $host, but has the following piece of code:
  1498.  
  1499.     sub Sys::Syslog::hostname
  1500.     {
  1501.         use Sys::Hostname;
  1502.         return hostname;
  1503.     }
  1504.  
  1505. I guess this was a more elaborate form of the previous bit, maybe because 
  1506. of a bug in Sys::Syslog back then?
  1507.  
  1508. - L<ftp://ftp.kiae.su/pub/unix/fido/>
  1509.  
  1510.  
  1511. Links
  1512. -----
  1513. II12021: SYSLOGD HOWTO TCPIPINFO (z/OS, OS/390, MVS)
  1514. - L<http://www-1.ibm.com/support/docview.wss?uid=isg1II12021>
  1515.  
  1516. Getting the most out of the Event Viewer
  1517. - L<http://www.codeproject.com/dotnet/evtvwr.asp?print=true>
  1518.  
  1519. Log events to the Windows NT Event Log with JNI
  1520. - L<http://www.javaworld.com/javaworld/jw-09-2001/jw-0928-ntmessages.html>
  1521.  
  1522. =end comment
  1523.  
  1524.