summaryrefslogtreecommitdiff
path: root/kvmd/helpers/otgmsd/unlock/__init__.py
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2019-10-21 03:40:58 +0300
committerDevaev Maxim <[email protected]>2019-10-21 03:40:58 +0300
commitcae86d930264f26f60bfb8c9ce05c524ed6d56d9 (patch)
tree095508352ecdb4fb3c62a5b32ae6ab73e3bced29 /kvmd/helpers/otgmsd/unlock/__init__.py
parent7ee3d585e8386ca59ca7e1804a521f4ad9f8e120 (diff)
improved otg msd
Diffstat (limited to 'kvmd/helpers/otgmsd/unlock/__init__.py')
-rw-r--r--kvmd/helpers/otgmsd/unlock/__init__.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/kvmd/helpers/otgmsd/unlock/__init__.py b/kvmd/helpers/otgmsd/unlock/__init__.py
index 9bdf353f..88832d66 100644
--- a/kvmd/helpers/otgmsd/unlock/__init__.py
+++ b/kvmd/helpers/otgmsd/unlock/__init__.py
@@ -31,12 +31,17 @@ _PROCESS_NAME = "file-storage"
# =====
+def _log(msg: str) -> None:
+ print(msg, file=sys.stderr)
+
+
def _unlock() -> None:
# https://github.com/torvalds/linux/blob/3039fad/drivers/usb/gadget/function/f_mass_storage.c#L2924
found = False
for proc in psutil.process_iter():
- attrs = proc.as_dict(attrs=["name", "exe"])
+ attrs = proc.as_dict(attrs=["name", "exe", "pid"])
if attrs.get("name") == _PROCESS_NAME and not attrs.get("exe"):
+ _log(f"Sending SIGUSR1 to MSD {_PROCESS_NAME!r} kernel thread with pid={attrs['pid']} ...")
try:
proc.send_signal(signal.SIGUSR1)
found = True
@@ -49,6 +54,5 @@ def _unlock() -> None:
# =====
def main() -> None:
if len(sys.argv) != 2 or sys.argv[1] != "unlock":
- raise SystemExit(f"This program interrupts all IO operations performed by OTG MSD.\n\n"
- f"Usage: python -m kvmd.helpers.otgmsd.unlock [-h|--help|unlock]")
+ raise SystemExit(f"Usage: {sys.argv[0]} [unlock]")
_unlock()