Skip to content

Commit

Permalink
debug pidfile
Browse files Browse the repository at this point in the history
Signed-off-by: zhangzujian <[email protected]>
  • Loading branch information
zhangzujian committed Nov 14, 2023
1 parent 6a29598 commit b68783f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
8 changes: 6 additions & 2 deletions lib/daemon-unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <config.h>
#include "backtrace.h"
#include "daemon.h"
#include "daemon-private.h"
// #include "daemon-private.h"
#include <errno.h>
#include <fcntl.h>
#include <grp.h>
Expand All @@ -29,6 +29,7 @@
#include <sys/wait.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/types.h>
#if HAVE_LIBCAPNG
#include <cap-ng.h>
#endif
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion lib/daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include "util.h"
#include "ovs-thread.h"
#include "openvswitch/vlog.h"
Expand Down Expand Up @@ -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. */
Expand Down
1 change: 1 addition & 0 deletions lib/ovs-thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b68783f

Please sign in to comment.