LCOV - code coverage report
Current view: top level - src/plugins/journald - journald.c (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 8 16 50.0 %
Date: 2019-09-12 12:28:41 Functions: 2 5 40.0 %

          Line data    Source code
       1             : /**
       2             :  * @file
       3             :  *
       4             :  * @brief A plugin which logs write operations and errors via the native journald interface
       5             :  *
       6             :  * @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
       7             :  *
       8             :  */
       9             : 
      10             : #ifndef HAVE_KDBCONFIG
      11             : #include "kdbconfig.h"
      12             : #endif
      13             : 
      14             : #include <stdlib.h>
      15             : #include <systemd/sd-journal.h>
      16             : #include <unistd.h>
      17             : 
      18             : #include "journald.h"
      19             : 
      20          20 : int elektraJournaldGet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned, Key * parentKey ELEKTRA_UNUSED)
      21             : {
      22          20 :         if (!strcmp (keyName (parentKey), "system/elektra/modules/journald"))
      23             :         {
      24             :                 KeySet * n;
      25          20 :                 ksAppend (
      26             :                         returned,
      27          20 :                         n = ksNew (30,
      28             :                                    keyNew ("system/elektra/modules/journald", KEY_VALUE, "journald plugin waits for your orders", KEY_END),
      29             :                                    keyNew ("system/elektra/modules/journald/exports", KEY_END),
      30             :                                    keyNew ("system/elektra/modules/journald/exports/get", KEY_FUNC, elektraJournaldGet, KEY_END),
      31             :                                    keyNew ("system/elektra/modules/journald/exports/set", KEY_FUNC, elektraJournaldSet, KEY_END),
      32             :                                    keyNew ("system/elektra/modules/journald/exports/error", KEY_FUNC, elektraJournaldError, KEY_END),
      33             : #include "readme_journald.c"
      34             :                                    keyNew ("system/elektra/modules/journald/infos/version", KEY_VALUE, PLUGINVERSION, KEY_END), KS_END));
      35          20 :                 ksDel (n);
      36          20 :                 return 1;
      37             :         }
      38             : 
      39           0 :         if (strncmp (keyString (ksLookupByName (elektraPluginGetConfig (handle), "/log/get", 0)), "1", 1) == 0)
      40             :         {
      41           0 :                 sd_journal_send ("MESSAGE=loading configuration %s", keyName (parentKey), "MESSAGE_ID=fc65eab25c18463f97e4f9b61ea31eae",
      42             :                                  "PRIORITY=5", /* notice priority */
      43             :                                  "HOME=%s", getenv ("HOME"), "USER=%s", getenv ("USER"), "PAGE_SIZE=%li", sysconf (_SC_PAGESIZE),
      44             :                                  "N_CPUS=%li", sysconf (_SC_NPROCESSORS_ONLN), NULL);
      45             :         }
      46             : 
      47             :         return 1;
      48             : }
      49             : 
      50           0 : int elektraJournaldSet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned, Key * parentKey)
      51             : {
      52           0 :         sd_journal_send ("MESSAGE=committed configuration %s with %zd keys", keyName (parentKey), ksGetSize (returned),
      53             :                          "MESSAGE_ID=fc65eab25c18463f97e4f9b61ea31eae", "PRIORITY=5", /* notice priority */
      54             :                          "HOME=%s", getenv ("HOME"), "USER=%s", getenv ("USER"), "PAGE_SIZE=%li", sysconf (_SC_PAGESIZE), "N_CPUS=%li",
      55             :                          sysconf (_SC_NPROCESSORS_ONLN), NULL);
      56           0 :         return 1;
      57             : }
      58             : 
      59           0 : int elektraJournaldError (Plugin * handle ELEKTRA_UNUSED, KeySet * returned, Key * parentKey)
      60             : {
      61           0 :         sd_journal_send ("MESSAGE=rollback configuration %s with %zd keys", keyName (parentKey), ksGetSize (returned),
      62             :                          "MESSAGE_ID=fb3928ea453048649c61d62619847ef6", "PRIORITY=3", /* error priority */
      63             :                          "HOME=%s", getenv ("HOME"), "USER=%s", getenv ("USER"), "PAGE_SIZE=%li", sysconf (_SC_PAGESIZE), "N_CPUS=%li",
      64             :                          sysconf (_SC_NPROCESSORS_ONLN), NULL);
      65             : 
      66           0 :         return 1; /* success */
      67             : }
      68             : 
      69          20 : Plugin * ELEKTRA_PLUGIN_EXPORT
      70             : {
      71             :         // clang-format off
      72          20 :         return elektraPluginExport ("journald",
      73             :                 ELEKTRA_PLUGIN_GET,     &elektraJournaldGet,
      74             :                 ELEKTRA_PLUGIN_SET,     &elektraJournaldSet,
      75             :                 ELEKTRA_PLUGIN_ERROR,   &elektraJournaldError,
      76             :                 ELEKTRA_PLUGIN_END);
      77             : }

Generated by: LCOV version 1.13