linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: avidanborisov@gmail.com
To: linux-trace-devel@vger.kernel.org
Cc: Avidan Borisov <avidanborisov@gmail.com>
Subject: [PATCH 3/3] trace-cmd record: Create a pidfile when using --daemonize
Date: Mon,  1 May 2023 23:31:18 +0300	[thread overview]
Message-ID: <20230501203118.3105605-4-avidanborisov@gmail.com> (raw)
In-Reply-To: <20230501203118.3105605-1-avidanborisov@gmail.com>

From: Avidan Borisov <avidanborisov@gmail.com>

When used with --daemonize, create a pidfile at
/var/run/trace-cmd-record.pid during the duration
of the recording, and delete it after we're done.

Signed-off-by: Avidan Borisov <avidanborisov@gmail.com>
---
 Documentation/trace-cmd/trace-cmd-record.1.txt |  1 +
 tracecmd/trace-record.c                        | 13 +++++++++++++
 tracecmd/trace-usage.c                         |  4 +++-
 3 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/Documentation/trace-cmd/trace-cmd-record.1.txt b/Documentation/trace-cmd/trace-cmd-record.1.txt
index 366ab46..0c9a914 100644
--- a/Documentation/trace-cmd/trace-cmd-record.1.txt
+++ b/Documentation/trace-cmd/trace-cmd-record.1.txt
@@ -420,6 +420,7 @@ OPTIONS
 
 *--daemonize*
     Run trace-cmd in the background as a daemon after recording has started.
+    Creates a pidfile at /var/run/trace-cmd-record.pid with the pid of trace-cmd during the recording.
 
 EXAMPLES
 --------
diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c
index 0eee8dd..85ad808 100644
--- a/tracecmd/trace-record.c
+++ b/tracecmd/trace-record.c
@@ -46,6 +46,8 @@
 #define _STR(x) #x
 #define STR(x) _STR(x)
 
+#define RECORD_PIDFILE	"trace-cmd-record.pid"
+
 #define TRACE_CTRL	"tracing_on"
 #define TRACE		"trace"
 #define AVAILABLE	"available_tracers"
@@ -93,6 +95,8 @@ static bool fork_process;
 
 static bool do_daemonize;
 
+static bool created_pidfile;
+
 /* Max size to let a per cpu file get */
 static int max_kb;
 
@@ -648,6 +652,9 @@ void die(const char *fmt, ...)
 	else
 		ret = -1;
 
+	if (created_pidfile)
+		remove_pid_file(RECORD_PIDFILE);
+
 	kill_threads();
 	va_start(ap, fmt);
 	fprintf(stderr, "  ");
@@ -1739,6 +1746,9 @@ static void daemonize_finish(void)
 
 	if (kill(getppid(), SIGRTMIN) == -1)
 		die("daemonize: kill");
+
+	make_pid_file(RECORD_PIDFILE);
+	created_pidfile = true;
 }
 
 static void trace_or_sleep(enum trace_type type, bool pwait)
@@ -7190,6 +7200,9 @@ static void record_trace(int argc, char **argv,
 
 	destroy_stats();
 	finalize_record_trace(ctx);
+
+	if (created_pidfile)
+		remove_pid_file(RECORD_PIDFILE);
 }
 
 /*
diff --git a/tracecmd/trace-usage.c b/tracecmd/trace-usage.c
index 0630e8e..2e5d861 100644
--- a/tracecmd/trace-usage.c
+++ b/tracecmd/trace-usage.c
@@ -81,7 +81,9 @@ static struct usage_help usage_help[] = {
 		"                        available algorithms can be listed with trace-cmd list -c\n"
 		"          --proxy vsocket to reach the agent. Acts the same as -A (for an agent)\n"
 		"              but will send the proxy connection to the agent.\n"
-		"          --daemonize run trace-cmd in the background as a daemon after recording has started\n"
+		"          --daemonize run trace-cmd in the background as a daemon after recording has started.\n"
+		"                      creates a pidfile at /var/run/trace-cmd-record.pid with the pid of trace-cmd\n"
+		"                      during the recording.\n"
 	},
 	{
 		"set",
-- 
2.25.1


  parent reply	other threads:[~2023-05-01 20:32 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-01 20:31 [PATCH 0/3] trace-cmd record: Support daemonization after recording starts avidanborisov
2023-05-01 20:31 ` [PATCH 1/3] trace-cmd record: Add --daemonize avidanborisov
2023-05-30  8:55   ` Steven Rostedt
2023-05-01 20:31 ` [PATCH 2/3] trace-cmd: export pidfile functions from trace-listen.c avidanborisov
2023-05-01 20:31 ` avidanborisov [this message]
2023-05-30  8:51 ` [PATCH 0/3] trace-cmd record: Support daemonization after recording starts Steven Rostedt
2023-06-26  9:16   ` [PATCH v2 0/4] trace-cmd record: Improvements to --daemonize option avidanborisov
2023-06-26  9:16     ` [PATCH v2 1/4] trace-cmd record: Add --daemonize avidanborisov
2023-07-06  0:13       ` Steven Rostedt
2023-07-06  0:19       ` Steven Rostedt
2023-06-26  9:16     ` [PATCH v2 2/4] trace-cmd: export pidfile functions from trace-listen.c avidanborisov
2023-06-26  9:16     ` [PATCH v2 3/4] trace-cmd record: Create a pidfile when using --daemonize avidanborisov
2023-06-26  9:16     ` [PATCH v2 4/4] trace-cmd record: Add --daemonize example to man page avidanborisov
2023-07-02  1:39     ` [PATCH v2 0/4] trace-cmd record: Improvements to --daemonize option Steven Rostedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230501203118.3105605-4-avidanborisov@gmail.com \
    --to=avidanborisov@gmail.com \
    --cc=linux-trace-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).