-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
connection: Support all signals in BackgroundCommand.send_signal()
Support sending any signal to background commands, instead of only supporting properly SIGKILL/SIGTERM/SIGQUIT. The main issue is figuring out what PID to send the signal to, as the devlib API allows running a whole snippet of shell script that typically is wrapped under many layers of sh -c and sudo calls. In order to lift the ambiguity, the user has access to a "devlib-signal-target" command that points devlib at what process should be the target of signals: # Run a "setup" command, then the main command that will receive the # signals cmd = 'echo setup; devlib-signal-target echo hello world' with target.background(cmd) as bg: bg.communicate() The devlib-signal-target script can only be used once per background command, so that it is never ambiguous what process is targeted, and so that the Python code can cache the target PID. Subsequent invocations of devlib-signal-target will fail.
- Loading branch information
1 parent
de84a08
commit 50e7a40
Showing
6 changed files
with
297 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
( | ||
# If there is no data dir, it means we are not running as a background | ||
# command so we just do nothing | ||
if [ -e "$_DEVLIB_BG_CMD_DATA_DIR" ]; then | ||
pid_file="$_DEVLIB_BG_CMD_DATA_DIR/pid" | ||
# Atomically check if the PID file already exist and make the write | ||
# fail if it already does. This way we don't have any race condition | ||
# with the Python API, as there is either no PID or the same PID for | ||
# the duration of the command | ||
set -o noclobber | ||
if ! printf "%u\n" $$ > "$pid_file"; then | ||
echo "$0 was already called for this command" >&2 | ||
exit 1 | ||
fi | ||
fi | ||
) || exit $? | ||
|
||
# Use exec so that the PID of the command we run is the same as the current $$ | ||
# PID that we just registered | ||
exec "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.