From 89c42d3a4083fd47da8cca82e5f5b7ee6e74f791 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Fri, 8 Jul 2022 12:24:20 +0200 Subject: bin/udev_match: make sure to terminate the child on exit --- bin/udev_match | 28 ++++++++++++++++++---------- 1 file 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) -- cgit v1.2.3