tree-wide: Include <libaudit.h> via libaudit-util.h

Let's keep the ifdeffery for the include in one place.
This commit is contained in:
Daan De Meyer
2025-05-21 12:22:40 +02:00
parent 9f23910935
commit cdd5fac068
7 changed files with 13 additions and 36 deletions

View File

@@ -3,19 +3,13 @@
#include <errno.h>
#include "audit-fd.h"
#if HAVE_AUDIT
# include <stdbool.h>
# include "libaudit-util.h"
# include "capability-util.h"
#include "capability-util.h"
#include "libaudit-util.h"
static bool initialized = false;
static int audit_fd = -EBADF;
#endif
int get_core_audit_fd(void) {
#if HAVE_AUDIT
if (!initialized) {
if (have_effective_cap(CAP_AUDIT_WRITE) <= 0)
audit_fd = -EPERM;
@@ -26,15 +20,10 @@ int get_core_audit_fd(void) {
}
return audit_fd;
#else
return -EAFNOSUPPORT;
#endif
}
void close_core_audit_fd(void) {
#if HAVE_AUDIT
close_audit_fd(audit_fd);
initialized = true;
audit_fd = -ECONNRESET;
#endif
}

View File

@@ -12,10 +12,6 @@
#include <sys/wait.h>
#include <unistd.h>
#if HAVE_AUDIT
#include <libaudit.h>
#endif
#include "sd-daemon.h"
#include "sd-messages.h"
#include "sd-path.h"
@@ -58,6 +54,7 @@
#include "io-util.h"
#include "iovec-util.h"
#include "label-util.h"
#include "libaudit-util.h"
#include "load-fragment.h"
#include "locale-setup.h"
#include "log.h"

View File

@@ -7,9 +7,6 @@
#include <errno.h>
#include <selinux/avc.h>
#include <selinux/selinux.h>
#if HAVE_AUDIT
#include <libaudit.h>
#endif
#include "sd-bus.h"
@@ -18,6 +15,7 @@
#include "bus-util.h"
#include "errno-util.h"
#include "format-util.h"
#include "libaudit-util.h"
#include "log.h"
#include "path-util.h"
#include "selinux-util.h"

View File

@@ -6,10 +6,6 @@
#include <stdio.h>
#include <sys/socket.h>
#if HAVE_AUDIT
# include <libaudit.h>
#endif
#include "fd-util.h"
#include "iovec-util.h"
#include "libaudit-util.h"
@@ -100,14 +96,15 @@ int close_audit_fd(int fd) {
}
int open_audit_fd_or_warn(void) {
int fd = -EBADF;
#if HAVE_AUDIT
/* If the kernel lacks netlink or audit support, don't worry about it. */
fd = audit_open();
int fd = audit_open();
if (fd < 0)
return log_full_errno(ERRNO_IS_NOT_SUPPORTED(errno) ? LOG_DEBUG : LOG_WARNING,
errno, "Failed to connect to audit log, ignoring: %m");
#endif
return fd;
#else
return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "libaudit support not compiled in");
#endif
}

View File

@@ -1,6 +1,10 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#if HAVE_AUDIT
# include <libaudit.h>
#endif
#include <stdbool.h>
bool use_audit(void);

View File

@@ -4,10 +4,6 @@
#include <stdlib.h>
#include <sys/stat.h>
#if HAVE_AUDIT
# include <libaudit.h>
#endif
#include "alloc-util.h"
#include "build.h"
#include "chase.h"

View File

@@ -2,10 +2,6 @@
#include <sys/stat.h>
#if HAVE_AUDIT
# include <libaudit.h>
#endif
#include "sd-bus.h"
#include "alloc-util.h"