Modify ChangeLog.
[libradsec.git] / debug.c
diff --git a/debug.c b/debug.c
index c011b08..d8cf6f2 100644 (file)
--- a/debug.c
+++ b/debug.c
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2007 Stig Venaas <venaas@uninett.no>
+ * Copyright (C) 2010 NORDUnet A/S
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -18,6 +19,7 @@
 #include <sys/time.h>
 #include <syslog.h>
 #include <errno.h>
+#include <assert.h>
 #include "debug.h"
 #include "util.h"
 
@@ -43,9 +45,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 +73,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 +132,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 +141,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 +185,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: */