diff --git a/configure.ac b/configure.ac index b054ebd..0b152f7 100644 --- a/configure.ac +++ b/configure.ac @@ -31,12 +31,15 @@ AC_C_INLINE AM_PROG_CC_C_O AC_ARG_WITH([systemd], - [ AS_HELP_STRING([--with-systemd],[Add systemd logging support])], + [ AS_HELP_STRING([--with-systemd],[Add systemd-lib support])] ) AS_IF( - [test "x$with_systemd" = xyes], - [AC_DEFINE(HAVE_SYSTEMD, 1, [systemd support])] -) + [test "x$with_systemd" = xyes], [ + PKG_CHECK_MODULES([SYSTEMD], [libsystemd-journal], [journal_lib=yes]) + AC_DEFINE(HAVE_LIBSYSTEMD, 1, [systemd support]) + AC_CHECK_LIB([systemd], [sd_journal_print_with_location]) + AC_CHECK_LIB([systemd], [sd_journal_print]) +]) AC_ARG_WITH([glib2], [AS_HELP_STRING([--without-glib2], diff --git a/irqbalance.c b/irqbalance.c index f25e9a9..a5079b9 100644 --- a/irqbalance.c +++ b/irqbalance.c @@ -85,9 +85,7 @@ struct option lopts[] = { {"deepestcache", 1, NULL, 'c'}, {"policyscript", 1, NULL, 'l'}, {"pid", 1, NULL, 's'}, -#ifdef HAVE_SYSTEMD {"journal", 0, NULL, 'j'}, -#endif /* HAVE_SYSTEMD */ {0, 0, 0, 0} }; @@ -178,13 +176,10 @@ static void parse_command_line(int argc, char **argv) case 's': pidfile = optarg; break; -#ifdef HAVE_SYSTEMD case 'j': journal_logging=1; foreground_mode=1; - debug_mode=1; break; -#endif /* HAVE_SYSTEMD */ } } } @@ -270,13 +265,10 @@ int main(int argc, char** argv) foreground_mode=1; if (argc>1 && strstr(argv[1],"--oneshot")) one_shot_mode=1; -# ifdef HAVE_SYSTEMD if (argc>1 && strstr(argv[1],"--journal")) { journal_logging=1; foreground_mode=1; - debug_mode=1; } -# endif /* HAVE_SYSTEMD */ #endif /* HAVE_GETOPT_LONG */ /* diff --git a/irqbalance.h b/irqbalance.h index 98d2193..a498dc2 100644 --- a/irqbalance.h +++ b/irqbalance.h @@ -12,12 +12,17 @@ #include #include "types.h" +#include "config.h" #ifdef HAVE_NUMA_H #include #else #define numa_available() -1 #endif +#ifdef HAVE_LIBSYSTEMD +#include +#endif + extern int package_count; extern int cache_domain_count; extern int core_count; @@ -137,9 +142,22 @@ static inline void for_each_object(GList *list, void (*cb)(struct topo_obj *obj, extern char * log_indent; extern unsigned int log_mask; -#ifdef HAVE_SYSTEMD +#ifdef HAVE_LIBSYSTEMD #define log(mask, lvl, fmt, args...) do { \ - if (journal_logging) { \ + if (journal_logging) { \ + sd_journal_print(lvl, fmt, ##args); \ + if (log_mask & mask & TO_CONSOLE) \ + printf(fmt, ##args); \ + } else { \ + if (log_mask & mask & TO_SYSLOG) \ + syslog(lvl, fmt, ##args); \ + if (log_mask & mask & TO_CONSOLE) \ + printf(fmt, ##args); \ + } \ +}while(0) +#else /* ! HAVE_LIBSYSTEMD */ +#define log(mask, lvl, fmt, args...) do { \ + if (journal_logging) { \ printf("<%d>", lvl); \ printf(fmt, ##args); \ } else { \ @@ -149,14 +167,7 @@ extern unsigned int log_mask; printf(fmt, ##args); \ } \ }while(0) -#else /* ! HAVE_SYSTEMD */ -#define log(mask, lvl, fmt, args...) do {\ - if (log_mask & mask & TO_SYSLOG)\ - syslog(lvl, fmt, ##args);\ - if (log_mask & mask & TO_CONSOLE)\ - printf(fmt, ##args);\ -}while(0) -#endif /* HAVE_SYSTEMD */ +#endif /* HAVE_LIBSYSTEMD */ #endif /* __INCLUDE_GUARD_IRQBALANCE_H_ */