Subversion Repositories

?revision_form?Rev ?revision_input??revision_submit??revision_endform?

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 magnus 1
package DebPool::Signal;
2
 
3
###
4
#
5
# DebPool::DB - Module for handling inter-process signals
6
#
7
# Copyright 2003-2004 Joel Aelwyn. All rights reserved.
8
# 
9
# Redistribution and use in source and binary forms, with or without
10
# modification, are permitted provided that the following conditions
11
# are met:
12
# 1. Redistributions of source code must retain the above copyright
13
#    notice, this list of conditions and the following disclaimer.
14
# 2. Redistributions in binary form must reproduce the above copyright
15
#    notice, this list of conditions and the following disclaimer in the
16
#    documentation and/or other materials provided with the distribution.
17
# 3. Neither the name of the Author nor the names of any contributors
18
#    may be used to endorse or promote products derived from this software
19
#    without specific prior written permission.
20
# 
21
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
22
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24
# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
25
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31
# SUCH DAMAGE.
32
#
33
# $Id: Signal.pm 27 2004-11-07 03:06:59Z joel $
34
#
35
###
36
 
37
# We use 'our', so we must have at least Perl 5.6
38
 
39
require 5.006_000;
40
 
41
# Always good ideas.
42
 
43
use strict;
44
use warnings;
45
 
46
# We do logging, so we need this.
47
 
48
use DebPool::Logging qw(:functions :facility :level);
49
 
50
### Module setup
51
 
52
BEGIN {
53
    use Exporter ();
54
    our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
55
 
56
    # Version checking
57
    $VERSION = '0.1.5';
58
 
59
    @ISA = qw(Exporter);
60
 
61
    @EXPORT = qw(
62
    );
63
 
64
    @EXPORT_OK = qw(
65
        $Signal_Caught
66
        %ComponentDB
67
    );
68
 
69
    %EXPORT_TAGS = (
70
        'functions' => [qw()],
71
        'vars' => [qw($Signal_Caught)],
72
    );
73
}
74
 
75
### Exported package globals
76
 
77
# Boolean value indicating whether we have caught one of the signals that
78
# normally trigger clean termination (SIGHUP, SIGINT, SIGPIPE, SIGTERM).
79
 
80
our($Signal_Caught) = 0;
81
 
82
### Non-exported package globals
83
 
84
# Thread-safe? What's that? Package global error value. We don't export
85
# this directly, because it would conflict with other modules.
86
 
87
our($Error);
88
 
89
### File lexicals
90
 
91
# None
92
 
93
### Constant functions
94
 
95
# None
96
 
97
### Meaningful functions
98
 
99
# None
100
 
101
### Special
102
 
103
# The purpose of this module is to handle signals usefully; therefore, we
104
# set up a basic term-signal handler that catches the 'ordinary termination
105
# requested' class of signals, and bind it via sigtrap.
106
 
107
sub Handle_SIGtermrequest {
108
    my($signal) = shift(@_);
109
 
110
    $Signal_Caught = 1;
111
    Log_Message("Caught signal " . $signal, LOG_GENERAL, LOG_INFO);
112
}
113
 
114
sub Handle_SIGHUP {
115
    Handle_SIGtermrequest('SIGHUP');
116
}
117
 
118
use sigtrap qw(handler Handle_SIGHUP HUP);
119
 
120
sub Handle_SIGINT {
121
    Handle_SIGtermrequest('SIGINT');
122
}
123
 
124
use sigtrap qw(handler Handle_SIGINT INT);
125
 
126
sub Handle_SIGPIPE {
127
    Handle_SIGtermrequest('SIGPIPE');
128
}
129
 
130
use sigtrap qw(handler Handle_SIGPIPE PIPE);
131
 
132
sub Handle_SIGTERM {
133
    Handle_SIGtermrequest('SIGTERM');
134
}
135
 
136
use sigtrap qw(handler Handle_SIGTERM TERM);
137
 
138
END {}
139
 
140
1;
141
 
142
__END__
143
 
144
# vim:set tabstop=4 expandtab: