]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
dout: Log version message when (re)opening log
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Thu, 3 Mar 2011 12:30:24 +0000 (04:30 -0800)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Thu, 3 Mar 2011 12:30:24 +0000 (04:30 -0800)
Log a version message whenever we open the dout log, not just the first
time. However, only output it to log files and syslog. Spewing versions
to stderr and stdout was determined to be annoying.

Rename dout_emergency_impl to dout_emergency_to_file_and_syslog to
better reflect its function.

Rename ceph_version_to_string to pretty_version_to_string.

Add get_process_name to do just that. Re-arrange some version.h methods.

Signed-off-by: Colin McCabe <colin.mccabe@dreamhost.com>
Conflicts:

src/common/common_init.cc

src/common/DoutStreambuf.cc
src/common/DoutStreambuf.h
src/common/ceph_argparse.cc
src/common/code_environment.cc
src/common/code_environment.h
src/common/common_init.cc
src/common/debug.cc
src/common/version.cc
src/common/version.h

index 324559c7d93dfb9fad7f444258171a1684bd3eea..cd262dfa515366f7dbfce7755e883130745d563c 100644 (file)
@@ -389,6 +389,21 @@ std::string DoutStreambuf<charT, traits>::config_to_str() const
   return oss.str();
 }
 
+template <typename charT, typename traits>
+void DoutStreambuf<charT, traits>::
+dout_emergency_to_file_and_syslog(const char * const str) const
+{
+  int len = strlen(str);
+  if (ofd >= 0) {
+    if (safe_write(ofd, str, len)) {
+      ; // ignore error code
+    }
+  }
+  if (flags & DOUTSB_FLAG_SYSLOG) {
+    syslog(LOG_USER | LOG_CRIT, "%s", str);
+  }
+}
+
 // This is called to flush the buffer.
 // This is called when we're done with the file stream (or when .flush() is called).
 template <typename charT, typename traits>
@@ -596,21 +611,6 @@ int DoutStreambuf<charT, traits>::_rotate_files(const std::string &base)
   return 0;
 }
 
-template <typename charT, typename traits>
-void DoutStreambuf<charT, traits>::
-dout_emergency_impl(const char * const str) const
-{
-  int len = strlen(str);
-  if (ofd >= 0) {
-    if (safe_write(ofd, str, len)) {
-      ; // ignore error code
-    }
-  }
-  if (flags & DOUTSB_FLAG_SYSLOG) {
-    syslog(LOG_USER | LOG_CRIT, "%s", str);
-  }
-}
-
 /* This function may be called from a signal handler.
  * This function may be called before dout has been initialized.
  */
@@ -627,7 +627,7 @@ void dout_emergency(const char * const str)
   /* Normally we would take the lock before even checking _doss, but since
    * this is an emergency, we can't do that. */
   if (_doss) {
-    _doss->dout_emergency_impl(str);
+    _doss->dout_emergency_to_file_and_syslog(str);
   }
 }
 
index aa9c449decc141aebbf6da034e17f39f02966ccd..778a8b84738b582a2697af742dc4527919074b66 100644 (file)
@@ -68,6 +68,10 @@ public:
 
   std::string config_to_str() const;
 
+  // Output a string directly to the file and to syslog
+  // (if those sinks are active)
+  void dout_emergency_to_file_and_syslog(const char * const str) const;
+
 protected:
   // Called when the buffer fills up
   virtual int_type overflow(int_type c);
@@ -79,7 +83,6 @@ protected:
   virtual int_type underflow();
 
 private:
-  void dout_emergency_impl(const char * const str) const;
   friend void dout_emergency(const char * const str);
   friend void dout_emergency(const std::string &str);
 
index aa4c56d115bd1c7328d965762079f629c235408e..e1724fadb77dea54a9482779509cf4a047380a92 100644 (file)
@@ -177,7 +177,7 @@ void parse_startup_config_options(std::vector<const char*>& args,
 
   FOR_EACH_ARG(args) {
     if (CONF_ARG_EQ("version", 'v')) {
-      cout << ceph_version_to_string() << std::endl;
+      cout << pretty_version_to_str() << std::endl;
       _exit(0);
     } else if (CONF_ARG_EQ("conf", 'c')) {
        CONF_SAFE_SET_ARG_VAL(&g_conf.conf, OPT_STR);
index fbea812cd119753e17ce68a3a738ee241783d587..9cbb70f8b02d374f6ff61ab023b3a50f1c59a8f7 100644 (file)
 
 #include "common/code_environment.h"
 
+#include <errno.h>
 #include <iostream>
+#include <stdlib.h>
+#include <string.h>
+#include <string>
+#include <sys/prctl.h>
 
 code_environment_t g_code_env;
 
@@ -39,3 +44,26 @@ std::ostream &operator<<(std::ostream &oss, enum code_environment_t e)
   oss << code_environment_to_str(e);
   return oss;
 }
+
+int get_process_name(char *buf, int len)
+{
+  int ret;
+  if (len <= 16) {
+    /* The man page discourages using this prctl with a buffer shorter
+     * than 16 bytes. With a 16-byte buffer, it might not be
+     * null-terminated. */
+    return -ENAMETOOLONG;
+  }
+  memset(buf, 0, len);
+  ret = prctl(PR_GET_NAME, buf);
+  return ret;
+}
+
+std::string get_process_name_cpp()
+{
+  char buf[32];
+  if (get_process_name(buf, sizeof(buf))) {
+    return "(unknown)";
+  }
+  return std::string(buf);
+}
index 16c5026364610ca99140d562ccf18bddf605d208..dd0491221651453bf1c557deeaa4cb39e234cff2 100644 (file)
@@ -24,15 +24,19 @@ enum code_environment_t {
 
 #ifdef __cplusplus
 #include <iosfwd>
+#include <string>
 
 extern "C" code_environment_t g_code_env;
 extern "C" const char *code_environment_to_str(enum code_environment_t e);
 std::ostream &operator<<(std::ostream &oss, enum code_environment_t e);
+extern "C" int get_process_name(char *buf, int len);
+std::string get_process_name_cpp();
 
 #else
 
 extern code_environment_t g_code_env;
 const char *code_environment_to_str(enum code_environment_t e);
+extern int get_process_name(char *buf, int len);
 
 #endif
 
index 6dd8fbd08ca4a27298b72685ca6a8a428bc1aab9..09c948978ef2f1f3fc6ce83f6ff5fead7d6a89fd 100644 (file)
@@ -150,8 +150,14 @@ void common_init(std::vector<const char*>& args, const char *module_type, int fl
   if (force_fg_logging)
     set_foreground_logging();
 
-  if (g_conf.daemonize)
-    cout << ceph_version_to_string() << std::endl;
+#ifdef HAVE_PROFILER
+  /*
+   * We need to call _something_ in libprofile.so so that the
+   * --as-needed stuff doesn't drop it from our .so dependencies.
+   * This is basically a no-op.
+   */
+  ProfilerFlush();
+#endif
 
   parse_config_options(args);
 
index ac083da64b17437b0b6bb0011f7404ffa6bf3b8f..851959c78bff7d967802258a0e3dfb8dbb3e277c 100644 (file)
@@ -1,5 +1,7 @@
 #include "common/DoutStreambuf.h"
+#include "common/code_environment.h"
 #include "common/config.h"
+#include "common/version.h"
 #include "debug.h"
 
 #include <iostream>
@@ -27,6 +29,13 @@ void _dout_open_log()
     _dout = new std::ostream(_doss);
   }
 
+  char buf[1024];
+  snprintf(buf, sizeof(buf), "ceph version %s.commit: %s. process: %s. "
+      "pid: %d\n",
+      ceph_version_to_str(), git_version_to_str(), get_process_name_cpp().c_str(),
+      getpid());
+  _doss->dout_emergency_to_file_and_syslog(buf);
+
   _dout_need_open = false;
 }
 
index 4a727bed1020cd056b49f6a035045760f5c6a6d9..1241e23c7e183bcf3751290f0a47731b96bbe547 100644 (file)
@@ -12,9 +12,8 @@
  *
  */
 
-#include "common/config.h"
+#include "acconfig.h"
 #include "ceph_ver.h"
-#include "common/debug.h"
 #include "common/version.h"
 
 #include <sstream>
 #define _STR(x) #x
 #define STRINGIFY(x) _STR(x)
 
-std::string ceph_version_to_string(void)
+const char * const ceph_version_to_str(void)
+{
+  return VERSION;
+}
+
+const char * const git_version_to_str(void)
+{
+  return STRINGIFY(CEPH_GIT_VER);
+}
+
+std::string const pretty_version_to_str(void)
 {
   std::ostringstream oss;
   oss << "ceph version " << VERSION << " (commit:"
       << STRINGIFY(CEPH_GIT_VER) << ")";
   return oss.str();
 }
-
-void dout_output_ceph_version(void)
-{
-  generic_dout(-1) << ceph_version_to_string() << dendl;
-}
index e98e7cccb8a6fb8f6dd439902c0b1e24c8a2f839..260b1ee0a763bcc531511e0381e45cf421e41006 100644 (file)
 #ifndef CEPH_COMMON_VERSION_H
 #define CEPH_COMMON_VERSION_H
 
+#include <string>
+
 // Return a string describing the Ceph version
-std::string ceph_version_to_string(void);
+const char * const ceph_version_to_str(void);
+
+// Return a string describing the git version
+const char * const git_version_to_str(void);
 
-// Output Ceph version to dout with prio -1
-void dout_output_ceph_version(void);
+// Return a formatted string describing the ceph and git versions
+std::string const pretty_version_to_str(void);
 
 #endif