@@ -51,6 +51,10 @@ static struct tcase {
51
51
"Limited queue" ,
52
52
FAN_CLASS_NOTIF ,
53
53
},
54
+ {
55
+ "Limited queue (FAN_REPORT_FD_ERROR)" ,
56
+ FAN_CLASS_NOTIF | FAN_REPORT_FD_ERROR ,
57
+ },
54
58
{
55
59
"Unlimited queue" ,
56
60
FAN_CLASS_NOTIF | FAN_UNLIMITED_QUEUE ,
@@ -63,6 +67,8 @@ static char symlnk[BUF_SIZE];
63
67
static char fdpath [BUF_SIZE ];
64
68
static int fd , fd_notify ;
65
69
70
+ static int fd_error_unsupported ;
71
+
66
72
static struct fanotify_event_metadata event ;
67
73
68
74
static void event_res (struct fanotify_event_metadata * event , int i )
@@ -110,9 +116,15 @@ static void test_fanotify(unsigned int n)
110
116
int len , nevents = 0 , got_overflow = 0 ;
111
117
int num_files = max_events + 1 ;
112
118
int expect_overflow = !(tc -> init_flags & FAN_UNLIMITED_QUEUE );
119
+ int nofd_err = tc -> init_flags & FAN_REPORT_FD_ERROR ? - EBADF : FAN_NOFD ;
113
120
114
121
tst_res (TINFO , "Test #%d: %s" , n , tc -> tname );
115
122
123
+ if (fd_error_unsupported && (tc -> init_flags & FAN_REPORT_FD_ERROR )) {
124
+ FANOTIFY_INIT_FLAGS_ERR_MSG (FAN_REPORT_FD_ERROR , fd_error_unsupported );
125
+ return ;
126
+ }
127
+
116
128
fd_notify = SAFE_FANOTIFY_INIT (tc -> init_flags | FAN_NONBLOCK , O_RDONLY );
117
129
118
130
SAFE_FANOTIFY_MARK (fd_notify , FAN_MARK_MOUNT | FAN_MARK_ADD , FAN_OPEN ,
@@ -142,7 +154,7 @@ static void test_fanotify(unsigned int n)
142
154
tst_res (expect_overflow ? TFAIL : TPASS , "Overflow event not generated!\n" );
143
155
break ;
144
156
}
145
- if (event .fd != FAN_NOFD ) {
157
+ if (event .fd >= 0 ) {
146
158
/*
147
159
* Verify that events generated on unique files
148
160
* are received by the same order they were generated.
@@ -166,7 +178,7 @@ static void test_fanotify(unsigned int n)
166
178
break ;
167
179
}
168
180
if (event .mask == FAN_Q_OVERFLOW ) {
169
- if (got_overflow || event .fd != FAN_NOFD ) {
181
+ if (got_overflow || event .fd != nofd_err ) {
170
182
tst_res (TFAIL ,
171
183
"%s overflow event: mask=%llx pid=%u fd=%d" ,
172
184
got_overflow ? "unexpected" : "invalid" ,
@@ -193,6 +205,8 @@ static void setup(void)
193
205
fd = SAFE_FANOTIFY_INIT (FAN_CLASS_NOTIF , O_RDONLY );
194
206
SAFE_CLOSE (fd );
195
207
208
+ fd_error_unsupported = fanotify_init_flags_supported_on_fs (FAN_REPORT_FD_ERROR , "." );
209
+
196
210
/* In older kernels this limit is fixed in kernel */
197
211
if (access (SYSFS_MAX_EVENTS , F_OK ) && errno == ENOENT )
198
212
max_events = DEFAULT_MAX_EVENTS ;
0 commit comments