From: Yan, Zheng Date: Mon, 20 Feb 2017 07:39:08 +0000 (+0800) Subject: ceph_fuse: fix daemonization when pid file is non-empty X-Git-Tag: v12.0.1~239^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=64a0e1401f2578b6a2ff958d6782c41e3ea847c8;p=ceph.git 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" --- diff --git a/src/ceph_fuse.cc b/src/ceph_fuse.cc index 5296939711c7..824be1272d5b 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(); } - 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; + 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; } - return r; + global_init_postfork_start(cct.get()); } - if (forker.is_child()) { + { common_init_finish(g_ceph_context); //cout << "child, mounting" << std::endl;