]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test-seccomp: Handle environment where sync() is already suppressed
authorDaan De Meyer <daan@amutable.com>
Sun, 5 Apr 2026 19:29:31 +0000 (21:29 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 14 Apr 2026 18:35:24 +0000 (20:35 +0200)
We might be running in an nspawn container booted with --suppress-sync,
so make sure we handle that scenario gracefully.

src/test/test-seccomp.c

index d40abf24e4dc65d6a4d5c0418ccf39eea100a6e7..44682b4a2c02353ed803f7b8f766547b09444db1 100644 (file)
@@ -1095,20 +1095,23 @@ static void test_seccomp_suppress_sync_child(void) {
         _cleanup_close_ int fd = -EBADF;
 
         ASSERT_OK(tempfn_random("/tmp/seccomp_suppress_sync", NULL, &path));
-        ASSERT_OK_ERRNO(fd = open(path, O_RDWR | O_CREAT | O_SYNC | O_CLOEXEC, 0666));
-        fd = safe_close(fd);
-
-        ASSERT_ERROR_ERRNO(fdatasync(-1), EBADF);
-        ASSERT_ERROR_ERRNO(fsync(-1), EBADF);
-        ASSERT_ERROR_ERRNO(syncfs(-1), EBADF);
-
-        ASSERT_ERROR_ERRNO(fdatasync(INT_MAX), EBADF);
-        ASSERT_ERROR_ERRNO(fsync(INT_MAX), EBADF);
-        ASSERT_ERROR_ERRNO(syncfs(INT_MAX), EBADF);
+        fd = open(path, O_RDWR | O_CREAT | O_SYNC | O_CLOEXEC, 0666);
+        /* We might be running in an environment where sync() is already suppressed. */
+        if (fd >= 0) {
+                ASSERT_ERROR_ERRNO(fdatasync(-1), EBADF);
+                ASSERT_ERROR_ERRNO(fsync(-1), EBADF);
+                ASSERT_ERROR_ERRNO(syncfs(-1), EBADF);
+
+                ASSERT_ERROR_ERRNO(fdatasync(INT_MAX), EBADF);
+                ASSERT_ERROR_ERRNO(fsync(INT_MAX), EBADF);
+                ASSERT_ERROR_ERRNO(syncfs(INT_MAX), EBADF);
+        } else if (errno != EINVAL)
+                ASSERT_OK_ERRNO(fd);
 
         ASSERT_OK(seccomp_suppress_sync());
 
-        ASSERT_ERROR_ERRNO(fd = open(path, O_RDWR | O_CREAT | O_SYNC | O_CLOEXEC, 0666), EINVAL);
+        fd = safe_close(fd);
+        fd = ASSERT_ERROR_ERRNO(open(path, O_RDWR | O_CREAT | O_SYNC | O_CLOEXEC, 0666), EINVAL);
 
         ASSERT_OK_ERRNO(fdatasync(INT_MAX));
         ASSERT_OK_ERRNO(fsync(INT_MAX));