[PATCH ucspi-vsock 5/7] log: add die function

Alyssa Ross
2021-03-19T03:03:32Z

This is useful if we want to provide a more specific error message
than strerror can provide.
---
log.c | 10 ++++++++++
log.h | 8 ++++----
2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/log.c b/log.c
index cdfacd6..8a57105 100644
--- a/log.c
+++ b/log.c
@@ -62,6 +62,16 @@ void ilog(const char *fmt, ...)
va_end(ap);
}

+void die(int eval, const char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ velog(fmt, ap);
+ va_end(ap);
+
+ exit(eval);
+}
+
void diee(int eval, const char *fmt, ...)
{
va_list ap;
diff --git a/log.h b/log.h
index 7b40e48..706d42f 100644
--- a/log.h
+++ b/log.h
@@ -11,20 +11,20 @@ enum verbosity {

extern enum verbosity verbosity;

+// Functions with an `e' suffix additionally print strerrno(errno).
+
// If opt is a character that matches a standard UCSPI command line
// verbosity option, sets the verbosity appropriately and returns
// true. Otherwise, returns false.
_Bool set_verbosity(int opt);

-// Log an error message, followed by strerrno(errno), then exit with
-// status eval.
+// Log an error message then exit with status eval.
+_Noreturn void die(int eval, const char *fmt, ...);
_Noreturn void diee(int eval, const char *fmt, ...);

// Log an error message.
void elog(const char *fmt, ...);
void velog(const char *fmt, va_list args);
-
-// Log an error message, followed by strerror(errno).
void veloge(const char *fmt, va_list args);

// Log an informative message.
--
2.30.0