X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/disorder/blobdiff_plain/763d5e6ad88ef3ba1cd1d7742d060e4f1e54c6b8..477b12ff719d3749b8d8f85035bd6384fee9be0d:/lib/log.h
diff --git a/lib/log.h b/lib/log.h
index f23dcd7..d1445cf 100644
--- a/lib/log.h
+++ b/lib/log.h
@@ -1,59 +1,77 @@
/*
* This file is part of DisOrder.
- * Copyright (C) 2004, 2005 Richard Kettlewell
+ * Copyright (C) 2004, 2005, 2007-9, 2013 Richard Kettlewell
*
- * This program is free software; you can redistribute it and/or modify
+ * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- * USA
+ * along with this program. If not, see .
+ */
+/** @file lib/log.h
+ * @brief Errors and logging
*/
#ifndef LOG_H
#define LOG_H
-/* All messages are initially emitted by one of the four functions below.
- * debug() is generally invoked via D() so that mostly you just do a test
- * rather than a complete subroutine call.
- *
- * Messages are dispatched via log_default. This defaults to log_stderr.
- * daemonize() will turn off log_stderr and use log_syslog instead.
- *
- * fatal() will call exitfn() with a nonzero status. The default value is
- * exit(), but it should be set to _exit() anywhere but the 'main line' of the
- * program, to guarantee that exit() gets called at most once.
- */
-
#include
struct log_output;
void set_progname(char **argv);
-/* set progname from argv[0] */
-void elog(int pri, int errno_value, const char *fmt, va_list ap);
-/* internals of fatal/error/info/debug */
+/** @brief Possible error number spaces */
+enum error_class {
+ /** @brief Invalid number space */
+ ec_none,
+
+ /** @brief @c errno number space */
+ ec_errno,
-void fatal(int errno_value, const char *msg, ...) attribute((noreturn))
+ /** @brief Windows GetLastError/WSAGetLastError return value */
+ ec_windows,
+
+ /** @brief getaddrinfo() return value */
+ ec_getaddrinfo,
+};
+
+#if _WIN32
+# define ec_native ec_windows
+# define ec_socket ec_windows
+#else
+# define ec_native ec_errno
+# define ec_socket ec_errno
+#endif
+
+void elog(int pri, enum error_class, int errno_value, const char *fmt, va_list ap);
+
+declspec(noreturn)
+void disorder_fatal(int errno_value, const char *msg, ...) attribute((noreturn))
attribute((format (printf, 2, 3)));
-void error(int errno_value, const char *msg, ...)
+declspec(noreturn)
+void disorder_fatal_ec(enum error_class ec, int errno_value, const char *msg, ...) attribute((noreturn))
+ attribute((format (printf, 3, 4)));
+void disorder_error(int errno_value, const char *msg, ...)
attribute((format (printf, 2, 3)));
-void info(const char *msg, ...)
+void disorder_error_ec(enum error_class ec, int errno_value, const char *msg, ...)
+ attribute((format (printf, 3, 4)));
+void disorder_info(const char *msg, ...)
attribute((format (printf, 1, 2)));
-void debug(const char *msg, ...)
+void disorder_debug(const char *msg, ...)
attribute((format (printf, 1, 2)));
/* report a message of the given class. @errno_value@ if present an
* non-zero is included. @fatal@ terminates the process. */
+const char *format_error(enum error_class ec, int err, char buffer[], size_t bufsize);
+
extern int debugging;
/* set when debugging enabled */
@@ -63,17 +81,26 @@ extern void (*exitfn)(int) attribute((noreturn));
extern const char *progname;
/* program name */
-extern struct log_output log_stderr, log_syslog, *log_default;
+extern struct log_output log_stderr, *log_default;
+#if HAVE_SYSLOG_H
+extern struct log_output log_syslog;
+#endif
/* some typical outputs */
extern const char *debug_filename;
extern int debug_lineno;
+extern int logdate;
+/** @brief Issue a debug message if debugging is turned on
+ * @param x Parenthesized debug arguments
+ *
+ * Use in the format: D(("format string", arg, arg, ...));
+ */
#define D(x) do { \
if(debugging) { \
debug_filename=__FILE__; \
debug_lineno=__LINE__; \
- debug x; \
+ disorder_debug x; \
} \
} while(0)