From b68783f7405f6b244a834228f56b0d5be2007742 Mon Sep 17 00:00:00 2001 From: zhangzujian Date: Tue, 14 Nov 2023 07:12:23 +0000 Subject: [PATCH] debug pidfile Signed-off-by: zhangzujian --- lib/daemon-unix.c | 8 ++++++-- lib/daemon.c | 13 ++++++++++++- lib/ovs-thread.c | 1 + 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/daemon-unix.c b/lib/daemon-unix.c index 1a7ba427d7a..a218ab4e384 100644 --- a/lib/daemon-unix.c +++ b/lib/daemon-unix.c @@ -17,7 +17,7 @@ #include #include "backtrace.h" #include "daemon.h" -#include "daemon-private.h" +// #include "daemon-private.h" #include #include #include @@ -29,6 +29,7 @@ #include #include #include +#include #if HAVE_LIBCAPNG #include #endif @@ -62,7 +63,7 @@ bool detach; /* Was --detach specified? */ static bool detached; /* Have we already detached? */ /* --pidfile: Name of pidfile (null if none). */ -char *pidfile; +char *pidfile = NULL; /* Device and inode of pidfile, so we can avoid reopening it. */ static dev_t pidfile_dev; @@ -490,6 +491,9 @@ daemonize_start(bool access_datapath) if (pidfile) { make_pidfile(); + } else { + pid_t tid = gettid(); + VLOG_WARN("pidfile %p in thread %u is NULL", &pidfile, tid); } /* Make sure that the unixctl commands for vlog get registered in a diff --git a/lib/daemon.c b/lib/daemon.c index 3249c5ab4b5..7aa25b7493c 100644 --- a/lib/daemon.c +++ b/lib/daemon.c @@ -19,6 +19,7 @@ #include #include #include +#include #include "util.h" #include "ovs-thread.h" #include "openvswitch/vlog.h" @@ -61,9 +62,19 @@ daemonize(void) void set_pidfile(const char *name) { + printf("set_pidfile(%s)\n", name); + VLOG_WARN("set_pidfile(%s)", name); assert_single_threaded(); - free(pidfile); + if (pidfile) { + printf("current pidfile is \"%s\"\n", pidfile); + free(pidfile); + } else { + printf("current pidfile is NULL\n"); + } pidfile = make_pidfile_name(name); + pid_t tid = gettid(); + VLOG_WARN("pidfile %p in thread %u is set to %s", &pidfile, tid, pidfile); + printf("pidfile %p in thread %u is set to %s\n", &pidfile, tid, pidfile); } /* Disables self confinement. */ diff --git a/lib/ovs-thread.c b/lib/ovs-thread.c index ac5d2c3d029..de66cc8b06e 100644 --- a/lib/ovs-thread.c +++ b/lib/ovs-thread.c @@ -559,6 +559,7 @@ xfork_at(const char *where) if (pid < 0) { VLOG_FATAL("%s: fork failed (%s)", where, ovs_strerror(errno)); } + VLOG_INFO("xfork_at(%s)", where); return pid; } #endif