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