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>
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.
*/
/* 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);
}
}
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);
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);
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);
#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;
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);
+}
#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
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);
#include "common/DoutStreambuf.h"
+#include "common/code_environment.h"
#include "common/config.h"
+#include "common/version.h"
#include "debug.h"
#include <iostream>
_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;
}
*
*/
-#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;
-}
#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