All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] trace-cmd: Cleanups for --daemonize option
@ 2023-10-17 23:20 Steven Rostedt
  2023-10-17 23:20 ` [PATCH 1/2] trace-cmd record: Use SIGTERM as well for --daemonize Steven Rostedt
  2023-10-17 23:20 ` [PATCH 2/2] trace-cmd record: Cleanup - be consistent with return status variable Steven Rostedt
  0 siblings, 2 replies; 3+ messages in thread
From: Steven Rostedt @ 2023-10-17 23:20 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: Avidan Borisov, Ross Zwisler, Steven Rostedt (Google)

From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

Just a few clean ups for the --daemonize option that I plan on committing
upstream soon. This is based on:

  https://lore.kernel.org/all/20230626091635.3002827-1-avidanborisov@gmail.com/

The first patch lets the daemon be killed with SIGTERM as well as with SIGINT,
as that's the default of "kill" without any option.

The second patch just renames a variable from "rc" to "ret" to be consistent
with the rest of the code.

Steven Rostedt (Google) (2):
  trace-cmd record: Use SIGTERM as well for --daemonize
  trace-cmd record: Cleanup - be consistent with return status variable

 tracecmd/trace-record.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

-- 
2.42.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] trace-cmd record: Use SIGTERM as well for --daemonize
  2023-10-17 23:20 [PATCH 0/2] trace-cmd: Cleanups for --daemonize option Steven Rostedt
@ 2023-10-17 23:20 ` Steven Rostedt
  2023-10-17 23:20 ` [PATCH 2/2] trace-cmd record: Cleanup - be consistent with return status variable Steven Rostedt
  1 sibling, 0 replies; 3+ messages in thread
From: Steven Rostedt @ 2023-10-17 23:20 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: Avidan Borisov, Ross Zwisler, Steven Rostedt (Google)

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 --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");
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] trace-cmd record: Cleanup - be consistent with return status variable
  2023-10-17 23:20 [PATCH 0/2] trace-cmd: Cleanups for --daemonize option Steven Rostedt
  2023-10-17 23:20 ` [PATCH 1/2] trace-cmd record: Use SIGTERM as well for --daemonize Steven Rostedt
@ 2023-10-17 23:20 ` Steven Rostedt
  1 sibling, 0 replies; 3+ messages in thread
From: Steven Rostedt @ 2023-10-17 23:20 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: Avidan Borisov, Ross Zwisler, Steven Rostedt (Google)

From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

The variable that checks return status in daemonize_start() is "rc". To be
consistent with the rest of the code, change it to "ret".

Also check for less than zero instead of -1.

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

diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c
index c943f486291e..022c27ffc294 100644
--- a/tracecmd/trace-record.c
+++ b/tracecmd/trace-record.c
@@ -1655,7 +1655,7 @@ static void daemonize_start(void)
 	int devnull;
 	int status;
 	int pid;
-	int rc;
+	int ret;
 
 	pid = fork();
 	if (pid == -1)
@@ -1719,12 +1719,12 @@ static void daemonize_start(void)
 			die("daemonize: sigaction failed");
 
 		do {
-			rc = waitpid(pid, &status, 0);
-		} while (!child_detached && ((rc == -1) && (errno == EINTR)));
+			ret = waitpid(pid, &status, 0);
+		} while (!child_detached && ((ret < 0) && (errno == EINTR)));
 
 		if (child_detached)
 			exit(0);
-		else if (rc == pid)
+		else if (ret == pid)
 			exit(WIFEXITED(status));
 		else
 			die("daemonize: waitpid failed");
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-10-17 23:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-17 23:20 [PATCH 0/2] trace-cmd: Cleanups for --daemonize option Steven Rostedt
2023-10-17 23:20 ` [PATCH 1/2] trace-cmd record: Use SIGTERM as well for --daemonize Steven Rostedt
2023-10-17 23:20 ` [PATCH 2/2] trace-cmd record: Cleanup - be consistent with return status variable Steven Rostedt

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.