2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-30 22:05:19 +00:00

util: Introduce ovs_assert macro.

An occasionally significant problem with the standard "assert" macro is
that it writes the failure message to stderr.  In our daemons, stderr is
generally redirected to /dev/null.  It's more useful to write the failure
message to the log, which is what the new ovs_assert macro introduced in
this patch does.

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
This commit is contained in:
Ben Pfaff
2013-01-16 16:03:03 -08:00
parent 1677446238
commit 4749f73d12
5 changed files with 102 additions and 4 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012 Nicira, Inc.
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,7 +16,6 @@
#include <config.h>
#include "util.h"
#include <assert.h>
#include <errno.h>
#include <limits.h>
#include <stdarg.h>
@@ -45,6 +44,30 @@ const char *subprogram_name = "";
/* --version option output. */
static char *program_version;
void
ovs_assert_failure(const char *where, const char *function,
const char *condition)
{
/* Prevent an infinite loop (or stack overflow) in case VLOG_ABORT happens
* to trigger an assertion failure of its own. */
static int reentry = 0;
switch (reentry++) {
case 0:
VLOG_ABORT("%s: assertion %s failed in %s()",
where, condition, function);
NOT_REACHED();
case 1:
fprintf(stderr, "%s: assertion %s failed in %s()",
where, condition, function);
abort();
default:
abort();
}
}
void
out_of_memory(void)
{
@@ -756,7 +779,7 @@ english_list_delimiter(size_t index, size_t total)
int
log_2_floor(uint32_t n)
{
assert(n);
ovs_assert(n);
#if !defined(UINT_MAX) || !defined(UINT32_MAX)
#error "Someone screwed up the #includes."