From 184f20c56576300343b8f8b60a8bebb185074485 Mon Sep 17 00:00:00 2001 From: Steve Grubb Date: Fri, 26 Apr 2024 12:44:56 -0400 Subject: [PATCH] Use atomic_int if available for signal related flags Reference:https://github.com/linux-audit/audit-userspace/commit/184f20c56576300343b8f8b60a8bebb185074485 Conflict:configure.ac --- configure.ac | 8 ++++++++ src/auditd-event.c | 5 ++++- src/auditd.c | 9 ++++++--- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index f2f2950..96a0fcc 100644 --- a/configure.ac +++ b/configure.ac @@ -85,6 +85,14 @@ AC_LINK_IFELSE( [AC_DEFINE(HAVE_STRNDUPA, 1, [Let us know if we have it or not])], [] ) + +AC_CHECK_HEADERS([stdatomic.h], [ + AC_DEFINE([HAVE_ATOMIC], 1, [Define to 1 if you have the header file.]) + AC_DEFINE([ATOMIC_INT], atomic_int, [Define atomic_int if you have the header file.]) + ], [ + AC_DEFINE([ATOMIC_INT], int, [Define to the type of an int if is not available.]) +]) + dnl; pthread_yield is used in zos-remote AC_SEARCH_LIBS(pthread_yield, pthread, [AC_DEFINE(HAVE_PTHREAD_YIELD, 1, [Define to 1 if we have pthread_yield])], []) diff --git a/src/auditd-event.c b/src/auditd-event.c index 847f5fe..c1e4b5a 100644 --- a/src/auditd-event.c +++ b/src/auditd-event.c @@ -36,6 +36,9 @@ #include /* POSIX_HOST_NAME_MAX */ #include /* toupper */ #include /* dirname */ +#ifdef HAVE_ATOMIC +#include +#endif #include "auditd-event.h" #include "auditd-dispatch.h" #include "auditd-listen.h" @@ -45,7 +48,7 @@ #include "auparse-idata.h" /* This is defined in auditd.c */ -extern volatile int stop; +extern volatile ATOMIC_INT stop; /* Local function prototypes */ static void send_ack(const struct auditd_event *e, int ack_type, diff --git a/src/auditd.c b/src/auditd.c index 34a9b57..75a180e 100644 --- a/src/auditd.c +++ b/src/auditd.c @@ -38,6 +38,9 @@ #include #include #include +#ifdef HAVE_ATOMIC +#include +#endif #include "libaudit.h" #include "auditd-event.h" @@ -62,7 +65,7 @@ #define SUBJ_LEN 4097 /* Global Data */ -volatile int stop = 0; +volatile ATOMIC_INT stop = 0; /* Local data */ static int fd = -1, pipefds[2] = {-1, -1}; @@ -72,8 +75,8 @@ static const char *state_file = "/var/run/auditd.state"; static int init_pipe[2]; static int do_fork = 1, opt_aggregate_only = 0, config_dir_set = 0; static struct auditd_event *cur_event = NULL, *reconfig_ev = NULL; -static int hup_info_requested = 0; -static int usr1_info_requested = 0, usr2_info_requested = 0; +static ATOMIC_INT hup_info_requested = 0; +static ATOMIC_INT usr1_info_requested = 0, usr2_info_requested = 0; static char subj[SUBJ_LEN]; static uint32_t session; static int hup_flag = 0; -- 2.33.0