OSDN Git Service

Add some more debug facilities.
authorPeter Jones <pjones@redhat.com>
Thu, 26 Apr 2018 19:57:48 +0000 (15:57 -0400)
committerPeter Jones <pmjones@gmail.com>
Mon, 21 May 2018 15:11:50 +0000 (11:11 -0400)
Signed-off-by: Peter Jones <pjones@redhat.com>
src/error.c
src/libefivar.map.in
src/util.h

index 7808e85..d1008a3 100644 (file)
@@ -157,3 +157,28 @@ efi_error_clear(void)
        error_table = NULL;
        current = 0;
 }
+
+static int efi_verbose;
+static FILE *efi_errlog;
+
+FILE PUBLIC *
+efi_get_logfile(void)
+{
+       if (efi_errlog)
+               return efi_errlog;
+       return stderr;
+}
+
+void PUBLIC
+efi_set_verbose(int verbosity, FILE *errlog)
+{
+       efi_verbose = verbosity;
+       if (errlog)
+               efi_errlog = errlog;
+}
+
+int PUBLIC
+efi_get_verbose(void)
+{
+       return efi_verbose;
+}
index 4036f57..31f696d 100644 (file)
@@ -120,3 +120,9 @@ LIBEFIVAR_1.35 {
        global: efi_get_variable_exists;
                efi_guid_fwupdate;
 } LIBEFIVAR_1.33;
+
+LIBEFIVAR_1.36 {
+       global: efi_set_verbose;
+               efi_get_verbose;
+               efi_get_logfile;
+} LIBEFIVAR_1.35;
index e6827c0..388542e 100644 (file)
 #include <alloca.h>
 #include <endian.h>
 #include <errno.h>
+#include <fcntl.h>
 #include <limits.h>
 #include <sched.h>
-#include <stdio.h>
 #include <stdarg.h>
+#include <stdbool.h>
 #include <stdlib.h>
+#include <stdint.h>
+#include <stdio.h>
 #include <string.h>
 #include <sys/ioctl.h>
 #include <sys/mount.h>
+#include <sys/stat.h>
+#include <sys/types.h>
 #include <tgmath.h>
 #include <unistd.h>
 
@@ -349,4 +354,25 @@ swizzle_guid_to_uuid(efi_guid_t *guid)
         u16[1] = __builtin_bswap16(u16[1]);
 }
 
+#define debug_(file, line, func, level, fmt, args...)                   \
+        ({                                                              \
+                if (efi_get_verbose() >= level) {                       \
+                        FILE *logfile_ = efi_get_logfile();             \
+                        int len_ = strlen(fmt);                         \
+                        fprintf(logfile_, "%s:%d %s(): ",               \
+                                file, line, func);                      \
+                        fprintf(logfile_, fmt, ## args);                \
+                        if (!len_ || fmt[len_ - 1] != '\n')             \
+                                fprintf(logfile_, "\n");                \
+                }                                                       \
+        })
+
+#define debug(level, fmt, args...) debug_(__FILE__, __LINE__, __func__, level, fmt, ## args)
+
+#define DEBUG 1
+
+extern void PUBLIC efi_set_verbose(int verbosity, FILE *errlog);
+extern int PUBLIC efi_get_verbose(void);
+extern FILE PUBLIC *efi_get_logfile(void);
+
 #endif /* EFIVAR_UTIL_H */