diff --git a/src/cmds.cc b/src/cmds.cc index a0696308e85..8af7bf28169 100644 --- a/src/cmds.cc +++ b/src/cmds.cc @@ -38,11 +38,11 @@ using namespace std; void usage() { - cerr << "usage: cmds -i name [flags] [--mds rank] [--journal_check]\n"; - cerr << " -m monitorip:port\n"; - cerr << " connect to monitor at given address\n"; - cerr << " --debug_mds n\n"; - cerr << " debug MDS level (e.g. 10)\n"; + derr << "usage: cmds -i name [flags] [--mds rank] [--journal_check]\n" + << " -m monitorip:port\n" + << " connect to monitor at given address\n" + << " --debug_mds n\n" + << " debug MDS level (e.g. 10)\n" << dendl; generic_server_usage(); } @@ -80,12 +80,12 @@ int main(int argc, const char **argv) dout(0) << "checking journal" << dendl; shadow = true; } else { - cerr << "unrecognized arg " << args[i] << std::endl; + derr << "unrecognized arg " << args[i] << dendl; usage(); } } if (!g_conf.id) { - cerr << "must specify '-i name' with the cmds instance name" << std::endl; + derr << "must specify '-i name' with the cmds instance name" << dendl; usage(); } @@ -104,9 +104,9 @@ int main(int argc, const char **argv) journal_dumper->init(); journal_dumper->dump(dump_file); } else { - cout << "starting mds." << g_conf.id + derr << "starting mds." << g_conf.id << " at " << messenger->get_ms_addr() - << std::endl; + << dendl; messenger->register_entity(entity_name_t::MDS(-1)); assert_warn(messenger); diff --git a/src/common/Clock.h b/src/common/Clock.h index 646d4febd10..a9521b7013d 100644 --- a/src/common/Clock.h +++ b/src/common/Clock.h @@ -69,7 +69,7 @@ class Clock { utime_t n(&tv); n -= zero; if (n < last) { - //std::cerr << "WARNING: clock jumped backwards from " << last << " to " << n << std::endl; + //derr << "WARNING: clock jumped backwards from " << last << " to " << n << dendl; n = last; // clock jumped backwards! } else last = n; diff --git a/src/common/DoutStreambuf.cc b/src/common/DoutStreambuf.cc index 2979a27f057..3d99af82351 100644 --- a/src/common/DoutStreambuf.cc +++ b/src/common/DoutStreambuf.cc @@ -71,14 +71,6 @@ static std::string normalize_relative(const char *from) return oss.str(); } -/* Complain about errors even without a logfile */ -static void primitive_log(const std::string &str) -{ - std::cerr << str; - std::cerr.flush(); - syslog(LOG_USER | LOG_NOTICE, "%s", str.c_str()); -} - static inline bool prio_is_visible_on_stderr(signed int prio) { return prio == -1; @@ -112,7 +104,9 @@ static int safe_write(int fd, const char *buf, signed int len) ostringstream oss; oss << __func__ << ": failed to write to fd " << fd << ": " << cpp_strerror(err) << "\n"; - primitive_log(oss.str()); + TEMP_FAILURE_RETRY(::write(STDERR_FILENO, oss.str().c_str(), + oss.str().size())); + syslog(LOG_USER | LOG_NOTICE, "%s", oss.str().c_str()); return err; } } @@ -123,6 +117,13 @@ static int safe_write(int fd, const char *buf, signed int len) } } +/* Complain about errors even without a logfile */ +static void primitive_log(const std::string &str) +{ + safe_write(STDERR_FILENO, str.c_str(), str.size()); + syslog(LOG_USER | LOG_NOTICE, "%s", str.c_str()); +} + static std::string get_basename(const std::string &filename) { size_t last_slash = filename.find_last_of("/"); @@ -435,7 +436,6 @@ template typename DoutStreambuf::int_type DoutStreambuf::sync() { - //std::cout << "flush!" << std::endl; typename DoutStreambuf::int_type ret(this->overflow(traits_ty::eof())); if (ret == traits_ty::eof()) diff --git a/src/common/Logger.cc b/src/common/Logger.cc index 8a2622c86a4..432e33edd64 100644 --- a/src/common/Logger.cc +++ b/src/common/Logger.cc @@ -89,8 +89,8 @@ void logger_tare(utime_t s) utime_t fromstart = g_clock.now(); if (fromstart < start) { - cerr << "logger_tare time jumped backwards from " - << start << " to " << fromstart << std::endl; + derr << "logger_tare time jumped backwards from " + << start << " to " << fromstart << dendl; fromstart = start; } fromstart -= start; @@ -133,7 +133,8 @@ static void flush_all_loggers() utime_t now = g_clock.now(); utime_t fromstart = now; if (fromstart < start) { - cerr << "logger time jumped backwards from " << start << " to " << fromstart << std::endl; + derr << "logger time jumped backwards from " << start << " to " + << fromstart << dendl; //assert(0); start = fromstart; } diff --git a/src/common/assert.cc b/src/common/assert.cc index 900e373fc9d..ca28bbf7767 100644 --- a/src/common/assert.cc +++ b/src/common/assert.cc @@ -12,7 +12,7 @@ void __ceph_assert_fail(const char *assertion, const char *file, int line, const { BackTrace *bt = new BackTrace(1); - _dout_lock.TryLock(); + _dout_lock.Lock(); *_dout << file << ": In function '" << func << "':" << std::endl; *_dout << file << ":" << line << ": FAILED assert(" << assertion << ")" << std::endl; bt->print(*_dout); @@ -20,12 +20,6 @@ void __ceph_assert_fail(const char *assertion, const char *file, int line, const _dout->flush(); - cerr << file << ": In function '" << func << "':" << std::endl; - cerr << file << ":" << line << ": FAILED assert(" << assertion << ")" << std::endl; - bt->print(cerr); - cerr << " NOTE: a copy of the executable, or `objdump -rdS ` is needed to interpret this." << std::endl; - cerr.flush(); - if (1) { throw FailedAssertion(bt); } else { @@ -36,9 +30,10 @@ void __ceph_assert_fail(const char *assertion, const char *file, int line, const } } -void __ceph_assert_warn(const char *assertion, const char *file, int line, const char *func) +void __ceph_assert_warn(const char *assertion, const char *file, + int line, const char *func) { - *_dout << "WARNING: assert(" << assertion << ") at: " << file << ":" << line << ": " << func << "()" << std::endl; + derr << "WARNING: assert(" << assertion << ") at: " << file << ":" << line << ": " << func << "()" << dendl; } } diff --git a/src/common/buffer.cc b/src/common/buffer.cc index 4af9ec798d2..0c2d2eba8c2 100644 --- a/src/common/buffer.cc +++ b/src/common/buffer.cc @@ -14,6 +14,7 @@ #include "config.h" +#include "common/errno.h" #include "include/types.h" #include "armor.h" #include "include/Spinlock.h" @@ -86,13 +87,13 @@ void buffer::list::rebuild_page_aligned() int buffer::list::read_file(const char *fn, bool silent) { struct stat st; - int fd = ::open(fn, O_RDONLY); + int fd = TEMP_FAILURE_RETRY(::open(fn, O_RDONLY)); if (fd < 0) { + int err = errno; if (!silent) { - char buf[80]; - cerr << "can't open " << fn << ": " << strerror_r(errno, buf, sizeof(buf)) << std::endl; + derr << "can't open " << fn << ": " << cpp_strerror(err) << dendl; } - return -errno; + return -err; } ::fstat(fd, &st); int s = ROUND_UP_TO(st.st_size, PAGE_SIZE); @@ -101,12 +102,22 @@ int buffer::list::read_file(const char *fn, bool silent) int got = 0; while (left > 0) { int r = ::read(fd, (void *)(bp.c_str() + got), left); - if (r <= 0) + if (r <= 0) { + int err = errno; + if (err == EINTR) { + // ignore EINTR, 'tis a silly error + continue; + } + if (!silent) { + derr << __PRETTY_FUNCTION__ << ": read error:" + << cpp_strerror(err) << dendl; + } break; + } got += r; left -= r; } - ::close(fd); + TEMP_FAILURE_RETRY(::close(fd)); bp.set_length(got); append(bp); return 0; diff --git a/src/common/common_init.cc b/src/common/common_init.cc index 01382a5bad3..5c877077a27 100644 --- a/src/common/common_init.cc +++ b/src/common/common_init.cc @@ -15,6 +15,7 @@ #include "auth/AuthSupported.h" #include "auth/KeyRing.h" #include "config.h" +#include "common/errno.h" #include "include/color.h" #include "tls.h" @@ -66,12 +67,16 @@ void common_init(std::vector& args, const char *module_type, bool i char buf[100]; int fd = ::open(g_conf.keyfile, O_RDONLY); if (fd < 0) { - cerr << "unable to open " << g_conf.keyfile << ": " << strerror(errno) << std::endl; + int err = errno; + derr << "unable to open " << g_conf.keyfile << ": " + << cpp_strerror(err) << dendl; exit(1); } int len = ::read(fd, buf, sizeof(buf)); if (len < 0) { - cerr << "unable to read key from " << g_conf.keyfile << ": " << strerror(errno) << std::endl; + int err = errno; + derr << "unable to read key from " << g_conf.keyfile << ": " + << cpp_strerror(err) << dendl; exit(1); } ::close(fd); diff --git a/src/common/lockdep.cc b/src/common/lockdep.cc index ed5162bdbfc..c7d0b53ec1b 100644 --- a/src/common/lockdep.cc +++ b/src/common/lockdep.cc @@ -16,13 +16,6 @@ // global int g_lockdep = 0; -/* -struct foobarr { - foobarr() { cerr << "lockdep.cc init" << std::endl; } - ~foobarr() { cerr << "lockdep.cc shutdown" << std::endl; } -} asdff; -*/ - // disable lockdep when this module destructs. struct lockdep_stopper_t { ~lockdep_stopper_t() { diff --git a/src/config.cc b/src/config.cc index fb31b4b4e6d..68d8b63588d 100644 --- a/src/config.cc +++ b/src/config.cc @@ -1240,24 +1240,27 @@ void parse_startup_config_options(std::vector& args, const char *mo ec->load(cf); } -void generic_usage() +void generic_usage(bool is_server) { - cerr << " -c ceph.conf or --conf=ceph.conf\n"; - cerr << " get options from given conf file" << std::endl; - cerr << " -D run in foreground.\n"; - cerr << " -f run in foreground. Show all log messages on stdout.\n"; + derr << " -c ceph.conf or --conf=ceph.conf\n" + << " get options from given conf file\n" + << " -D run in foreground.\n" + << " -f run in foreground. Show all log messages on stdout."; + if (is_server) { + *_dout << " --debug_ms N\n" + << " set message debug level (e.g. 1)"; + } + *_dout << dendl; } void generic_server_usage() { - cerr << " --debug_ms N\n"; - cerr << " set message debug level (e.g. 1)\n"; - generic_usage(); + generic_usage(true); exit(1); } void generic_client_usage() { - generic_usage(); + generic_usage(false); exit(1); } diff --git a/src/librados.cc b/src/librados.cc index 9f84d1c8357..9c7a67bd660 100644 --- a/src/librados.cc +++ b/src/librados.cc @@ -377,7 +377,8 @@ public: void notify(uint8_t opcode, uint64_t ver) { if (opcode != WATCH_NOTIFY_COMPLETE) - cerr << "WARNING: C_NotifyComplete got response: opcode=" << (int)opcode << " ver=" << ver << std::endl; + derr << "WARNING: C_NotifyComplete got response: opcode=" + << (int)opcode << " ver=" << ver << dendl; *done = true; cond->Signal(); } diff --git a/src/mds/MDSTableClient.cc b/src/mds/MDSTableClient.cc index 7bdd9734121..3356eb50889 100644 --- a/src/mds/MDSTableClient.cc +++ b/src/mds/MDSTableClient.cc @@ -13,8 +13,6 @@ */ #include -using std::cout; -using std::cerr; #include "MDSMap.h" diff --git a/src/os/BDBMap.h b/src/os/BDBMap.h index 74a26ee3ca4..434c87f3c3c 100644 --- a/src/os/BDBMap.h +++ b/src/os/BDBMap.h @@ -17,11 +17,12 @@ #define CEPH_BERKELEYDB_H #include +#include #include -#include -using namespace std; +#include "common/debug.h" +using namespace std; template class BDBMap { @@ -42,7 +43,7 @@ class BDBMap { int r; if ((r = db_create(&dbp, NULL, 0)) != 0) { - cerr << "db_create: " << db_strerror(r) << endl; + derr << "db_create: " << db_strerror(r) << dendl; assert(0); } diff --git a/src/test/TestDoutStreambuf.cc b/src/test/TestDoutStreambuf.cc index 18eec24051e..1f14735b881 100644 --- a/src/test/TestDoutStreambuf.cc +++ b/src/test/TestDoutStreambuf.cc @@ -27,8 +27,6 @@ #include #include -using std::cout; -using std::cerr; using std::string; int main(int argc, const char **argv) @@ -48,8 +46,8 @@ int main(int argc, const char **argv) // dos->set_flags(DoutStreambuf::DOUTSB_FLAG_SYSLOG | // DoutStreambuf::DOUTSB_FLAG_STDOUT | // DoutStreambuf::DOUTSB_FLAG_STDERR); - std::cout << "using configuration: " << dos->config_to_str() << std::endl; _dout_lock.Unlock(); + derr << "using configuration: " << dos->config_to_str() << dendl; std::ostream oss(dos); syslog(LOG_USER | LOG_NOTICE, "TestDoutStreambuf: starting test\n");