From: avidanborisov@gmail.com
To: linux-trace-devel@vger.kernel.org
Cc: rostedt@goodmis.org, avidanborisov@gmail.com
Subject: [PATCH v2 2/4] trace-cmd: export pidfile functions from trace-listen.c
Date: Mon, 26 Jun 2023 12:16:33 +0300 [thread overview]
Message-ID: <20230626091635.3002827-3-avidanborisov@gmail.com> (raw)
In-Reply-To: <20230626091635.3002827-1-avidanborisov@gmail.com>
From: Avidan Borisov <avidanborisov@gmail.com>
trace-listen.c has some utility functions for creating and removing
pidfiles, to avoid code duplication we make those functions generic
and export them to the rest of the codebase.
Signed-off-by: Avidan Borisov <avidanborisov@gmail.com>
---
tracecmd/include/trace-local.h | 4 ++++
tracecmd/trace-listen.c | 32 ++++++++++++++------------------
2 files changed, 18 insertions(+), 18 deletions(-)
diff --git a/tracecmd/include/trace-local.h b/tracecmd/include/trace-local.h
index 8f18f6d..33397b1 100644
--- a/tracecmd/include/trace-local.h
+++ b/tracecmd/include/trace-local.h
@@ -461,4 +461,8 @@ static inline bool is_digits(const char *s)
bool trace_tsc2nsec_is_supported(void);
+void make_pid_name(char *buf, const char *pidfile_basename);
+void remove_pid_file(const char *pidfile_basename);
+void make_pid_file(const char *pidfile_basename);
+
#endif /* __TRACE_LOCAL_H */
diff --git a/tracecmd/trace-listen.c b/tracecmd/trace-listen.c
index e95c571..5894a92 100644
--- a/tracecmd/trace-listen.c
+++ b/tracecmd/trace-listen.c
@@ -34,6 +34,8 @@
#define VAR_RUN_DIR VAR_DIR_Q(VAR_DIR) "/run"
+#define LISTEN_PIDFILE "trace-cmd-net.pid"
+
static char *default_output_dir = ".";
static char *output_dir;
static char *default_output_file = "trace";
@@ -52,7 +54,8 @@ static bool done;
#define pdie(fmt, ...) \
do { \
tracecmd_plog_error(fmt, ##__VA_ARGS__);\
- remove_pid_file(); \
+ if (do_daemon) \
+ remove_pid_file(LISTEN_PIDFILE);\
exit(-1); \
} while (0)
@@ -126,21 +129,16 @@ static void finish(int sig)
done = true;
}
-static void make_pid_name(int mode, char *buf)
+void make_pid_name(char *buf, const char *pidfile_basename)
{
- snprintf(buf, PATH_MAX, VAR_RUN_DIR "/trace-cmd-net.pid");
+ snprintf(buf, PATH_MAX, VAR_RUN_DIR "/%s", pidfile_basename);
}
-static void remove_pid_file(void)
+void remove_pid_file(const char *pidfile_basename)
{
char buf[PATH_MAX];
- int mode = do_daemon;
-
- if (!do_daemon)
- return;
-
- make_pid_name(mode, buf);
+ make_pid_name(buf, pidfile_basename);
unlink(buf);
}
@@ -991,16 +989,12 @@ static void do_accept_loop(int sfd)
clean_up();
}
-static void make_pid_file(void)
+void make_pid_file(const char *pidfile_basename)
{
char buf[PATH_MAX];
- int mode = do_daemon;
int fd;
- if (!do_daemon)
- return;
-
- make_pid_name(mode, buf);
+ make_pid_name(buf, pidfile_basename);
fd = open(buf, O_WRONLY | O_CREAT | O_TRUNC, 0644);
if (fd < 0) {
@@ -1075,7 +1069,8 @@ static void do_listen(char *port)
if (!tracecmd_get_debug())
signal_setup(SIGCHLD, sigstub);
- make_pid_file();
+ if (do_daemon)
+ make_pid_file(LISTEN_PIDFILE);
if (use_vsock)
sfd = get_vsock(port);
@@ -1090,7 +1085,8 @@ static void do_listen(char *port)
kill_clients();
- remove_pid_file();
+ if (do_daemon)
+ remove_pid_file(LISTEN_PIDFILE);
}
static void start_daemon(void)
--
2.25.1
next prev parent reply other threads:[~2023-06-26 9:20 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 ` [PATCH 3/3] trace-cmd record: Create a pidfile when using --daemonize avidanborisov
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 ` avidanborisov [this message]
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=20230626091635.3002827-3-avidanborisov@gmail.com \
--to=avidanborisov@gmail.com \
--cc=linux-trace-devel@vger.kernel.org \
--cc=rostedt@goodmis.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).