]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/core/audit-fd.c
Revert "core: add IgnoreOnSoftReboot= unit option"
[thirdparty/systemd.git] / src / core / audit-fd.c
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2
3 #include <errno.h>
4
5 #include "audit-fd.h"
6
7 #if HAVE_AUDIT
8
9 #include <libaudit.h>
10 #include <stdbool.h>
11
12 #include "capability-util.h"
13 #include "fd-util.h"
14 #include "log.h"
15
16 static bool initialized = false;
17 static int audit_fd;
18
19 int get_audit_fd(void) {
20
21 if (!initialized) {
22 if (have_effective_cap(CAP_AUDIT_WRITE) <= 0) {
23 audit_fd = -EPERM;
24 initialized = true;
25
26 return audit_fd;
27 }
28
29 audit_fd = audit_open();
30
31 if (audit_fd < 0) {
32 if (!IN_SET(errno, EAFNOSUPPORT, EPROTONOSUPPORT))
33 log_error_errno(errno, "Failed to connect to audit log: %m");
34
35 audit_fd = errno ? -errno : -EINVAL;
36 }
37
38 initialized = true;
39 }
40
41 return audit_fd;
42 }
43
44 void close_audit_fd(void) {
45
46 if (initialized && audit_fd >= 0)
47 safe_close(audit_fd);
48
49 initialized = true;
50 audit_fd = -ECONNRESET;
51 }
52
53 #else
54
55 int get_audit_fd(void) {
56 return -EAFNOSUPPORT;
57 }
58
59 void close_audit_fd(void) {
60 }
61
62 #endif