summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorRuss Allbery <rra@stanford.edu>2009-11-25 21:27:21 -0800
committerRuss Allbery <rra@stanford.edu>2009-11-25 21:27:21 -0800
commit23da37ecfa39e8eede5677a56c25b0daa5d1a254 (patch)
tree5fb14604f2e221eb048383c6c15350796eef4f21 /util
parenteff5f56d73159ab07ce0e4812dbaae0248930457 (diff)
Update to rra-c-util 2.1 and C TAP Harness 1.1
Update to rra-c-util 2.1: * Revert separation of die into a separate object file. * Fall back on manual library probing if krb5-config doesn't work. * Don't try to use a non-executable krb5-config for GSS-API probes. * Suppress error output from krb5-config GSS-API probes. * Prefer KRB5_CONFIG over a path constructed from --with-gssapi. * Fix network test suite failures when IPv6 is available but disabled. Update to C TAP Harness 1.1: * Summarize results at the end of test execution.
Diffstat (limited to 'util')
-rw-r--r--util/concat.c2
-rw-r--r--util/messages-die.c137
-rw-r--r--util/messages.c75
3 files changed, 66 insertions, 148 deletions
diff --git a/util/concat.c b/util/concat.c
index e49fc39..bef67db 100644
--- a/util/concat.c
+++ b/util/concat.c
@@ -28,7 +28,7 @@
#include <util/util.h>
/* Abbreviation for cleaner code. */
-#define VA_NEXT(var, type) ((var) = (type) va_arg(args, type))
+#define VA_NEXT(var, type) ((var) = (type) va_arg(args, type))
/*
diff --git a/util/messages-die.c b/util/messages-die.c
deleted file mode 100644
index 0419d35..0000000
--- a/util/messages-die.c
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * Message and error reporting (fatal).
- *
- * Usage:
- *
- * extern int cleanup(void);
- * extern void log(int, const char *, va_list, int);
- *
- * message_fatal_cleanup = cleanup;
- * message_program_name = argv[0];
- *
- * die("Something fatal happened at %lu", time);
- * sysdie("open of %s failed", filename);
- *
- * message_handlers_die(1, log);
- * die("This now goes through our log function");
- *
- * die() implements message reporting through user-configurable handler
- * functions and then exits, normally with a status of 1. sysdie() does the
- * same but appends a colon, a space, and the results of strerror(errno) to
- * the end of the message. Both functions accept printf-style formatting
- * strings and arguments.
- *
- * If message_fatal_cleanup is non-NULL, it is called before exit by die and
- * sysdie and its return value is used as the argument to exit. It is a
- * pointer to a function taking no arguments and returning an int, and can be
- * used to call cleanup functions or to exit in some alternate fashion (such
- * as by calling _exit).
- *
- * If message_program_name is non-NULL, the string it points to, followed by a
- * colon and a space, is prepended to all error messages logged through the
- * message_log_stderr message handler (the default for die).
- *
- * Honoring error_program_name and printing to stderr is just the default
- * handler; with message_handlers_die the handler for die() can be changed.
- * By default, die prints to stderr. message_handlers_die takes a count of
- * handlers and then that many function pointers, each one to a function that
- * takes a message length (the number of characters snprintf generates given
- * the format and arguments), a format, an argument list as a va_list, and the
- * applicable errno value (if any).
- *
- * This file is separate from messages.c so that the potentially fatal
- * functions aren't linked with code that will never call exit(). This helps
- * automated analysis ensure that shared libraries don't call exit().
- *
- * Copyright 2009 Russ Allbery <rra@stanford.edu>
- * Copyright 2008 Board of Trustees, Leland Stanford Jr. University
- * Copyright (c) 2004, 2005, 2006
- * by Internet Systems Consortium, Inc. ("ISC")
- * Copyright (c) 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
- * 2002, 2003 by The Internet Software Consortium and Rich Salz
- *
- * See LICENSE for licensing terms.
- */
-
-#include <config.h>
-#include <portable/system.h>
-
-#include <errno.h>
-
-#include <util/util.h>
-
-/* The default message handler. */
-static message_handler_func stderr_handlers[2] = {
- message_log_stderr, NULL
-};
-static message_handler_func *die_handlers = stderr_handlers;
-
-/* If non-NULL, called before exit and its return value passed to exit. */
-int (*message_fatal_cleanup)(void) = NULL;
-
-
-/*
- * Set the handlers for die. This duplicates code from messages.c but seems
- * to be the best way to handle separating the potentially fatal functions
- * from the rest.
- */
-void
-message_handlers_die(int count, ...)
-{
- va_list args;
- int i;
-
- va_start(args, count);
- if (die_handlers != stderr_handlers)
- free(die_handlers);
- die_handlers = xmalloc(sizeof(message_handler_func) * (count + 1));
- for (i = 0; i < count; i++)
- die_handlers[i] = va_arg(args, message_handler_func);
- die_handlers[count] = NULL;
- va_end(args);
-}
-
-
-/*
- * The error reporting functions. There is code duplication between the two
- * functions that could be avoided with judicious use of va_copy(), but it's
- * never seemed worth the effort.
- */
-void
-die(const char *format, ...)
-{
- va_list args;
- message_handler_func *log;
- int length;
-
- va_start(args, format);
- length = vsnprintf(NULL, 0, format, args);
- va_end(args);
- if (length >= 0)
- for (log = die_handlers; *log != NULL; log++) {
- va_start(args, format);
- (**log)(length, format, args, 0);
- va_end(args);
- }
- exit(message_fatal_cleanup ? (*message_fatal_cleanup)() : 1);
-}
-
-void
-sysdie(const char *format, ...)
-{
- va_list args;
- message_handler_func *log;
- int length;
- int error = errno;
-
- va_start(args, format);
- length = vsnprintf(NULL, 0, format, args);
- va_end(args);
- if (length >= 0)
- for (log = die_handlers; *log != NULL; log++) {
- va_start(args, format);
- (**log)(length, format, args, error);
- va_end(args);
- }
- exit(message_fatal_cleanup ? (*message_fatal_cleanup)() : 1);
-}
diff --git a/util/messages.c b/util/messages.c
index 6f728a7..b46415f 100644
--- a/util/messages.c
+++ b/util/messages.c
@@ -1,16 +1,20 @@
/*
- * Message and error reporting (non-fatal).
+ * Message and error reporting (possibly fatal).
*
* Usage:
*
* extern int cleanup(void);
* extern void log(int, const char *, va_list, int);
*
+ * message_fatal_cleanup = cleanup;
* message_program_name = argv[0];
*
* warn("Something horrible happened at %lu", time);
* syswarn("Couldn't unlink temporary file %s", tmpfile);
*
+ * die("Something fatal happened at %lu", time);
+ * sysdie("open of %s failed", filename);
+ *
* debug("Some debugging message about %s", string);
* notice("Informational notices");
*
@@ -19,27 +23,34 @@
*
* These functions implement message reporting through user-configurable
* handler functions. debug() only does something if DEBUG is defined, and
- * notice() and warn() just output messages as configured.
+ * notice() and warn() just output messages as configured. die() similarly
+ * outputs a message but then exits, normally with a status of 1.
*
* The sys* versions do the same, but append a colon, a space, and the results
* of strerror(errno) to the end of the message. All functions accept
* printf-style formatting strings and arguments.
*
+ * If message_fatal_cleanup is non-NULL, it is called before exit by die and
+ * sysdie and its return value is used as the argument to exit. It is a
+ * pointer to a function taking no arguments and returning an int, and can be
+ * used to call cleanup functions or to exit in some alternate fashion (such
+ * as by calling _exit).
+ *
* If message_program_name is non-NULL, the string it points to, followed by a
* colon and a space, is prepended to all error messages logged through the
* message_log_stdout and message_log_stderr message handlers (the former is
- * the default for notice, and the latter is the default for warn).
+ * the default for notice, and the latter is the default for warn and die).
*
* Honoring error_program_name and printing to stderr is just the default
* handler; with message_handlers_* the handlers for any message function can
- * be changed. By default, notice prints to stdout, warn prints to stderr,
- * and the others don't do anything at all. These functions take a count of
- * handlers and then that many function pointers, each one to a function that
- * takes a message length (the number of characters snprintf generates given
- * the format and arguments), a format, an argument list as a va_list, and the
- * applicable errno value (if any).
+ * be changed. By default, notice prints to stdout, warn and die print to
+ * stderr, and the others don't do anything at all. These functions take a
+ * count of handlers and then that many function pointers, each one to a
+ * function that takes a message length (the number of characters snprintf
+ * generates given the format and arguments), a format, an argument list as a
+ * va_list, and the applicable errno value (if any).
*
- * Copyright 2008, 2009 Board of Trustees, Leland Stanford Jr. University
+ * Copyright 2008 Board of Trustees, Leland Stanford Jr. University
* Copyright (c) 2004, 2005, 2006
* by Internet Systems Consortium, Inc. ("ISC")
* Copyright (c) 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
@@ -80,6 +91,10 @@ static message_handler_func stderr_handlers[2] = {
static message_handler_func *debug_handlers = NULL;
static message_handler_func *notice_handlers = stdout_handlers;
static message_handler_func *warn_handlers = stderr_handlers;
+static message_handler_func *die_handlers = stderr_handlers;
+
+/* If non-NULL, called before exit and its return value passed to exit. */
+int (*message_fatal_cleanup)(void) = NULL;
/* If non-NULL, prepended (followed by ": ") to messages. */
const char *message_program_name = NULL;
@@ -121,6 +136,7 @@ message_handlers(message_handler_func **list, int count, va_list args)
HANDLER_FUNCTION(debug)
HANDLER_FUNCTION(notice)
HANDLER_FUNCTION(warn)
+HANDLER_FUNCTION(die)
/*
@@ -318,3 +334,42 @@ syswarn(const char *format, ...)
va_end(args);
}
}
+
+void
+die(const char *format, ...)
+{
+ va_list args;
+ message_handler_func *log;
+ int length;
+
+ va_start(args, format);
+ length = vsnprintf(NULL, 0, format, args);
+ va_end(args);
+ if (length >= 0)
+ for (log = die_handlers; *log != NULL; log++) {
+ va_start(args, format);
+ (**log)(length, format, args, 0);
+ va_end(args);
+ }
+ exit(message_fatal_cleanup ? (*message_fatal_cleanup)() : 1);
+}
+
+void
+sysdie(const char *format, ...)
+{
+ va_list args;
+ message_handler_func *log;
+ int length;
+ int error = errno;
+
+ va_start(args, format);
+ length = vsnprintf(NULL, 0, format, args);
+ va_end(args);
+ if (length >= 0)
+ for (log = die_handlers; *log != NULL; log++) {
+ va_start(args, format);
+ (**log)(length, format, args, error);
+ va_end(args);
+ }
+ exit(message_fatal_cleanup ? (*message_fatal_cleanup)() : 1);
+}