[sheepdog] [PATCH] compile with -DNDEBUG by default
MORITA Kazutaka
morita.kazutaka at lab.ntt.co.jp
Wed May 22 09:16:12 CEST 2013
assert() is used to confirm code's correctness and it's no problem to
remove it for a release build.
This also replaces assert() in cluster/local.c with if/panic() because
it abuses assert() for error checking.
Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
configure.ac | 2 ++
sheep/cluster/local.c | 15 ++++++++++-----
sheep/ops.c | 3 +--
3 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/configure.ac b/configure.ac
index 6d6410d..8e54284 100644
--- a/configure.ac
+++ b/configure.ac
@@ -238,6 +238,8 @@ if test "x${enable_debug}" = xyes; then
AC_DEFINE_UNQUOTED([DEBUG], [1], [Compiling Debugging code])
OPT_CFLAGS="-O0"
PACKAGE_FEATURES="$PACKAGE_FEATURES debug"
+else
+ OPT_CFLAGS="-DNDEBUG"
fi
# gdb flags
diff --git a/sheep/cluster/local.c b/sheep/cluster/local.c
index ae7941b..4624429 100644
--- a/sheep/cluster/local.c
+++ b/sheep/cluster/local.c
@@ -213,11 +213,13 @@ static void shm_queue_init(void)
shm_queue_lock();
ret = ftruncate(shmfd, sizeof(*shm_queue));
- assert(ret == 0);
+ if (ret != 0)
+ panic("failed to truncate shmfile, %m");
shm_queue = mmap(NULL, sizeof(*shm_queue),
PROT_READ | PROT_WRITE, MAP_SHARED, shmfd, 0);
- assert(shm_queue != MAP_FAILED);
+ if (shm_queue == MAP_FAILED)
+ panic("mmap error, %m");
if (is_shm_queue_valid()) {
block_event_pos = shm_queue->block_event_pos;
@@ -227,9 +229,11 @@ static void shm_queue_init(void)
block_event_pos = 0;
nonblock_event_pos = 0;
ret = ftruncate(shmfd, 0);
- assert(ret == 0);
+ if (ret != 0)
+ panic("failed to truncate shmfile, %m");
ret = ftruncate(shmfd, sizeof(*shm_queue));
- assert(ret == 0);
+ if (ret != 0)
+ panic("failed to truncate shmfile, %m");
}
shm_queue_unlock();
@@ -510,7 +514,8 @@ static void local_handler(int listen_fd, int events, void *data)
sd_dprintf("read siginfo");
ret = read(sigfd, &siginfo, sizeof(siginfo));
- assert(ret == sizeof(siginfo));
+ if (ret != sizeof(siginfo))
+ panic("failed to read from sigfd, %m");
shm_queue_lock();
diff --git a/sheep/ops.c b/sheep/ops.c
index 9399fd8..af6e0e5 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -736,9 +736,8 @@ static int local_set_cache_size(const struct sd_req *req, struct sd_rsp *rsp,
static int local_md_info(struct request *request)
{
struct sd_rsp *rsp = &request->rp;
- struct sd_req *req = &request->rq;
- assert(req->data_length == sizeof(struct sd_md_info));
+ assert(request->rq.data_length == sizeof(struct sd_md_info));
rsp->data_length = md_get_info((struct sd_md_info *)request->data);
return rsp->data_length ? SD_RES_SUCCESS : SD_RES_UNKNOWN;
--
1.8.1.3.566.gaa39828
More information about the sheepdog
mailing list