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