6 require Config; import Config;
7 if ($Config{'extensions'} !~ /\bSyslog\b/) {
8 print "1..0 # Skip: Sys::Syslog was not built\n";
11 if ($Config{'extensions'} !~ /\bSocket\b/) {
12 print "1..0 # Skip: Socket was not built\n";
18 # This code inspired by Sys::Syslog::connect():
19 require Sys::Hostname;
20 my ($host_uniq) = Sys::Hostname::hostname();
21 my ($host) = $host_uniq =~ /([A-Za-z0-9_.-]+)/;
23 if (! defined Socket::inet_aton($host)) {
24 print "1..0 # Skip: Can't lookup $host\n";
30 eval {require Sys::Syslog} or do {
31 if ($@ =~ /Your vendor has not/) {
32 print "1..0 # Skip: missing macros\n";
38 use Sys::Syslog qw(:DEFAULT setlogsock);
40 # Test this to 1 if your syslog accepts udp connections.
41 # Most don't (or at least shouldn't)
42 my $Test_Syslog_INET = 0;
44 my $test_string = "uid $< is testing perl $] syslog capabilities";
48 if (Sys::Syslog::_PATH_LOG()) {
49 if (-e Sys::Syslog::_PATH_LOG()) {
50 # The only known $^O eq 'svr4' that needs this is NCR MP-RAS,
51 # but assuming 'stream' in SVR4 is probably not that bad.
52 if ($^O =~ /^(solaris|irix|svr4|powerux)$/) {
53 # we should check for stream support here, not for solaris/irix
54 print defined(eval { setlogsock('stream') }) ? "ok 1\n" : "not ok 1 # $!\n";
56 print defined(eval { setlogsock('unix') }) ? "ok 1\n" : "not ok 1 # $!\n";
58 if (defined(eval { openlog('perl', 'ndelay', 'local0') })) {
60 print defined(eval { syslog('info', $test_string ) })
61 ? "ok 3\n" : "not ok 3 # $!\n";
63 if ($@ =~ /no connection to syslog available/) {
64 print "ok 2 # Skip: syslogd not running\n";
66 print "not ok 2 # $@\n";
68 print "ok 3 # Skip: openlog failed\n";
73 "ok $_ # Skip: file ",
74 Sys::Syslog::_PATH_LOG(),
80 for (1..3) { print "ok $_ # Skip: _PATH_LOG unavailable\n" }
83 if( $Test_Syslog_INET ) {
84 print defined(eval { setlogsock('inet') }) ? "ok 4\n"
86 print defined(eval { openlog('perl', 'ndelay', 'local0') }) ? "ok 5\n"
88 print defined(eval { syslog('info', $test_string ) }) ? "ok 6\n"
92 print "ok $_ # Skip: assuming syslog doesn't accept inet connections\n"