summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2022-07-08 12:24:20 +0200
committerAnton Khirnov <anton@khirnov.net>2022-07-08 12:24:20 +0200
commit89c42d3a4083fd47da8cca82e5f5b7ee6e74f791 (patch)
tree86255c1496338586650c42c32c9bd9909e6f37ac
parent18dbadf1a02b797acb4a99b2670b022462664dd3 (diff)
bin/udev_match: make sure to terminate the child on exit
-rwxr-xr-xbin/udev_match28
1 files changed, 18 insertions, 10 deletions
diff --git a/bin/udev_match b/bin/udev_match
index de51650..57cbb02 100755
--- a/bin/udev_match
+++ b/bin/udev_match
@@ -2,6 +2,7 @@
import argparse
import subprocess
+import time
parser = argparse.ArgumentParser(description = 'Run a command on matching udev events')
@@ -24,16 +25,23 @@ if args.subsystem:
child = subprocess.Popen(cmdline, text = True, stdout = subprocess.PIPE)
-# skip first three lines
-[child.stdout.readline() for i in range(3)]
+try:
+ # skip first three lines
+ [child.stdout.readline() for i in range(3)]
-buf = []
+ buf = []
-while child.poll() is None:
- line = child.stdout.readline().strip()
- if not line:
- process_buf(buf)
- buf.clear()
- continue
+ while child.poll() is None:
+ line = child.stdout.readline().strip()
+ if not line:
+ process_buf(buf)
+ buf.clear()
+ continue
+
+ buf.append(line)
+finally:
+ child.terminate()
+ if child.returncode is None:
+ time.sleep(0.1)
+ child.kill()
- buf.append(line)