1 |
#!/usr/bin/perl -w |
#!/usr/bin/perl -w |
2 |
############################################################################### |
############################################################################### |
3 |
# Meteor |
# Meteor |
4 |
# An HTTP server for the 2.0 web |
# An HTTP server for the 2.0 web |
5 |
# Copyright (c) 2006 contributing authors |
# Copyright (c) 2006 contributing authors |
6 |
# |
# |
7 |
# Subscriber.pm |
# Subscriber.pm |
8 |
# |
# |
9 |
# Description: |
# Description: |
10 |
# Convenience interface to syslog |
# Convenience interface to syslog |
11 |
# |
# |
12 |
############################################################################### |
############################################################################### |
13 |
# |
# |
14 |
# This program is free software; you can redistribute it and/or modify it |
# This program is free software; you can redistribute it and/or modify it |
15 |
# under the terms of the GNU General Public License as published by the Free |
# under the terms of the GNU General Public License as published by the Free |
16 |
# Software Foundation; either version 2 of the License, or (at your option) |
# Software Foundation; either version 2 of the License, or (at your option) |
17 |
# any later version. |
# any later version. |
18 |
# |
# |
19 |
# This program is distributed in the hope that it will be useful, but WITHOUT |
# This program is distributed in the hope that it will be useful, but WITHOUT |
20 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
21 |
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
22 |
# more details. |
# more details. |
23 |
# |
# |
24 |
# You should have received a copy of the GNU General Public License along |
# You should have received a copy of the GNU General Public License along |
25 |
# with this program; if not, write to the Free Software Foundation, Inc., |
# with this program; if not, write to the Free Software Foundation, Inc., |
26 |
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
27 |
# |
# |
28 |
# For more information visit www.meteorserver.org |
# For more information visit www.meteorserver.org |
29 |
# |
# |
30 |
############################################################################### |
############################################################################### |
31 |
|
|
32 |
package Meteor::Syslog; |
package Meteor::Syslog; |
33 |
############################################################################### |
############################################################################### |
34 |
|
|
35 |
use strict; |
use strict; |
36 |
use Sys::Syslog; |
use Sys::Syslog; |
37 |
|
|
38 |
############################################################################### |
############################################################################### |
39 |
# Configuration |
# Configuration |
40 |
############################################################################### |
############################################################################### |
41 |
|
|
42 |
$Meteor::Syslog::DEFAULT_FACILITY='daemon'; |
$Meteor::Syslog::DEFAULT_FACILITY='daemon'; |
43 |
|
|
44 |
$Meteor::Syslog::_open=0; # set to 1 by _open |
$Meteor::Syslog::_open=0; # set to 1 by _open |
45 |
|
|
46 |
############################################################################### |
############################################################################### |
47 |
# Implementation |
# Implementation |
48 |
############################################################################### |
############################################################################### |
49 |
sub ::syslog { |
sub ::syslog { |
50 |
|
|
51 |
if($::CONF{'Debug'}) |
if($::CONF{'Debug'}) |
52 |
{ |
{ |
53 |
my $priority=shift; |
my $priority=shift; |
54 |
my $format=shift; |
my $format=shift; |
55 |
|
|
56 |
$format=~s/\%m/$!/g; |
$format=~s/\%m/$!/g; |
57 |
|
|
58 |
print STDERR "$::PGM($priority): "; |
print STDERR "$::PGM($priority): "; |
59 |
print STDERR sprintf($format,@_); |
print STDERR sprintf($format,@_); |
60 |
print STDERR "\n" unless(substr($format,-1) eq "\n"); |
print STDERR "\n" unless(substr($format,-1) eq "\n"); |
61 |
|
|
62 |
return; |
return; |
63 |
} |
} |
64 |
else |
else |
65 |
{ |
{ |
66 |
# No expensive syslog calls for debug! |
# No expensive syslog calls for debug! |
67 |
return if($_[0] eq 'debug'); |
return if($_[0] eq 'debug'); |
68 |
} |
} |
69 |
|
|
70 |
unless($Meteor::Syslog::_open) |
unless($Meteor::Syslog::_open) |
71 |
{ |
{ |
72 |
my $facility=$::CONF{'SyslogFacility'} || $Meteor::Syslog::DEFAULT_FACILITY; |
my $facility=$::CONF{'SyslogFacility'} || $Meteor::Syslog::DEFAULT_FACILITY; |
73 |
openlog($::PGM,0,$facility); |
openlog($::PGM,0,$facility); |
74 |
$Meteor::Syslog::_open=1; |
$Meteor::Syslog::_open=1; |
75 |
} |
} |
76 |
|
|
77 |
syslog(@_); |
syslog(@_); |
78 |
} |
} |
79 |
|
|
80 |
sub myWarn { |
sub myWarn { |
81 |
local $SIG{'__DIE__'}=''; |
local $SIG{'__DIE__'}=''; |
82 |
local $SIG{'__WARN__'}=''; |
local $SIG{'__WARN__'}=''; |
83 |
|
|
84 |
&::syslog('warning',$_[0]); |
&::syslog('warning',$_[0]); |
85 |
} |
} |
86 |
|
|
87 |
sub myDie { |
sub myDie { |
88 |
local $SIG{'__DIE__'}=''; |
local $SIG{'__DIE__'}=''; |
89 |
local $SIG{'__WARN__'}=''; |
local $SIG{'__WARN__'}=''; |
90 |
|
|
91 |
my $inEval=0; |
my $inEval=0; |
92 |
my $i=0; |
my $i=0; |
93 |
my $sub; |
my $sub; |
94 |
while((undef,undef,undef,$sub)=caller(++$i)) |
while((undef,undef,undef,$sub)=caller(++$i)) |
95 |
{ |
{ |
96 |
$inEval=1, last if $sub eq '(eval)'; |
$inEval=1, last if $sub eq '(eval)'; |
97 |
} |
} |
98 |
|
|
99 |
unless($inEval) |
unless($inEval) |
100 |
{ |
{ |
101 |
&::syslog('err',$_[0]); |
&::syslog('err',$_[0]); |
102 |
$Meteor::Socket::NO_WARN_ON_CLOSE=1; |
$Meteor::Socket::NO_WARN_ON_CLOSE=1; |
103 |
exit; |
exit; |
104 |
} |
} |
105 |
} |
} |
106 |
|
|
107 |
1; |
1; |
108 |
############################################################################EOF |
############################################################################EOF |