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