Debian Codegraph @

src/core/audit-fd.c

raw
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2
3 #include "audit-fd.h"
4 #include "capability-util.h"
5 #include "libaudit-util.h"
6
7 static bool initialized = false;
8 static int audit_fd = -EBADF;
9
10 int get_core_audit_fd(void) {
11 if (!initialized) {
12 if (have_effective_cap(CAP_AUDIT_WRITE) <= 0)
13 audit_fd = -EPERM;
14 else
15 audit_fd = open_audit_fd_or_warn();
16
17 initialized = true;
18 }
19
20 return audit_fd;
21 }
22
23 void close_core_audit_fd(void) {
24 close_audit_fd(audit_fd);
25 initialized = true;
26 audit_fd = -ECONNRESET;
27 }