[irqbalance] [RFC][PATCH 1/5] Added option for journal-style logging

  • From: Andrej Manduch <amanduch@xxxxxxxxx>
  • To: irqbalance@xxxxxxxxxxxxx
  • Date: Tue, 3 Mar 2015 12:51:42 -0500

From: Andrej Manduch <AManduch@xxxxxxxxx>

Signed-off-by: Andrej Manduch <amanduch@xxxxxxxxx>
---
 configure.ac |  8 ++++++++
 irqbalance.1 |  4 ++++
 irqbalance.c | 21 +++++++++++++++++----
 3 files changed, 29 insertions(+), 4 deletions(-)

diff --git a/configure.ac b/configure.ac
index 885f10b..b054ebd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -30,6 +30,14 @@ AC_C_CONST
 AC_C_INLINE
 AM_PROG_CC_C_O
 
+AC_ARG_WITH([systemd],
+  [ AS_HELP_STRING([--with-systemd],[Add systemd logging support])],
+)
+AS_IF(
+  [test "x$with_systemd" = xyes],
+    [AC_DEFINE(HAVE_SYSTEMD, 1, [systemd support])]
+)
+
 AC_ARG_WITH([glib2],
   [AS_HELP_STRING([--without-glib2],
     [Don't use system glib2 library. Use local implementation instead.])],
diff --git a/irqbalance.1 b/irqbalance.1
index b6f451a..14d5d98 100644
--- a/irqbalance.1
+++ b/irqbalance.1
@@ -46,6 +46,10 @@ Causes irqbalance to print extra debug information.  Implies 
--foreground.
 Causes irqbalance to run in the foreground (without --debug).
 
 .TP
+.B -j, --journal
+Enables log output optimized for systemd-journal.
+
+.TP
 .B -h, --hintpolicy=[exact | subset | ignore]
 Set the policy for how IRQ kernel affinity hinting is treated.  Can be one of:
 .P
diff --git a/irqbalance.c b/irqbalance.c
index bb8c3da..4059ef5 100644
--- a/irqbalance.c
+++ b/irqbalance.c
@@ -46,6 +46,7 @@ int one_shot_mode;
 int debug_mode;
 int foreground_mode;
 int numa_avail;
+int journal_logging = 0;
 int need_rescan;
 unsigned int log_mask = TO_ALL;
 enum hp_e global_hint_policy = HINT_POLICY_IGNORE;
@@ -83,12 +84,15 @@ 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}
 };
 
 static void usage(void)
 {
-       log(TO_CONSOLE, LOG_INFO, "irqbalance [--oneshot | -o] [--debug | -d] 
[--foreground | -f] [--hintpolicy= | -h [exact|subset|ignore]]\n");
+       log(TO_CONSOLE, LOG_INFO, "irqbalance [--oneshot | -o] [--debug | -d] 
[--foreground | -f] [--journal | -j] [--hintpolicy= | -h 
[exact|subset|ignore]]\n");
        log(TO_CONSOLE, LOG_INFO, "     [--powerthresh= | -p <off> | <n>] 
[--banirq= | -i <n>] [--policyscript=<script>] [--pid= | -s <file>] 
[--deepestcache= | -c <n>]\n");
 }
 
@@ -99,7 +103,7 @@ static void parse_command_line(int argc, char **argv)
        unsigned long val;
 
        while ((opt = getopt_long(argc, argv,
-               "odfh:i:p:s:c:b:l:",
+               "odfjh:i:p:s:c:b:l:",
                lopts, &longind)) != -1) {
 
                switch(opt) {
@@ -173,6 +177,11 @@ static void parse_command_line(int argc, char **argv)
                        case 's':
                                pidfile = optarg;
                                break;
+#ifdef HAVE_SYSTEMD
+                       case 'j':
+                               journal_logging=1;
+                               break;
+#endif /* HAVE_SYSTEMD */
                }
        }
 }
@@ -250,7 +259,7 @@ int main(int argc, char** argv)
 
 #ifdef HAVE_GETOPT_LONG
        parse_command_line(argc, argv);
-#else
+#else /* ! HAVE_GETOPT_LONG */
        if (argc>1 && strstr(argv[1],"--debug")) {
                debug_mode=1;
                foreground_mode=1;
@@ -259,7 +268,11 @@ int main(int argc, char** argv)
                foreground_mode=1;
        if (argc>1 && strstr(argv[1],"--oneshot"))
                one_shot_mode=1;
-#endif
+#      ifdef HAVE_SYSTEMD
+       if (argc>1 && strstr(argv[1],"--journal"))
+               journal_logging=1;
+#      endif /* HAVE_SYSTEMD */
+#endif /* HAVE_GETOPT_LONG */
 
        /*
         * Open the syslog connection
-- 
2.1.0


Other related posts:

  • » [irqbalance] [RFC][PATCH 1/5] Added option for journal-style logging - Andrej Manduch