Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F159974241
D57451.id179305.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D57451.id179305.diff
View Options
diff --git a/contrib/openbsm/bin/auditd/auditd_fbsd.c b/contrib/openbsm/bin/auditd/auditd_fbsd.c
--- a/contrib/openbsm/bin/auditd/auditd_fbsd.c
+++ b/contrib/openbsm/bin/auditd/auditd_fbsd.c
@@ -33,6 +33,7 @@
#include <errno.h>
#include <fcntl.h>
+#include <poll.h>
#include <stdarg.h>
#include <signal.h>
#include <string.h>
@@ -57,10 +58,7 @@
*/
static int max_idletime = 0;
-static int sigchlds, sigchlds_handled;
-static int sighups, sighups_handled;
-static int sigterms, sigterms_handled;
-static int sigalrms, sigalrms_handled;
+static volatile sig_atomic_t signaled[NSIG];
static int triggerfd = 0;
@@ -207,48 +205,66 @@
void
auditd_wait_for_events(void)
{
- int num;
+ sigset_t oset, set;
+ struct pollfd pfd;
+ ssize_t ret;
unsigned int trigger;
+ sigemptyset(&set);
+ sigaddset(&set, SIGTERM);
+ sigaddset(&set, SIGALRM);
+ sigaddset(&set, SIGCHLD);
+ sigaddset(&set, SIGHUP);
+ sigprocmask(SIG_BLOCK, &set, &oset);
+ pfd.fd = triggerfd;
+ pfd.events = POLLIN;
+ pfd.revents = 0;
for (;;) {
- num = read(triggerfd, &trigger, sizeof(trigger));
- if ((num == -1) && (errno != EINTR)) {
- auditd_log_err("%s: error %d", __FUNCTION__, errno);
- return;
- }
-
/* Reset the idle time alarm, if used. */
- if (max_idletime)
+ if (max_idletime != 0)
alarm(max_idletime);
- if (sigterms != sigterms_handled) {
+ /* Check signals first as some may have occurred already */
+ if (signaled[SIGTERM]) {
+ signaled[SIGTERM] = 0;
auditd_log_debug("%s: SIGTERM", __FUNCTION__);
auditd_terminate();
/* not reached */
}
- if (sigalrms != sigalrms_handled) {
+ if (signaled[SIGALRM]) {
+ signaled[SIGALRM] = 0;
auditd_log_debug("%s: SIGALRM", __FUNCTION__);
auditd_terminate();
/* not reached */
}
- if (sigchlds != sigchlds_handled) {
- sigchlds_handled = sigchlds;
+ if (signaled[SIGCHLD]) {
+ signaled[SIGCHLD] = 0;
auditd_reap_children();
}
- if (sighups != sighups_handled) {
+ if (signaled[SIGHUP]) {
+ signaled[SIGHUP] = 0;
auditd_log_debug("%s: SIGHUP", __FUNCTION__);
- sighups_handled = sighups;
auditd_config_controls();
}
- if (num == -1)
+ /* Now wait for a trigger */
+ if ((ret = ppoll(&pfd, 1, NULL, &oset)) < 0 && errno != EINTR) {
+ auditd_log_err("%s: error %d", __FUNCTION__, errno);
+ break;
+ }
+ if (ret <= 0)
continue;
- if (num == 0) {
+ if ((ret = read(triggerfd, &trigger, sizeof(trigger))) < 0) {
+ auditd_log_err("%s: error %d", __FUNCTION__, errno);
+ break;
+ }
+ if (ret == 0) {
auditd_log_err("%s: read EOF", __FUNCTION__);
- return;
+ break;
}
auditd_handle_trigger(trigger);
}
+ sigprocmask(SIG_SETMASK, &oset, NULL);
}
/*
@@ -258,15 +274,8 @@
* context.
*/
void
-auditd_relay_signal(int signal)
+auditd_relay_signal(int signo)
{
- if (signal == SIGHUP)
- sighups++;
- if (signal == SIGTERM)
- sigterms++;
- if (signal == SIGCHLD)
- sigchlds++;
- if (signal == SIGALRM)
- sigalrms++;
-}
+ signaled[signo] = 1;
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Jun 21, 3:13 AM (19 h, 55 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
33786486
Default Alt Text
D57451.id179305.diff (3 KB)
Attached To
Mode
D57451: auditd: Fix signal handling
Attached
Detach File
Event Timeline
Log In to Comment