runfvp: Ensure new process group is in the foreground
PATCH 1/1 runfvp: Ensure new process group is in the foreground
From: Peter Hoyes <[email protected]>
When a new process group is created, it is launched in the background and any attempt to access the session terminal triggers a SIGTTIN (for stdin) or SIGTTOU (for stdout) signal. These are ignored in an interactive shell, but the default signal behavior in a new job is to send a SIGTSTP to the whole process group. This causes runfvp to hang when executed via a subprocess when stdin is accessed.
After creating a new process group, use tcsetpgrp to make the new group the foreground process for the terminal associated with stdin/stdout.
The documentation for tcsetgrp states that tcsetpgrp itself raises a SIGTTOU signal, so set this signal to SIG_IGN.
--- scripts/runfvp | 4 ++++ 1 file changed, 4 insertions(+)
scripts/runfvp +4 -0
@@ -4,6 +4,7 @@ import asyncio import json import os import re +import signal import sys import subprocess import pathlib
@@ -220,6 +221,9 @@ if __name__ == "__main__": # Set the process group so that it's possible to kill runfvp and # everything it spawns easily. os.setpgid(0, 0) + signal.signal(signal.SIGTTOU, signal.SIG_IGN) + os.tcsetpgrp(sys.stdin.fileno(), os.getpgrp()) runfvp(sys.argv[1:]) + except KeyboardInterrupt: pass
Signature · 1 line
2.25.1
Breaks in CI, v2 incoming shortly.
Ross
Quoted 56 lines · Ross Burton via lists.yoctoproject.org
From: Peter Hoyes <[email protected]>
When a new process group is created, it is launched in the background and any attempt to access the session terminal triggers a SIGTTIN (for stdin) or SIGTTOU (for stdout) signal. These are ignored in an interactive shell, but the default signal behavior in a new job is to send a SIGTSTP to the whole process group. This causes runfvp to hang when executed via a subprocess when stdin is accessed.
After creating a new process group, use tcsetpgrp to make the new group the foreground process for the terminal associated with stdin/stdout.
The documentation for tcsetgrp states that tcsetpgrp itself raises a SIGTTOU signal, so set this signal to
SIG_IGN.Signed-off-by Peter Hoyes <[email protected]>Change-Id I349a825df7fcb8a3cedb81762b901c6f50fa53b5--- scripts/runfvp | 4 ++++ 1 file changed, 4 insertions(+)scripts/runfvp +4
-1@@ -4,6 +4,7 @@ import asyncio import json import os import re +import signal import sys import subprocess import pathlib@@ -220,6 +221,9 @@ if __name__ == "__main__": # Set the process group so that it's possible to kill runfvp and # everything it spawns easily. os.setpgid(0, 0) + signal.signal(signal.SIGTTOU, signal.SIG_IGN) + os.tcsetpgrp(sys.stdin.fileno(), os.getpgrp()) runfvp(sys.argv[1:]) + except KeyboardInterrupt: pass --2.25.1
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#2289): https://lists.yoctoproject.org/g/meta-arm/message/2289
Mute This Topic: https://lists.yoctoproject.org/mt/86470663/1676615
Group Owner: [email protected]
Unsubscribe: https://lists.yoctoproject.org/g/meta-arm/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-