aboutsummaryrefslogtreecommitdiffstats
path: root/lib/bb/utils.py
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2015-09-08 23:31:13 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-09-08 23:45:03 +0100
commit34974f5e30e9b09c016481e4c81c156a5f379784 (patch)
treec5f7e4724441724054077ea852fdeee01fec7fa4 /lib/bb/utils.py
parent1032ddddbe3241da02ebb3608a1c40f9123b9e80 (diff)
downloadbitbake-34974f5e30e9b09c016481e4c81c156a5f379784.tar.gz
utils: Add signal_on_parent_exit() function
Add a new bb.utils.signal_on_parent_exit() function so that a process can register to recieve a signal when the parent dies. There is no POSIX standard for this and the implementation is Linux specific. Alternatives would be having an open pipe or polling os.getppid() for changes but this seems more effective and less invasive to most of bitbake's code structure. We need to be able to determine when parents die to ensure child processes stop running in a variety of circumstances to avoid locks being held and ensure clean shutdown. Roughly based on https://gist.github.com/evansd/2346614 Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'lib/bb/utils.py')
-rw-r--r--lib/bb/utils.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/bb/utils.py b/lib/bb/utils.py
index b62985dd7..91faa494c 100644
--- a/lib/bb/utils.py
+++ b/lib/bb/utils.py
@@ -35,6 +35,8 @@ import errno
import signal
from commands import getstatusoutput
from contextlib import contextmanager
+from ctypes import cdll
+
logger = logging.getLogger("BitBake.Util")
@@ -1291,3 +1293,20 @@ def get_file_layer(filename, d):
result = path_to_layer(filename)
return result
+
+
+# Constant taken from http://linux.die.net/include/linux/prctl.h
+PR_SET_PDEATHSIG = 1
+
+class PrCtlError(Exception):
+ pass
+
+def signal_on_parent_exit(signame):
+ """
+ Trigger signame to be sent when the parent process dies
+ """
+ signum = getattr(signal, signame)
+ # http://linux.die.net/man/2/prctl
+ result = cdll['libc.so.6'].prctl(PR_SET_PDEATHSIG, signum)
+ if result != 0:
+ raise PrCtlError('prctl failed with error code %s' % result)