chdir_ = false;
}
+/* Will we chdir to "/" as part of daemonizing? */
+bool
+is_chdir_enabled(void)
+{
+ return chdir_;
+}
+
/* Normally, die_if_already_running() will terminate the program with a message
* if a locked pidfile already exists. If this function is called,
* die_if_already_running() will merely log a warning. */
detach = true;
}
+/* Will daemonize() really detach? */
+bool
+get_detach(void)
+{
+ return detach;
+}
+
/* If a pidfile has been configured and that pidfile already exists and is
* locked by a running process, returns the pid of the running process.
* Otherwise, returns 0. */
/*
- * Copyright (c) 2008 Nicira Networks.
+ * Copyright (c) 2008, 2009 Nicira Networks.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
void set_pidfile(const char *name);
const char *get_pidfile(void);
void set_no_chdir(void);
+bool is_chdir_enabled(void);
void set_detach(void);
+bool get_detach(void);
void daemonize(void);
void die_if_already_running(void);
void ignore_existing_pidfile(void);
#include <errno.h>
#include <getopt.h>
#include <signal.h>
+#include <unistd.h>
#include "command-line.h"
#include "daemon.h"
struct ovsdb *db;
const char *name;
char *file_name;
+ bool do_chdir;
int retval;
size_t i;
parse_options(argc, argv, &file_name, &active, &passive);
+ if (get_detach() && is_chdir_enabled()) {
+ /* We need to skip chdir("/") in daemonize() and do it later, because
+ * we need to open the database and possible set up up Unix domain
+ * sockets in the current working directory after we daemonize. We
+ * can't open the database before we daemonize because file locks
+ * aren't inherited by child processes. */
+ do_chdir = true;
+ set_no_chdir();
+ } else {
+ do_chdir = false;
+ }
+ die_if_already_running();
+ daemonize();
+
error = ovsdb_file_open(file_name, false, &db);
if (error) {
ovs_fatal(0, "%s", ovsdb_error_to_string(error));
svec_destroy(&active);
svec_destroy(&passive);
- die_if_already_running();
- daemonize();
-
retval = unixctl_server_create(NULL, &unixctl);
if (retval) {
ovs_fatal(retval, "could not listen for control connections");
}
+ if (do_chdir) {
+ chdir("/");
+ }
for (;;) {
ovsdb_jsonrpc_server_run(jsonrpc);
unixctl_server_run(unixctl);