diff options
author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2015-09-08 23:31:13 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2015-09-09 14:27:56 +0100 |
commit | 289007e5ebd82e7cf61a20c6afd0206e0037ce0d (patch) | |
tree | 2196b8e402558499cbf2e54c2f9880b4e52de798 /bitbake | |
parent | 384533bdb47af2c3a0f3faea8879e8f3cb6f39f9 (diff) | |
download | poky-289007e5ebd82e7cf61a20c6afd0206e0037ce0d.tar.gz |
bitbake: 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
(Bitbake rev: 34974f5e30e9b09c016481e4c81c156a5f379784)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake')
-rw-r--r-- | bitbake/lib/bb/utils.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py index b62985dd7b..91faa494ca 100644 --- a/bitbake/lib/bb/utils.py +++ b/bitbake/lib/bb/utils.py | |||
@@ -35,6 +35,8 @@ import errno | |||
35 | import signal | 35 | import signal |
36 | from commands import getstatusoutput | 36 | from commands import getstatusoutput |
37 | from contextlib import contextmanager | 37 | from contextlib import contextmanager |
38 | from ctypes import cdll | ||
39 | |||
38 | 40 | ||
39 | logger = logging.getLogger("BitBake.Util") | 41 | logger = logging.getLogger("BitBake.Util") |
40 | 42 | ||
@@ -1291,3 +1293,20 @@ def get_file_layer(filename, d): | |||
1291 | result = path_to_layer(filename) | 1293 | result = path_to_layer(filename) |
1292 | 1294 | ||
1293 | return result | 1295 | return result |
1296 | |||
1297 | |||
1298 | # Constant taken from http://linux.die.net/include/linux/prctl.h | ||
1299 | PR_SET_PDEATHSIG = 1 | ||
1300 | |||
1301 | class PrCtlError(Exception): | ||
1302 | pass | ||
1303 | |||
1304 | def signal_on_parent_exit(signame): | ||
1305 | """ | ||
1306 | Trigger signame to be sent when the parent process dies | ||
1307 | """ | ||
1308 | signum = getattr(signal, signame) | ||
1309 | # http://linux.die.net/man/2/prctl | ||
1310 | result = cdll['libc.so.6'].prctl(PR_SET_PDEATHSIG, signum) | ||
1311 | if result != 0: | ||
1312 | raise PrCtlError('prctl failed with error code %s' % result) | ||