mirror of
https://github.com/ceph/ceph
synced 2025-01-15 07:23:16 +00:00
common: more cerr -> derr conversions
cmds: cerr -> derr DoutStreambuf: primitive_log: just write to the stdout fd rather than cerr assert: don't write output to stderr manually (dout will do that automatically). Do _dout_lock.Lock rather than TryLock. Failing to wait for the lock is potentially buggy and provides no benefit in that code. Signed-off-by: Colin McCabe <colinm@hq.newdream.net>
This commit is contained in:
parent
30f752cd32
commit
c4b5c33b12
18
src/cmds.cc
18
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);
|
||||
|
@ -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;
|
||||
|
@ -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 charT, typename traits>
|
||||
typename DoutStreambuf<charT, traits>::int_type
|
||||
DoutStreambuf<charT, traits>::sync()
|
||||
{
|
||||
//std::cout << "flush!" << std::endl;
|
||||
typename DoutStreambuf<charT, traits>::int_type
|
||||
ret(this->overflow(traits_ty::eof()));
|
||||
if (ret == traits_ty::eof())
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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 <executable>` 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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<const char*>& 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);
|
||||
|
@ -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() {
|
||||
|
@ -1240,24 +1240,27 @@ void parse_startup_config_options(std::vector<const char*>& 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);
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -13,8 +13,6 @@
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
using std::cout;
|
||||
using std::cerr;
|
||||
|
||||
#include "MDSMap.h"
|
||||
|
||||
|
@ -17,11 +17,12 @@
|
||||
#define CEPH_BERKELEYDB_H
|
||||
|
||||
#include <db.h>
|
||||
#include <list>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <list>
|
||||
using namespace std;
|
||||
#include "common/debug.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
template<typename K, typename D>
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -27,8 +27,6 @@
|
||||
#include <string>
|
||||
#include <syslog.h>
|
||||
|
||||
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<char>::DOUTSB_FLAG_SYSLOG |
|
||||
// DoutStreambuf<char>::DOUTSB_FLAG_STDOUT |
|
||||
// DoutStreambuf<char>::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");
|
||||
|
Loading…
Reference in New Issue
Block a user