config: allow chdir to arbitrary dir on daemonize (not just /)

This lets you configure where your core files go.
This commit is contained in:
Sage Weil 2009-03-10 12:34:23 -07:00
parent d594f91d8d
commit 4c62970abf
7 changed files with 20 additions and 8 deletions

View File

@ -50,7 +50,7 @@ int main(int argc, const char **argv, const char *envp[]) {
vec_to_argv(args, argc, argv);
// FUSE will chdir("/"); be ready.
g_conf.chdir_root = true;
g_conf.chdir = "/";
if (g_conf.clock_tare) g_clock.tare();

View File

@ -115,7 +115,7 @@ void Logger::_open_log()
return;
filename = "";
if (g_conf.chdir_root && g_conf.logger_dir[0] != '/') {
if (g_conf.chdir && g_conf.chdir[0] && g_conf.logger_dir[0] != '/') {
char cwd[200];
getcwd(cwd, 200);
filename = cwd;

View File

@ -359,7 +359,7 @@ static struct config_option config_optionsp[] = {
OPTION(global, conf_file, 'c', STR, INSTALL_PREFIX "/etc/ceph/ceph.conf"),
OPTION(global, cluster_conf_file, 'C', STR, INSTALL_PREFIX "/etc/ceph/cluster.conf"),
OPTION(global, dump_conf, 0, BOOL, false),
OPTION(global, chdir_root, 0, BOOL, true), // chdir("/") after daemonizing. if true, we generate absolute paths as needed.
OPTION(global, chdir, 0, STR, "/"),
OPTION(global, fake_clock, 0, BOOL, false),
OPTION(global, fakemessenger_serialize, 0, BOOL, true),
OPTION(global, kill_after, 0, INT, 0),

View File

@ -68,7 +68,7 @@ struct md_config_t {
const char *cluster_conf_file;
bool dump_conf;
bool chdir_root;
const char *chdir;
bool fake_clock;
bool fakemessenger_serialize;

View File

@ -63,7 +63,7 @@ int MonitorStore::mount()
return -errno;
}
if (g_conf.chdir_root && dir[0] != '/') {
if (g_conf.chdir && g_conf.chdir[0] && dir[0] != '/') {
// combine it with the cwd, in case fuse screws things up (i.e. fakefuse)
string old = dir;
char cwd[200];

View File

@ -388,8 +388,20 @@ int Rank::start(bool nodaemon)
}
dout(1) << "rank.start daemonizing" << dendl;
::daemon(!g_conf.chdir_root, 0);
write_pid_file(getpid());
pid_t pid = fork();
if (pid) {
// i am parent
write_pid_file(pid);
::close(0);
::close(1);
::close(2);
_exit(0);
}
if (g_conf.chdir && g_conf.chdir[0]) {
::mkdir(g_conf.chdir, 0700);
::chdir(g_conf.chdir);
}
_dout_rename_output_file();
} else {

View File

@ -6,5 +6,5 @@
log dir = out
log sym dir = out
logger dir = log
chdir root = false
chdir = ""