• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2016 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#      http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15"""Signal related functionality."""
16
17import os
18import signal
19import sys
20
21_path = os.path.realpath(__file__ + '/../..')
22if sys.path[0] != _path:
23    sys.path.insert(0, _path)
24del _path
25
26
27def relay_signal(handler, signum, frame):
28    """Notify a listener returned from getsignal of receipt of a signal.
29
30    Returns:
31      True if it was relayed to the target, False otherwise.
32      False in particular occurs if the target isn't relayable.
33    """
34    if handler in (None, signal.SIG_IGN):
35        return True
36    if handler == signal.SIG_DFL:
37        # This scenario is a fairly painful to handle fully, thus we just
38        # state we couldn't handle it and leave it to client code.
39        return False
40    handler(signum, frame)
41    return True
42