forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathowned_child.py
More file actions
34 lines (25 loc) · 1012 Bytes
/
Copy pathowned_child.py
File metadata and controls
34 lines (25 loc) · 1012 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"""Marker-bearing child guard for fail-closed dev-harness ownership."""
from __future__ import annotations
import argparse
import signal
import subprocess
_child: subprocess.Popen[bytes] | None = None
def _forward(signum: int, _frame: object) -> None:
if _child is not None and _child.poll() is None:
_child.send_signal(signum)
def main(argv: list[str] | None = None) -> int:
parser = argparse.ArgumentParser()
parser.add_argument("--marker", required=True)
parser.add_argument("--service", required=True)
parser.add_argument("command", nargs=argparse.REMAINDER)
args = parser.parse_args(argv)
command = args.command[1:] if args.command[:1] == ["--"] else args.command
if not command:
parser.error("command is required after --")
signal.signal(signal.SIGTERM, _forward)
signal.signal(signal.SIGINT, _forward)
global _child
_child = subprocess.Popen(command)
return _child.wait()
if __name__ == "__main__":
raise SystemExit(main())