From: Ben Pfaff Date: Tue, 22 May 2012 18:36:50 +0000 (-0700) Subject: vlog: Add VLOG_ABORT() to log and call abort(). X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d41d4b714d29091dd502dd8705ef489467e11a43;p=openvswitch vlog: Add VLOG_ABORT() to log and call abort(). Whereas VLOG_FATAL() eventually calls exit(1), VLOG_ABORT() eventually calls abort(). The key difference is that abort() will cause a "monitor" process to restart, where exit(1) will cause it to exit along with the monitored process. Signed-off-by: Ben Pfaff --- diff --git a/lib/util.c b/lib/util.c index bc5fa988..cbcf693e 100644 --- a/lib/util.c +++ b/lib/util.c @@ -199,9 +199,14 @@ ovs_abort(int err_no, const char *format, ...) va_list args; va_start(args, format); - ovs_error_valist(err_no, format, args); - va_end(args); + ovs_abort_valist(err_no, format, args); +} +/* Same as ovs_abort() except that the arguments are supplied as a va_list. */ +void +ovs_abort_valist(int err_no, const char *format, va_list args) +{ + ovs_error_valist(err_no, format, args); abort(); } diff --git a/lib/util.h b/lib/util.h index dd86de26..809ae9c5 100644 --- a/lib/util.h +++ b/lib/util.h @@ -188,6 +188,8 @@ void ovs_strzcpy(char *dst, const char *src, size_t size); void ovs_abort(int err_no, const char *format, ...) PRINTF_FORMAT(2, 3) NO_RETURN; +void ovs_abort_valist(int err_no, const char *format, va_list) + PRINTF_FORMAT(2, 0) NO_RETURN; void ovs_fatal(int err_no, const char *format, ...) PRINTF_FORMAT(2, 3) NO_RETURN; void ovs_fatal_valist(int err_no, const char *format, va_list) diff --git a/lib/vlog.c b/lib/vlog.c index 128ed45d..d4d277aa 100644 --- a/lib/vlog.c +++ b/lib/vlog.c @@ -745,6 +745,12 @@ vlog(const struct vlog_module *module, enum vlog_level level, va_end(args); } +/* Logs 'message' to 'module' at maximum verbosity, then exits with a failure + * exit code. Always writes the message to stderr, even if the console + * facility is disabled. + * + * Choose this function instead of vlog_abort_valist() if the daemon monitoring + * facility shouldn't automatically restart the current daemon. */ void vlog_fatal_valist(const struct vlog_module *module_, const char *message, va_list args) @@ -759,6 +765,12 @@ vlog_fatal_valist(const struct vlog_module *module_, ovs_fatal_valist(0, message, args); } +/* Logs 'message' to 'module' at maximum verbosity, then exits with a failure + * exit code. Always writes the message to stderr, even if the console + * facility is disabled. + * + * Choose this function instead of vlog_abort() if the daemon monitoring + * facility shouldn't automatically restart the current daemon. */ void vlog_fatal(const struct vlog_module *module, const char *message, ...) { @@ -769,6 +781,40 @@ vlog_fatal(const struct vlog_module *module, const char *message, ...) va_end(args); } +/* Logs 'message' to 'module' at maximum verbosity, then calls abort(). Always + * writes the message to stderr, even if the console facility is disabled. + * + * Choose this function instead of vlog_fatal_valist() if the daemon monitoring + * facility should automatically restart the current daemon. */ +void +vlog_abort_valist(const struct vlog_module *module_, + const char *message, va_list args) +{ + struct vlog_module *module = (struct vlog_module *) module_; + + /* Don't log this message to the console to avoid redundancy with the + * message written by the later ovs_abort_valist(). */ + module->levels[VLF_CONSOLE] = VLL_OFF; + + vlog_valist(module, VLL_EMER, message, args); + ovs_abort_valist(0, message, args); +} + +/* Logs 'message' to 'module' at maximum verbosity, then calls abort(). Always + * writes the message to stderr, even if the console facility is disabled. + * + * Choose this function instead of vlog_fatal() if the daemon monitoring + * facility should automatically restart the current daemon. */ +void +vlog_abort(const struct vlog_module *module, const char *message, ...) +{ + va_list args; + + va_start(args, message); + vlog_abort_valist(module, message, args); + va_end(args); +} + bool vlog_should_drop(const struct vlog_module *module, enum vlog_level level, struct vlog_rate_limit *rl) diff --git a/lib/vlog.h b/lib/vlog.h index 9050634e..9570b0ef 100644 --- a/lib/vlog.h +++ b/lib/vlog.h @@ -142,6 +142,11 @@ void vlog_fatal(const struct vlog_module *, const char *format, ...) void vlog_fatal_valist(const struct vlog_module *, const char *format, va_list) PRINTF_FORMAT (2, 0) NO_RETURN; +void vlog_abort(const struct vlog_module *, const char *format, ...) + PRINTF_FORMAT (2, 3) NO_RETURN; +void vlog_abort_valist(const struct vlog_module *, const char *format, va_list) + PRINTF_FORMAT (2, 0) NO_RETURN; + void vlog_rate_limit(const struct vlog_module *, enum vlog_level, struct vlog_rate_limit *, const char *, ...) PRINTF_FORMAT (4, 5); @@ -160,6 +165,7 @@ void vlog_rate_limit(const struct vlog_module *, enum vlog_level, * Guaranteed to preserve errno. */ #define VLOG_FATAL(...) vlog_fatal(THIS_MODULE, __VA_ARGS__) +#define VLOG_ABORT(...) vlog_abort(THIS_MODULE, __VA_ARGS__) #define VLOG_EMER(...) VLOG(VLL_EMER, __VA_ARGS__) #define VLOG_ERR(...) VLOG(VLL_ERR, __VA_ARGS__) #define VLOG_WARN(...) VLOG(VLL_WARN, __VA_ARGS__)