From ff96789e46f4ede58a1a833f994eb61edcb2ad89 Mon Sep 17 00:00:00 2001 From: Sam Lang Date: Mon, 24 Sep 2012 14:09:43 -0700 Subject: [PATCH] client: add WARN_UNUSED_RESULT to client init func Adds the gcc attribute (if available) to client init functions to ensure proper error handling. Signed-off-by: Sam Lang --- src/client/Client.cc | 2 +- src/client/Client.h | 4 +++- src/client/SyntheticClient.cc | 10 ++++++++-- src/common/compiler_extensions.h | 3 ++- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/client/Client.cc b/src/client/Client.cc index a99faabd36c15..a25a0d553126a 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -267,7 +267,7 @@ void Client::dump_cache() } } -int Client::init() +int Client::init() { client_lock.Lock(); assert(!initialized); diff --git a/src/client/Client.h b/src/client/Client.h index 316a819fa7ea5..02f6e89bc89c1 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -43,6 +43,8 @@ using namespace __gnu_cxx; #include "common/Mutex.h" #include "common/Timer.h" +#include "common/compiler_extensions.h" + #include "osdc/ObjectCacher.h" class MDSMap; @@ -371,7 +373,7 @@ protected: inodeno_t get_root_ino(); - int init(); + int init() WARN_UNUSED_RESULT; void shutdown(); // messaging diff --git a/src/client/SyntheticClient.cc b/src/client/SyntheticClient.cc index 374543ca78579..20c3bc02d16aa 100644 --- a/src/client/SyntheticClient.cc +++ b/src/client/SyntheticClient.cc @@ -318,9 +318,15 @@ string SyntheticClient::get_sarg(int seq) int SyntheticClient::run() { dout(15) << "initing" << dendl; - client->init(); + int err = client->init(); + if (err < 0) { + char buf[80]; + dout(0) << "failed to initialize: " << strerror_r(-err, buf, sizeof(buf)) << dendl; + return -1; + } + dout(15) << "mounting" << dendl; - int err = client->mount(""); + err = client->mount(""); if (err < 0) { char buf[80]; dout(0) << "failed to mount: " << strerror_r(-err, buf, sizeof(buf)) << dendl; diff --git a/src/common/compiler_extensions.h b/src/common/compiler_extensions.h index 6a4956f867935..2fd8f5c2d1367 100644 --- a/src/common/compiler_extensions.h +++ b/src/common/compiler_extensions.h @@ -23,7 +23,8 @@ // GCC #define WARN_UNUSED_RESULT __attribute__((warn_unused_result)) #else -// some other compiler +// some other compiler - just make it a no-op +#define WARN_UNUSED_RESULT #endif #endif -- 2.39.5