diff mbox series

[5/6] v4l2-tracer: stop waiting to handle a signal

Message ID 2297fc0ea49ad201d213950c7f32d7ab5e998163.1701390439.git.deborah.brouwer@collabora.com (mailing list archive)
State New, archived
Headers show
Series v4l2-tracer: misc fixes and improvements | expand

Commit Message

Deborah Brouwer Dec. 1, 2023, 12:46 a.m. UTC
Usually the v4l2-tracer will wait for its tracee to handle a signal e.g.
from ctrl+c before the v4l2-tracer exits, but if there is no tracee,
then the v4l2-tracer waits forever.

Exit gracefully by waiting only if a tracee exists.

Signed-off-by: Deborah Brouwer <deborah.brouwer@collabora.com>
---
 utils/v4l2-tracer/v4l2-tracer.cpp | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/utils/v4l2-tracer/v4l2-tracer.cpp b/utils/v4l2-tracer/v4l2-tracer.cpp
index 37e17eb6..05e5b368 100644
--- a/utils/v4l2-tracer/v4l2-tracer.cpp
+++ b/utils/v4l2-tracer/v4l2-tracer.cpp
@@ -16,9 +16,12 @@  pid_t tracee_pid = 0;
 void v4l2_tracer_sig_handler(int signum)
 {
 	line_info("\n\tReceived signum: %d", signum);
-	kill(tracee_pid, signum);
-	/* Wait for tracee to handle the signal first before v4l2-tracer exits. */
-	wait(nullptr);
+
+	/* If there is a tracee, wait for it to handle the signal first before exiting. */
+	if (tracee_pid) {
+		kill(tracee_pid, signum);
+		wait(nullptr);
+	}
 }
 
 enum Options {