diff mbox series

[1/2] trace-cmd record: Use SIGTERM as well for --daemonize

Message ID 20231017233503.2205514-2-rostedt@goodmis.org (mailing list archive)
State Accepted
Commit 4f996b33a73e0f847a9e5ce6c46f2773dcac60f3
Headers show
Series trace-cmd: Cleanups for --daemonize option | expand

Commit Message

Steven Rostedt Oct. 17, 2023, 11:20 p.m. UTC
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

Currently --daemonize expects a SIGINT to stop the daemon and build the
trace.dat file. But if the user just does a:

  kill <pid>

it will send a SIGTERM. This will actually kill the process and it will
not create the trace.dat file, leaving a bunch of trace.dat.cpuX files
just lying around.

Update it to also do the same with SIGTERM.

Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 tracecmd/trace-record.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c
index 69a10bf1f0bd..c943f486291e 100644
--- a/tracecmd/trace-record.c
+++ b/tracecmd/trace-record.c
@@ -3344,6 +3344,7 @@  static void do_sig(int sig)
 	case SIGALRM:
 	case SIGUSR1:
 	case SIGINT:
+	case SIGTERM:
 		return finish();
 	case SIGUSR2:
 		return flush();
@@ -3591,6 +3592,7 @@  static int create_recorder(struct buffer_instance *instance, int cpu,
 			return pid;
 
 		signal(SIGINT, SIG_IGN);
+		signal(SIGTERM, SIG_IGN);
 		signal(SIGUSR1, do_sig);
 		signal(SIGUSR2, do_sig);
 		signal(SIGALRM, do_sig);
@@ -7146,6 +7148,7 @@  static void record_trace(int argc, char **argv,
 
 	if (type & (TRACE_TYPE_RECORD | TRACE_TYPE_STREAM)) {
 		signal(SIGINT, do_sig);
+		signal(SIGTERM, do_sig);
 		if (!latency)
 			start_threads(type, ctx);
 	}
@@ -7182,7 +7185,7 @@  static void record_trace(int argc, char **argv,
 
 		if (do_daemonize) {
 			daemonize_finish();
-			printf("Send SIGINT to pid %d to stop recording\n", getpid());
+			printf("Send SIGINT/SIGTERM to pid %d to stop recording\n", getpid());
 		} else {
 			/* sleep till we are woken with Ctrl^C */
 			printf("Hit Ctrl^C to stop recording\n");