]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
ceph_fuse: fix daemonization when pid file is non-empty
authorYan, Zheng <zyan@redhat.com>
Mon, 20 Feb 2017 07:39:08 +0000 (15:39 +0800)
committerYan, Zheng <zyan@redhat.com>
Thu, 23 Feb 2017 07:28:20 +0000 (15:28 +0800)
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" <zyan@redhat.com>
src/ceph_fuse.cc

index 5296939711c7235748f71263297ea039cd2755c1..824be1272d5b54267fd55fbbb30ce1f72e0223e6 100644 (file)
@@ -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;