mirror of
https://github.com/systemd/systemd.git
synced 2026-08-12 12:16:06 +00:00
test-seccomp: Handle environment where sync() is already suppressed
We might be running in an nspawn container booted with --suppress-sync, so make sure we handle that scenario gracefully. (cherry picked from commit31441cb782) (cherry picked from commit4f974b5492)
This commit is contained in:
committed by
Luca Boccassi
parent
db2ae46225
commit
6c2be56375
@@ -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);
|
||||
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(-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);
|
||||
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));
|
||||
|
||||
Reference in New Issue
Block a user