forked from ElektraInitiative/libelektra
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuname.c
More file actions
113 lines (92 loc) · 2.94 KB
/
uname.c
File metadata and controls
113 lines (92 loc) · 2.94 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/**
* @file
*
* @brief
*
* @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
*/
#include "uname.h"
#include <errno.h>
#include <kdblogger.h>
#include <string.h>
#include <sys/utsname.h>
#ifndef HAVE_KDBCONFIG
#include "kdbconfig.h"
#endif
#include <kdberrors.h>
#include <kdbmacros.h>
static int elektraAddUname (KeySet * returned, Key * parentKey)
{
Key * dir;
Key * key = keyDup (parentKey, KEY_CP_ALL);
ksAppendKey (returned, key);
struct utsname buf;
if (uname (&buf) < 0)
{
ELEKTRA_SET_INTERFACE_ERRORF (parentKey, "Cannot retrieve uname info: %s", strerror (errno));
return -1;
}
dir = keyDup (parentKey, KEY_CP_ALL);
keyAddBaseName (dir, "sysname");
keySetString (dir, buf.sysname);
ksAppendKey (returned, dir);
dir = keyDup (parentKey, KEY_CP_ALL);
keyAddBaseName (dir, "nodename");
keySetString (dir, buf.nodename);
ksAppendKey (returned, dir);
dir = keyDup (parentKey, KEY_CP_ALL);
keyAddBaseName (dir, "release");
keySetString (dir, buf.release);
ksAppendKey (returned, dir);
dir = keyDup (parentKey, KEY_CP_ALL);
keyAddBaseName (dir, "version");
keySetString (dir, buf.version);
ksAppendKey (returned, dir);
dir = keyDup (parentKey, KEY_CP_ALL);
keyAddBaseName (dir, "machine");
keySetString (dir, buf.machine);
ksAppendKey (returned, dir);
return 0;
}
int elektraUnameGet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned, Key * parentKey)
{
ELEKTRA_LOG ("get uname %s from %s\n", keyName (parentKey), keyString (parentKey));
if (!strcmp (keyName (parentKey), "system:/elektra/modules/uname"))
{
KeySet * moduleConfig =
ksNew (50, keyNew ("system:/elektra/modules/uname", KEY_VALUE, "uname plugin waits for your orders", KEY_END),
keyNew ("system:/elektra/modules/uname/exports", KEY_END),
keyNew ("system:/elektra/modules/uname/exports/get", KEY_FUNC, elektraUnameGet, KEY_END),
keyNew ("system:/elektra/modules/uname/exports/set", KEY_FUNC, elektraUnameSet, KEY_END),
#include "readme_uname.c"
keyNew ("system:/elektra/modules/uname/infos/version", KEY_VALUE, PLUGINVERSION, KEY_END), KS_END);
ksAppend (returned, moduleConfig);
ksDel (moduleConfig);
return ELEKTRA_PLUGIN_STATUS_SUCCESS;
}
if (elektraAddUname (returned, parentKey) < 0)
{
return ELEKTRA_PLUGIN_STATUS_ERROR;
}
return ELEKTRA_PLUGIN_STATUS_SUCCESS;
}
int elektraUnameSet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned ELEKTRA_UNUSED, Key * parentKey)
{
ELEKTRA_LOG ("set uname %s from %s\n", keyName (parentKey), keyString (parentKey));
KeySet * info = ksNew (0, KS_END);
if (elektraAddUname (info, parentKey) < 0)
{
return ELEKTRA_PLUGIN_STATUS_ERROR;
}
ELEKTRA_SET_ERROR_READ_ONLY (info, returned, parentKey);
return ELEKTRA_PLUGIN_STATUS_NO_UPDATE;
}
Plugin * ELEKTRA_PLUGIN_EXPORT
{
// clang-format off
return elektraPluginExport ("uname",
ELEKTRA_PLUGIN_GET, &elektraUnameGet,
ELEKTRA_PLUGIN_SET, &elektraUnameSet,
ELEKTRA_PLUGIN_END
);
}