Skip to content

Commit 93fdff5

Browse files
committed
Add FAN_FS_ERROR configure switch
FAN_FS_ERROR monitoring opens a second fanotify notification group and closes it during daemon shutdown. The blocked-task trace from the hang is in the fanotify group close path, so deployments need a build-time way to remove that newer descriptor while testing kernel shutdown behavior against older fapolicyd behavior. Add --disable-fanotify-fs-error, default it to enabled, and gate the FAN_FS_ERROR implementation on the configure define as well as kernel header support. The disabled build keeps the public helpers as no-ops and logs that monitoring was disabled by configure so the runtime behavior is explicit. Tests were updated so notify_test only exercises synthetic FAN_FS_ERROR events when the configure switch enables the implementation.
1 parent 1234249 commit 93fdff5

3 files changed

Lines changed: 31 additions & 5 deletions

File tree

configure.ac

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,23 @@ if test $perm = "no"; then
151151
fi
152152
AC_CHECK_DECLS([FAN_MARK_FILESYSTEM], [], [], [[#include <linux/fanotify.h>]])
153153

154+
AC_ARG_ENABLE(fanotify-fs-error,
155+
AS_HELP_STRING([--disable-fanotify-fs-error],
156+
[disable FAN_FS_ERROR health monitoring even when supported]),
157+
[enable_fanotify_fs_error=$enableval],
158+
[enable_fanotify_fs_error=yes])
159+
case x$enable_fanotify_fs_error in
160+
xyes)
161+
AC_DEFINE([FAPOLICYD_ENABLE_FANOTIFY_FS_ERROR], [1],
162+
[Define to enable FAN_FS_ERROR health monitoring])
163+
;;
164+
xno)
165+
;;
166+
*)
167+
AC_MSG_ERROR([bad value $enableval for --enable-fanotify-fs-error])
168+
;;
169+
esac
170+
154171
withval=""
155172
AC_ARG_WITH(rpm,
156173
AS_HELP_STRING([--with-rpm],[Use the rpm database as a trust source]),
@@ -238,5 +255,6 @@ echo "
238255
`echo $LDFLAGS | fmt -w 50 | sed 's,^, ,'`
239256
__attr_access support: $ACCESS
240257
__attr_dealloc_free support: $DEALLOC
258+
FAN_FS_ERROR monitoring: $enable_fanotify_fs_error
241259
"
242260

src/daemon/fanotify-fs-error.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@
3636
* queue handled by notify.c.
3737
*
3838
* Header and kernel support vary across supported build targets. Public entry
39-
* points stay available even when FAN_FS_ERROR symbols are absent; in that case
40-
* initialization reports that monitoring is unavailable and all other helpers
41-
* become harmless no-ops.
39+
* points stay available even when FAN_FS_ERROR symbols are absent or configure
40+
* disables this monitor; in that case initialization reports that monitoring is
41+
* unavailable and all other helpers become harmless no-ops.
4242
*/
4343

4444
#include "config.h" /* Needed to get O_LARGEFILE definition */
@@ -62,7 +62,8 @@
6262
#define FANOTIFY_FS_ERROR_BUFFER_SIZE 8192
6363
#define FS_ERROR_LOG_INTERVAL 60
6464

65-
#if defined(FAN_FS_ERROR) && defined(FAN_REPORT_FID) && \
65+
#if defined(FAPOLICYD_ENABLE_FANOTIFY_FS_ERROR) && \
66+
defined(FAN_FS_ERROR) && defined(FAN_REPORT_FID) && \
6667
defined(FAN_MARK_FILESYSTEM) && \
6768
defined(FAN_EVENT_INFO_TYPE_ERROR) && \
6869
defined(FAN_EVENT_INFO_TYPE_FID)
@@ -599,9 +600,14 @@ void fanotify_fs_error_unmark(const char *path)
599600
int fanotify_fs_error_init(mlist *m)
600601
{
601602
(void)m;
603+
#if defined(FAPOLICYD_ENABLE_FANOTIFY_FS_ERROR)
602604
msg(LOG_INFO,
603605
"FAN_FS_ERROR monitoring disabled; kernel headers do not provide "
604606
"the required fanotify info records");
607+
#else
608+
msg(LOG_INFO,
609+
"FAN_FS_ERROR monitoring disabled by configure option");
610+
#endif
605611
return -1;
606612
}
607613
#endif

src/tests/notify_test.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*
22
* notify_test.c - unit tests for daemon fanotify metadata handling
33
*/
4+
#include "config.h"
45
#include <error.h>
56
#include <errno.h>
67
#include <stdbool.h>
@@ -23,7 +24,8 @@
2324
#define FAN_Q_OVERFLOW 0x00004000
2425
#endif
2526

26-
#if defined(FAN_FS_ERROR) && defined(FAN_REPORT_FID) && \
27+
#if defined(FAPOLICYD_ENABLE_FANOTIFY_FS_ERROR) && \
28+
defined(FAN_FS_ERROR) && defined(FAN_REPORT_FID) && \
2729
defined(FAN_MARK_FILESYSTEM) && \
2830
defined(FAN_EVENT_INFO_TYPE_ERROR) && \
2931
defined(FAN_EVENT_INFO_TYPE_FID)

0 commit comments

Comments
 (0)