~ptman/hipl/reload

« back to all changes in this revision

Viewing changes to tools/hipdnsproxy/util.py

  • Committer: Paul Tötterman
  • Date: 2013-07-11 15:08:01 UTC
  • Revision ID: paul.totterman@iki.fi-20130711150801-kt3riwzqz0hoeonq
Reload handling of SIGHUP.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
import struct
33
33
import sys
34
34
 
35
 
__FLAGS = {'down': False,
36
 
           'alarm': False}
 
35
__FLAGS = {'down': False, 'hup': False}
37
36
 
38
37
 
39
38
class Random:
67
66
 
68
67
def sighandler(signum, unused_frame):
69
68
    """A signal handler that toggles flags about received signals."""
70
 
    if signum == signal.SIGTERM:
71
 
        __FLAGS['down'] = True
72
 
    if signum == signal.SIGINT:
73
 
        __FLAGS['down'] = True
74
 
    if signum == signal.SIGALRM:
75
 
        __FLAGS['alarm'] = True
 
69
    if signum in (signal.SIGTERM, signal.SIGINT):
 
70
        __FLAGS['down'] = True
 
71
    if signum == signal.SIGHUP:
 
72
        __FLAGS['hup'] = True
76
73
 
77
74
 
78
75
def init_wantdown():
79
76
    """Hook signal handler to SIGTERM."""
80
77
    signal.signal(signal.SIGTERM, sighandler)
81
 
 
82
 
 
83
 
def init_wantdown_int():
84
 
    """Hook signal handler to SIGINT."""
85
78
    signal.signal(signal.SIGINT, sighandler)
86
79
 
87
80
 
88
 
def init_wantalarm():
89
 
    """Hook signal handler to SIGALRM."""
90
 
    signal.signal(signal.SIGALRM, sighandler)
 
81
def init_hup():
 
82
    """Hook signal handler to SIGHUP."""
 
83
    signal.signal(signal.SIGHUP, sighandler)
91
84
 
92
85
 
93
86
def wantdown():
94
87
    """Check if SIGINT or SIGTERM has been received."""
95
 
    previous = __FLAGS['down']
96
 
    __FLAGS['down'] = False
97
 
    return previous
98
 
 
99
 
 
100
 
def wantalarm():
101
 
    """Check if SIGALRM has been received."""
102
 
    previous = __FLAGS['alarm']
103
 
    __FLAGS['alarm'] = False
104
 
    return previous
105
 
 
 
88
    return __FLAGS['down']
 
89
 
 
90
def wanthup(reset=None):
 
91
    """Check if SIGHUP has been received."""
 
92
    previous = __FLAGS['hup']
 
93
 
 
94
    if reset is not None:
 
95
        __FLAGS['hup'] = reset
 
96
 
 
97
    return previous
106
98
 
107
99
TMULT = (
108
100
    (re.compile('^(?P<tval>-?\d+(\.\d*))(s|)$', re.I), float, 1),