| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# $Date: 2003/05/31 18:16:43 $ |
|
2
|
|
|
|
|
|
|
# $Revision: 1.5 $ |
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Net::Z3950::AsyncZ::Errors; |
|
6
|
1
|
|
|
1
|
|
32250
|
use Event; |
|
|
1
|
|
|
|
|
18613
|
|
|
|
1
|
|
|
|
|
6
|
|
|
7
|
1
|
|
|
1
|
|
4065
|
use Symbol; |
|
|
1
|
|
|
|
|
867
|
|
|
|
1
|
|
|
|
|
79
|
|
|
8
|
1
|
|
|
1
|
|
5
|
use Exporter; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
44
|
|
|
9
|
|
|
|
|
|
|
@ISA=qw (Exporter); |
|
10
|
|
|
|
|
|
|
@EXPORT = qw(suppressErrors); |
|
11
|
1
|
|
|
1
|
|
4
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
941
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
{ |
|
14
|
|
|
|
|
|
|
my $_FH = \*STDOUT; |
|
15
|
|
|
|
|
|
|
my $_SAVESTDERR = \*STDERR; |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
|
18
|
0
|
|
|
0
|
|
|
sub _FH() { $_FH; } |
|
19
|
0
|
|
|
0
|
|
|
sub _setFH { $_FH = $_[0]; } |
|
20
|
0
|
|
|
0
|
|
|
sub _saveSTDERR { $_SAVESTDERR = $_[0]; } |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my $_HOST = ""; |
|
24
|
|
|
|
|
|
|
my $_DB = ""; |
|
25
|
0
|
|
|
0
|
|
|
sub _setHost { $_HOST = $_[0]; } |
|
26
|
0
|
|
|
0
|
|
|
sub _getHost { $_HOST; } |
|
27
|
0
|
|
|
0
|
|
|
sub _setDB { $_DB = $_[0]; } |
|
28
|
0
|
|
|
0
|
|
|
sub _getDB { $_DB; } |
|
29
|
|
|
|
|
|
|
|
|
30
|
0
|
|
|
0
|
|
|
sub _getSaveErr { $_SAVESTDERR; } |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
my $_QUERY = ""; |
|
33
|
|
|
|
|
|
|
my $_SYNTAX= ""; |
|
34
|
0
|
|
|
0
|
|
|
sub _setQuery { $_QUERY = $_[0]; } |
|
35
|
0
|
|
|
0
|
|
|
sub _setSyntax{ $_SYNTAX = $_[0]; } |
|
36
|
0
|
|
|
0
|
|
|
sub _getQuery { $_QUERY; } |
|
37
|
0
|
|
|
0
|
|
|
sub _getSyntax{ $_SYNTAX; } |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
my $ERROR_VAL = 225; |
|
40
|
|
|
|
|
|
|
my $SUPPRESS_ERRORS = 0; |
|
41
|
|
|
|
|
|
|
|
|
42
|
0
|
0
|
|
0
|
0
|
|
sub suppress { $SUPPRESS_ERRORS = $_[0] if $_[0]; $SUPPRESS_ERRORS } |
|
|
0
|
|
|
|
|
|
|
|
43
|
0
|
|
|
0
|
0
|
|
sub errorval { $ERROR_VAL; } |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# when this is called, setting log=>suppressErrors(), then all error output is |
|
48
|
|
|
|
|
|
|
# suppressed, including STDERR |
|
49
|
|
|
|
|
|
|
|
|
50
|
0
|
|
|
0
|
0
|
|
sub suppressErrors { return Net::Z3950::AsyncZ::SuppressErr->new();} |
|
51
|
|
|
|
|
|
|
|
|
52
|
0
|
|
|
0
|
0
|
|
sub fh { return _FH(); } |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub closelog { |
|
55
|
0
|
|
|
0
|
0
|
|
my $fh = _FH(); |
|
56
|
0
|
0
|
|
|
|
|
my $retv = close($fh) if $fh != \*STDOUT; |
|
57
|
0
|
|
|
|
|
|
my $err = _getSaveErr(); |
|
58
|
0
|
0
|
0
|
|
|
|
close STDERR and open STDERR, ">&SAVERR" if $err != \*STDERR; |
|
59
|
0
|
|
|
|
|
|
return $retv; |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# To suppress errors set log => suppressErrors() |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub new { |
|
65
|
0
|
|
|
0
|
0
|
|
my($class, $filespec, $server, $query, $syntax, $db) = @_; |
|
66
|
0
|
|
|
|
|
|
my $handle = \*STDOUT; |
|
67
|
0
|
0
|
|
|
|
|
_setHost($server) if $server; |
|
68
|
0
|
0
|
|
|
|
|
_setQuery($query) if $query; |
|
69
|
0
|
0
|
|
|
|
|
_setSyntax($syntax) if $syntax; |
|
70
|
0
|
0
|
|
|
|
|
_setDB($db) if $db; |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# DEFAULT: write all error messages to terminal |
|
74
|
|
|
|
|
|
|
|
|
75
|
0
|
0
|
|
|
|
|
if(ref $filespec eq 'Net::Z3950::AsyncZ::SuppressErr') |
|
|
|
0
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
{ # redirect all system and lib messages to /dev/null |
|
77
|
0
|
0
|
|
|
|
|
open SAVERR, ">&STDERR" and _saveSTDERR(\*SAVERR); |
|
78
|
0
|
0
|
|
|
|
|
open STDERR, ">>/dev/null" if(_getSaveErr() != \*STDERR); |
|
79
|
0
|
|
|
|
|
|
suppress(1); |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
elsif($filespec) { |
|
82
|
0
|
0
|
0
|
|
|
|
open (FH, ">>$filespec") and $handle = \*FH |
|
|
|
|
0
|
|
|
|
|
|
83
|
|
|
|
|
|
|
and open SAVERR, ">&STDERR" and _saveSTDERR(\*SAVERR); |
|
84
|
0
|
0
|
|
|
|
|
if(_getSaveErr() != \*STDERR) { |
|
85
|
0
|
0
|
0
|
|
|
|
open STDERR, ">>$filespec" and select STDERR and $|=1; |
|
86
|
0
|
|
|
|
|
|
select STDOUT; |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
_setFH($handle); |
|
91
|
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
$SIG{__WARN__} = \&sigHandler; |
|
93
|
0
|
|
|
|
|
|
$SIG{__DIE__} = \&dieHandler; |
|
94
|
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
bless $handle, $class; |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub report_error { |
|
100
|
0
|
|
|
0
|
0
|
|
my $parm = shift; |
|
101
|
0
|
|
|
|
|
|
my $errno = shift; |
|
102
|
0
|
|
|
|
|
|
my $handle; |
|
103
|
0
|
|
|
|
|
|
my ($msg) = "Unspecified Error"; |
|
104
|
|
|
|
|
|
|
|
|
105
|
0
|
0
|
|
|
|
|
if (defined $errno) { |
|
106
|
0
|
|
|
|
|
|
$errno += errorval(); |
|
107
|
|
|
|
|
|
|
} |
|
108
|
0
|
|
|
|
|
|
else { $errno = -1; } |
|
109
|
|
|
|
|
|
|
|
|
110
|
0
|
0
|
|
|
|
|
if(ref $parm) { |
|
111
|
0
|
|
|
|
|
|
$handle = $parm; |
|
112
|
|
|
|
|
|
|
} |
|
113
|
|
|
|
|
|
|
else { |
|
114
|
0
|
|
|
|
|
|
$msg = $parm; |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
|
|
117
|
0
|
0
|
|
|
|
|
if($handle) { |
|
118
|
0
|
|
|
|
|
|
$errno=$handle->errcode(); |
|
119
|
0
|
|
|
|
|
|
$msg = $handle->errmsg(); |
|
120
|
0
|
|
|
|
|
|
my $query = _getQuery(); |
|
121
|
0
|
|
|
|
|
|
my $syntax = _getSyntax(); |
|
122
|
0
|
0
|
|
|
|
|
if($msg) { |
|
123
|
0
|
|
|
|
|
|
$msg = "Error Number: $errno\n$msg\n"; |
|
124
|
0
|
|
|
|
|
|
$msg .= "Query: $query\n"; |
|
125
|
0
|
|
|
|
|
|
$msg .= "preferredRecordSyntax: $syntax\n" ; |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
} |
|
128
|
|
|
|
|
|
|
} |
|
129
|
|
|
|
|
|
|
else { |
|
130
|
0
|
|
|
|
|
|
$msg = "[$errno] $msg"; |
|
131
|
|
|
|
|
|
|
} |
|
132
|
0
|
|
|
|
|
|
sigHandler($msg); |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
} |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub reportNoEntries { |
|
137
|
0
|
|
|
0
|
0
|
|
my $fh = _FH(); |
|
138
|
0
|
0
|
|
|
|
|
print $fh "No Records for this Query\n" if(!suppress()); |
|
139
|
0
|
|
|
|
|
|
pushErr("No Records for this Query"); |
|
140
|
|
|
|
|
|
|
} |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub dieHandler { |
|
143
|
|
|
|
|
|
|
|
|
144
|
0
|
|
|
0
|
0
|
|
my ($pkg,$file, $line) = caller(); |
|
145
|
0
|
|
|
|
|
|
my $errno = $! + 0; |
|
146
|
0
|
|
|
|
|
|
sigHandler("[$errno] Die condition at $pkg; file: $file; line: $line\n" . $_[0] . "\n"); |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
} |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
my $errorPrevious = 0; |
|
152
|
|
|
|
|
|
|
sub sigHandler { |
|
153
|
1
|
|
|
1
|
|
5
|
no strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
39
|
|
|
154
|
0
|
|
|
0
|
0
|
|
local ($_sig) = @_; |
|
155
|
0
|
|
|
|
|
|
my $sig = $_sig; |
|
156
|
1
|
|
|
1
|
|
4
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
751
|
|
|
157
|
0
|
|
|
|
|
|
my $_FH = _FH(); |
|
158
|
0
|
|
|
|
|
|
_lock(_FH()); |
|
159
|
|
|
|
|
|
|
|
|
160
|
0
|
0
|
|
|
|
|
exit $errorPrevious if $errorPrevious; |
|
161
|
|
|
|
|
|
|
|
|
162
|
0
|
|
|
|
|
|
my $errno = errorval(); |
|
163
|
0
|
0
|
|
|
|
|
if ($sig =~/^\[(\d+)\]/) { |
|
164
|
0
|
|
|
|
|
|
$errno = $1; |
|
165
|
|
|
|
|
|
|
} |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
|
|
168
|
0
|
0
|
|
|
|
|
if(!suppress()) { # this goes to Error Log |
|
169
|
0
|
|
|
|
|
|
print $_FH "\n--------------------\n\n"; |
|
170
|
0
|
|
|
|
|
|
print $_FH scalar localtime, "\n"; |
|
171
|
0
|
|
|
|
|
|
my ($pkg,$file, $line, $sbr) = caller(); |
|
172
|
0
|
|
|
|
|
|
my ($pkg_1,$file_1, $line_1, $sbr_1) = caller(1); |
|
173
|
0
|
|
|
|
|
|
my ($pkg_2,$file_2, $line_2, $sbr_2) = caller(2); |
|
174
|
0
|
|
|
|
|
|
my ($pkg_3,$file_3, $line_3, $sbr_3) = caller(3); |
|
175
|
0
|
|
|
|
|
|
print $_FH "Package: $pkg; file: $file; line: $line\n"; |
|
176
|
|
|
|
|
|
|
|
|
177
|
0
|
|
|
|
|
|
print $_FH "Package: $pkg_1; file: $file_1; line: $line_1\n"; |
|
178
|
0
|
0
|
|
|
|
|
print $_FH "Package: $pkg_2; file: $file_2; line: $line_2\n" if $pkg_2; |
|
179
|
0
|
0
|
|
|
|
|
print $_FH "Package: $pkg_3; file: $file_3; line: $line_3\n" if $pkg_3; |
|
180
|
|
|
|
|
|
|
|
|
181
|
0
|
0
|
|
|
|
|
print $_FH "Subroutine: $sbr\n", if $sbr; |
|
182
|
|
|
|
|
|
|
|
|
183
|
0
|
0
|
|
|
|
|
print $_FH "Host: ", _getHost(), "\n" if _getHost(); |
|
184
|
0
|
0
|
|
|
|
|
print $_FH "DB: ", _getDB(), "\n" if _getDB(); |
|
185
|
0
|
0
|
|
|
|
|
print $_FH "$sig\n" if $sig; |
|
186
|
0
|
0
|
|
|
|
|
print $_FH "$!\n" if $errno != errorval(); |
|
187
|
0
|
0
|
|
|
|
|
print $_FH "Unable to connect to ", _getHost(), ".\n" if !$sig; |
|
188
|
|
|
|
|
|
|
} |
|
189
|
|
|
|
|
|
|
# this is available for browser when not in async mode |
|
190
|
0
|
0
|
|
|
|
|
pushErr("$!\n") if $errno != errorval(); |
|
191
|
0
|
|
|
|
|
|
pushErr("Unable to connect to: ". _getHost() . " " . _getDB()); |
|
192
|
0
|
|
|
|
|
|
$errorPrevious = $errno; |
|
193
|
0
|
|
|
|
|
|
_unlock(_FH()); |
|
194
|
|
|
|
|
|
|
|
|
195
|
0
|
|
|
|
|
|
exit $errno; |
|
196
|
|
|
|
|
|
|
} |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
my $LOCK_EX = 2; # Exclusive lock. |
|
201
|
|
|
|
|
|
|
my $LOCK_UN = 8; # Unlock. |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
sub _lock { |
|
204
|
|
|
|
|
|
|
|
|
205
|
0
|
|
|
0
|
|
|
flock $_[0], $LOCK_EX; |
|
206
|
0
|
|
|
|
|
|
seek $_[0], 0, 2; # seek end of file |
|
207
|
|
|
|
|
|
|
} |
|
208
|
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
sub _unlock { |
|
211
|
0
|
|
|
0
|
|
|
flock $_[0], $LOCK_UN; |
|
212
|
|
|
|
|
|
|
} |
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
{ |
|
216
|
|
|
|
|
|
|
my @ErrorStack=(); |
|
217
|
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
sub pushErr { |
|
219
|
0
|
|
|
0
|
0
|
|
foreach my $err(@_) { |
|
220
|
0
|
|
|
|
|
|
push(@ErrorStack, $err); |
|
221
|
|
|
|
|
|
|
} |
|
222
|
|
|
|
|
|
|
} |
|
223
|
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
sub popErrs { |
|
225
|
0
|
0
|
|
0
|
0
|
|
return if !@ErrorStack; |
|
226
|
0
|
|
|
|
|
|
foreach my $err(@ErrorStack) { |
|
227
|
0
|
|
|
|
|
|
print STDOUT $err,"\n"; |
|
228
|
|
|
|
|
|
|
} |
|
229
|
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
} |
|
231
|
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
sub getErrs { |
|
233
|
0
|
0
|
|
0
|
0
|
|
return () if !@ErrorStack; |
|
234
|
0
|
|
|
|
|
|
return @ErrorStack; |
|
235
|
|
|
|
|
|
|
} |
|
236
|
|
|
|
|
|
|
} |
|
237
|
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
package Net::Z3950::AsyncZ::SuppressErr; |
|
240
|
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
# return a blank marker class to signal suppression of error output |
|
242
|
0
|
|
|
0
|
|
|
sub new { bless {}, $_[0]; } |
|
243
|
|
|
|
|
|
|
1; |
|
244
|
|
|
|
|
|
|
|