Fix a typo in an error string.
[libradsec.git] / debug.c
diff --git a/debug.c b/debug.c
index c011b08..3bbcd0a 100644 (file)
--- a/debug.c
+++ b/debug.c
@@ -18,6 +18,7 @@
 #include <sys/time.h>
 #include <syslog.h>
 #include <errno.h>
+#include <assert.h>
 #include "debug.h"
 #include "util.h"
 
@@ -43,9 +44,12 @@ void debug_set_level(uint8_t level) {
        debug_level = DBG_WARN;
        return;
     case 3:
-       debug_level = DBG_INFO;
+       debug_level = DBG_NOTICE;
        return;
     case 4:
+       debug_level = DBG_INFO;
+       return;
+    case 5:
        debug_level = DBG_DBG;
        return;
     }
@@ -68,7 +72,7 @@ int debug_set_destination(char *dest) {
                                   LOG_LOCAL5, LOG_LOCAL6, LOG_LOCAL7 };
     extern int errno;
     int i;
-    
+
     if (!strncasecmp(dest, "file:///", 8)) {
        debug_filepath = stringcopy(dest + 7, 0);
        debug_file = fopen(debug_filepath, "a");
@@ -127,7 +131,7 @@ void debug_logit(uint8_t level, const char *format, va_list ap) {
     struct timeval now;
     char *timebuf;
     int priority;
-    
+
     if (debug_syslogfacility) {
        switch (level) {
        case DBG_DBG:
@@ -136,6 +140,9 @@ void debug_logit(uint8_t level, const char *format, va_list ap) {
        case DBG_INFO:
            priority = LOG_INFO;
            break;
+       case DBG_NOTICE:
+           priority = LOG_NOTICE;
+           break;
        case DBG_WARN:
            priority = LOG_WARNING;
            break;
@@ -177,3 +184,34 @@ void debugx(int status, uint8_t level, char *format, ...) {
     }
     exit(status);
 }
+
+void debugerrno(int err, uint8_t level, char *format, ...) {
+    if (level >= debug_level) {
+       va_list ap;
+       size_t len = strlen(format);
+       char *tmp = malloc(len + 1024 + 2);
+       assert(tmp);
+       strcpy(tmp, format);
+       tmp[len++] = ':';
+       tmp[len++] = ' ';
+       if (strerror_r(err, tmp + len, 1024))
+           tmp = format;
+       va_start(ap, format);
+       debug_logit(level, tmp, ap);
+       va_end(ap);
+    }
+}
+
+void debugerrnox(int err, uint8_t level, char *format, ...) {
+    if (level >= debug_level) {
+       va_list ap;
+       va_start(ap, format);
+       debugerrno(err, level, format, ap);
+       va_end(ap);
+    }
+    exit(err);
+}
+
+/* Local Variables: */
+/* c-file-style: "stroustrup" */
+/* End: */