From 64a0e1401f2578b6a2ff958d6782c41e3ea847c8 Mon Sep 17 00:00:00 2001 From: "Yan, Zheng" Date: Mon, 20 Feb 2017 15:39:08 +0800 Subject: [PATCH] ceph_fuse: fix daemonization when pid file is non-empty During daemonizing ceph-fuse, both the parent and child processes call global_init_postfork_start(). global_init_postfork_start() calls pidfile_write(). If pid file is non-empty, one pidfile_write() call fails because it can't lock the pid file. The fix is only child process calls global_init_postfork_start() Signed-off-by: "Yan, Zheng" --- src/ceph_fuse.cc | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/ceph_fuse.cc b/src/ceph_fuse.cc index 5296939711c..824be1272d5 100644 --- a/src/ceph_fuse.cc +++ b/src/ceph_fuse.cc @@ -115,28 +115,32 @@ int main(int argc, const char **argv, const char *envp[]) { cerr << std::endl; } - global_init_prefork(g_ceph_context); Preforker forker; if (g_conf->daemonize) { + global_init_prefork(g_ceph_context); + int r; string err; - if (forker.prefork(err)) { - cerr << "ceph-fuse[" << err << std::endl; - return 1; + r = forker.prefork(err); + if (r < 0 || forker.is_parent()) { + // Start log if current process is about to exit. Otherwise, we hit an assert + // in the Ceph context destructor. + g_ceph_context->_log->start(); + } + if (r < 0) { + cerr << "ceph-fuse " << err << std::endl; + return r; + } + if (forker.is_parent()) { + r = forker.parent_wait(err); + if (r < 0) { + cerr << "ceph-fuse " << err << std::endl; + } + return r; } global_init_postfork_start(cct.get()); } - - if (forker.is_parent()) { - string err; - int r = forker.parent_wait(err); - if (r) { - cerr << "ceph-fuse" << err << std::endl; - } - return r; - } - - if (forker.is_child()) { + { common_init_finish(g_ceph_context); //cout << "child, mounting" << std::endl;