]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph_mon: split postfork() in two and finish postfork just before daemonize
authorJoao Eduardo Luis <joao.luis@inktank.com>
Fri, 14 Mar 2014 17:39:00 +0000 (17:39 +0000)
committerJoao Eduardo Luis <joao.luis@inktank.com>
Fri, 14 Mar 2014 17:39:00 +0000 (17:39 +0000)
We split global_init_postfork() in two: start and finish, with the first
keeping much of postfork()'s tasks except closing stderr, which we leave
open until just before we daemonize.  This allows the user to see any
error messages that the monitor may spit out before it daemonizes, making
sense of the error code (which we were already returning).

Fixes: 7489
Signed-off-by: Joao Eduardo Luis <joao.luis@inktank.com>
src/ceph_mon.cc
src/global/global_init.cc
src/global/global_init.h

index f9752b4ca0e86a34793ab56b9198b7205d0b5d55..d5e154ca8581ce9d7903adc42f682233fc106df5 100644 (file)
@@ -412,7 +412,7 @@ int main(int argc, const char **argv)
       if (prefork.is_parent()) {
        return prefork.parent_wait();
       }
-      global_init_postfork(g_ceph_context, 0);
+      global_init_postfork_start(g_ceph_context);
     }
     common_init_finish(g_ceph_context);
     global_init_chdir(g_ceph_context);
@@ -655,8 +655,10 @@ int main(int argc, const char **argv)
     derr << "done compacting" << dendl;
   }
 
-  if (g_conf->daemonize)
+  if (g_conf->daemonize) {
+    global_init_postfork_finish(g_ceph_context, 0);
     prefork.daemonize();
+  }
 
   messenger->start();
 
index e96c317f820718afb41bec871df5e55d6e5408ad..5e56e8f808be55d7c2c433cd0fdb4688a9b298fb 100644 (file)
@@ -180,10 +180,11 @@ void global_init_daemonize(CephContext *cct, int flags)
     exit(1);
   }
 
-  global_init_postfork(cct, flags);
+  global_init_postfork_start(cct);
+  global_init_postfork_finish(cct, flags);
 }
 
-void global_init_postfork(CephContext *cct, int flags)
+void global_init_postfork_start(CephContext *cct)
 {
   // restart log thread
   g_ceph_context->_log->start();
@@ -215,6 +216,16 @@ void global_init_postfork(CephContext *cct, int flags)
         << err << dendl;
     exit(1);
   }
+
+  pidfile_write(g_conf);
+}
+
+void global_init_postfork_finish(CephContext *cct, int flags)
+{
+  /* We only close stderr once the caller decides the daemonization
+   * process is finished.  This way we can allow error messages to be
+   * propagated in a manner that the user is able to see.
+   */
   if (!(flags & CINIT_FLAG_NO_CLOSE_STDERR)) {
     int ret = global_init_shutdown_stderr(cct);
     if (ret) {
@@ -223,10 +234,10 @@ void global_init_postfork(CephContext *cct, int flags)
       exit(1);
     }
   }
-  pidfile_write(g_conf);
   ldout(cct, 1) << "finished global_init_daemonize" << dendl;
 }
 
+
 void global_init_chdir(const CephContext *cct)
 {
   const md_config_t *conf = cct->_conf;
index d2ba6ef9dedb2818c9db6ba7d18bc13c29ccbf47..67586e44699d48572897135763d68146e1b059c4 100644 (file)
@@ -41,10 +41,16 @@ void global_init(std::vector < const char * > *alt_def_args, std::vector < const
 int global_init_prefork(CephContext *cct, int flags);
 
 /*
- * perform all of the steps that global_init_daemonize performs just after
- * the fork.
+ * perform all the steps that global_init_daemonize performs just after
+ * the fork, except closing stderr, which we'll do later on.
  */
-void global_init_postfork(CephContext *cct, int flags);
+void global_init_postfork_start(CephContext *cct);
+
+/*
+ * close stderr, thus completing the postfork.
+ */
+void global_init_postfork_finish(CephContext *cct, int flags);
+
 
 /*
  * global_init_daemonize handles daemonizing a process.