From 3955b5e29e119122dc2fc0a53ba82529613e4e1c Mon Sep 17 00:00:00 2001
From: Steve Grubb <sgrubb@redhat.com>
Date: Fri, 26 Apr 2024 14:03:02 -0400
Subject: [PATCH] Use atomic_uint if available for signal related flags

Reference:https://github.com/linux-audit/audit-userspace/commit/3955b5e29e119122dc2fc0a53ba82529613e4e1c
Conflict:configure.ac

---
 audisp/audispd.c | 7 +++++--
 audisp/queue.c   | 9 ++++++---
 configure.ac     | 2 ++
 3 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/audisp/audispd.c b/audisp/audispd.c
index 0172e12..8be0e8f 100644
--- a/audisp/audispd.c
+++ b/audisp/audispd.c
@@ -41,6 +41,9 @@
 #include <limits.h>
 #include <sys/uio.h>
 #include <getopt.h>
+#ifdef HAVE_ATOMIC
+#include <stdatomic.h>
+#endif
 
 #include "audispd-pconfig.h"
 #include "audispd-config.h"
@@ -51,8 +54,8 @@
 #include "private.h"
 
 /* Global Data */
-static volatile int stop = 0;
-volatile int disp_hup = 0;
+static volatile ATOMIC_INT stop = 0;
+volatile ATOMIC_INT disp_hup = 0;
 
 /* Local data */
 static daemon_conf_t daemon_config;
diff --git a/audisp/queue.c b/audisp/queue.c
index 2b7ea43..6204453 100644
--- a/audisp/queue.c
+++ b/audisp/queue.c
@@ -25,17 +25,20 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <syslog.h>
+#ifdef HAVE_ATOMIC
+#include <stdatomic.h>
+#endif
 #include "queue.h"
 
 static volatile event_t **q;
 static pthread_mutex_t queue_lock;
 static pthread_cond_t queue_nonempty;
-static unsigned int q_next, q_last, q_depth, processing_suspended;
-static unsigned int currently_used, max_used, overflowed;
+static unsigned int q_next, q_last, q_depth, processing_suspended, overflowed;
+static ATOMIC_UNSIGNED currently_used, max_used;
 static const char *SINGLE = "1";
 static const char *HALT = "0";
 static int queue_full_warning = 0;
-extern volatile int disp_hup;
+extern volatile ATOMIC_INT disp_hup;
 #define QUEUE_FULL_LIMIT 5
 
 void reset_suspended(void)
diff --git a/configure.ac b/configure.ac
index 96a0fcc..57c961a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -89,8 +89,10 @@ AC_LINK_IFELSE(
 AC_CHECK_HEADERS([stdatomic.h], [
     AC_DEFINE([HAVE_ATOMIC], 1, [Define to 1 if you have the <stdatomic.h> header file.])
     AC_DEFINE([ATOMIC_INT], atomic_int, [Define atomic_int if you have the <stdatomic.h> header file.])
+    AC_DEFINE([ATOMIC_UNSIGNED], atomic_uint, [Define atomic_uint if you have the <stdatomic.h> header file.])
   ], [
     AC_DEFINE([ATOMIC_INT], int, [Define to the type of an int if <stdatomic.h> is not available.])
+    AC_DEFINE([ATOMIC_UNSIGNED], unsigned, [Define to the type of an unsigned if <stdatomic.h> is not available.])
 ])
 
 dnl; pthread_yield is used in zos-remote
-- 
2.33.0

