}
_DEFINE_ABS_WRAPPER(PRIVILEGE);
+/* Three different errors for writing on a filesystem */
+static inline bool ERRNO_IS_NEG_FS_WRITE_REFUSED(intmax_t r) {
+ return r == -EROFS || ERRNO_IS_NEG_PRIVILEGE(r);
+}
+_DEFINE_ABS_WRAPPER(FS_WRITE_REFUSED);
+
/* Three different errors for "not enough disk space" */
static inline bool ERRNO_IS_NEG_DISK_SPACE(intmax_t r) {
return IN_SET(r,
/* Returns the log level to use when cgroup attribute writes fail. When an attribute is missing or we have access
* problems we downgrade to LOG_DEBUG. This is supposed to be nice to container managers and kernels which want to mask
* out specific attributes from us. */
-#define LOG_LEVEL_CGROUP_WRITE(r) (IN_SET(ABS(r), ENOENT, EROFS, EACCES, EPERM) ? LOG_DEBUG : LOG_WARNING)
+#define LOG_LEVEL_CGROUP_WRITE(r) ((ABS(r) == ENOENT || ERRNO_IS_FS_WRITE_REFUSED(r)) ? LOG_DEBUG : LOG_WARNING)
static void unit_remove_from_cgroup_empty_queue(Unit *u);
* different, but the operation would fail silently.) */
r = sysctl_write("fs/file-max", LONG_MAX_STR);
if (r < 0)
- log_full_errno(IN_SET(r, -EROFS, -EPERM, -EACCES) ? LOG_DEBUG : LOG_WARNING,
- r, "Failed to bump fs.file-max, ignoring: %m");
+ log_full_errno(ERRNO_IS_NEG_FS_WRITE_REFUSED(r) ? LOG_DEBUG : LOG_WARNING, r,
+ "Failed to bump fs.file-max, ignoring: %m");
#endif
#if BUMP_PROC_SYS_FS_NR_OPEN
continue;
}
if (r < 0) {
- log_full_errno(IN_SET(r, -EROFS, -EPERM, -EACCES) ? LOG_DEBUG : LOG_WARNING, r, "Failed to bump fs.nr_open, ignoring: %m");
+ log_full_errno(ERRNO_IS_NEG_FS_WRITE_REFUSED(r) ? LOG_DEBUG : LOG_WARNING, r,
+ "Failed to bump fs.nr_open, ignoring: %m");
break;
}
r = sysctl_write("net/unix/max_dgram_qlen", STRINGIFY(DEFAULT_UNIX_MAX_DGRAM_QLEN));
if (r < 0)
- return log_full_errno(IN_SET(r, -EROFS, -EPERM, -EACCES) ? LOG_DEBUG : LOG_WARNING, r,
+ return log_full_errno(ERRNO_IS_NEG_FS_WRITE_REFUSED(r) ? LOG_DEBUG : LOG_WARNING, r,
"Failed to bump AF_UNIX datagram queue length, ignoring: %m");
return 1;
* when the path is on NFS. See issue #24120. All such errors will be logged in the debug level. */
if (r < 0 && r != -EEXIST)
log_unit_full_errno(UNIT(m),
- (r == -EROFS || ERRNO_IS_PRIVILEGE(r)) ? LOG_DEBUG : LOG_WARNING,
+ ERRNO_IS_NEG_FS_WRITE_REFUSED(r) ? LOG_DEBUG : LOG_WARNING,
r, "Failed to make bind mount source '%s', ignoring: %m", p->what);
}
log_debug_errno(r, "Timezone %s does not exist (or is not accessible) in container, not creating symlink: %m", z);
else {
if (unlink(where) < 0 && errno != ENOENT) {
- log_full_errno(IN_SET(errno, EROFS, EACCES, EPERM) ? LOG_DEBUG : LOG_WARNING, /* Don't complain on read-only images */
+ log_full_errno(ERRNO_IS_FS_WRITE_REFUSED(errno) ? LOG_DEBUG : LOG_WARNING, /* Don't complain on read-only images */
errno, "Failed to remove existing timezone info %s in container, ignoring: %m", where);
return 0;
}
what = strjoina("../usr/share/zoneinfo/", z);
if (symlink(what, where) < 0) {
- log_full_errno(IN_SET(errno, EROFS, EACCES, EPERM) ? LOG_DEBUG : LOG_WARNING,
+ log_full_errno(ERRNO_IS_FS_WRITE_REFUSED(errno) ? LOG_DEBUG : LOG_WARNING,
errno, "Failed to correct timezone of container, ignoring: %m");
return 0;
}
/* If mounting failed, try to copy */
r = copy_file_atomic("/etc/localtime", where, 0644, COPY_REFLINK|COPY_REPLACE);
if (r < 0) {
- log_full_errno(IN_SET(r, -EROFS, -EACCES, -EPERM) ? LOG_DEBUG : LOG_WARNING, r,
+ log_full_errno(ERRNO_IS_NEG_FS_WRITE_REFUSED(r) ? LOG_DEBUG : LOG_WARNING, r,
"Failed to copy /etc/localtime to %s, ignoring: %m", where);
return 0;
}
* If the disk image is read-only, there's also no point in complaining.
*/
log_full_errno(!IN_SET(RESOLV_CONF_COPY_HOST, RESOLV_CONF_COPY_STATIC, RESOLV_CONF_COPY_UPLINK, RESOLV_CONF_COPY_STUB) &&
- IN_SET(r, -ELOOP, -EROFS, -EACCES, -EPERM) ? LOG_DEBUG : LOG_WARNING, r,
+ (r == -ELOOP || ERRNO_IS_NEG_FS_WRITE_REFUSED(r)) ? LOG_DEBUG : LOG_WARNING, r,
"Failed to copy /etc/resolv.conf to %s, ignoring: %m", where);
return 0;
}
r = fd;
/* Retry read-only? */
- if (open_flags >= 0 || !(ERRNO_IS_PRIVILEGE(r) || r == -EROFS))
+ if (open_flags >= 0 || !ERRNO_IS_NEG_FS_WRITE_REFUSED(r))
return r;
fd = xopenat(dir_fd, path, basic_flags|direct_flags|O_RDONLY);
log_debug("Container manager does not provide /run/host/unix-export/ mount, not binding AF_UNIX socket there.");
return 0;
}
- if (errno == EROFS || ERRNO_IS_PRIVILEGE(errno)) {
+ if (ERRNO_IS_FS_WRITE_REFUSED(errno)) {
log_debug("Container manager does not provide write access to /run/host/unix-export/, not binding AF_UNIX socket there.");
return 0;
}
* permission problem here, since that's how container managers usually protected their
* sysctls.)
* In all other cases log an error and make the tool fail. */
- if (ignore_failure || (!arg_strict && (r == -EROFS || ERRNO_IS_PRIVILEGE(r))))
+ if (ignore_failure || (!arg_strict && ERRNO_IS_NEG_FS_WRITE_REFUSED(r)))
log_debug_errno(r, "Couldn't write '%s' to '%s', ignoring: %m", value, key);
else if (ignore_enoent && r == -ENOENT)
log_warning_errno(r, "Couldn't write '%s' to '%s', ignoring: %m", value, key);
(void) cg_trim(test_b, /* delete_root= */ true);
r = cg_create(test_a);
- if (IN_SET(r, -EPERM, -EACCES, -EROFS)) {
- log_info_errno(r, "Skipping %s: %m", __func__);
- return;
- }
+ if (ERRNO_IS_NEG_FS_WRITE_REFUSED(r))
+ return (void) log_tests_skipped_errno(r, "%s: Failed to create cgroup %s", __func__, test_a);
ASSERT_OK_EQ(r, 1);
ASSERT_OK_ZERO(cg_create(test_a));
log_info("Reducing limit by one to %"PRIu64"…", limit-1);
r = procfs_tasks_set_limit(limit-1);
- if (IN_SET(r, -ENOENT, -EROFS) || ERRNO_IS_PRIVILEGE(r))
+ if (r == -ENOENT || ERRNO_IS_NEG_FS_WRITE_REFUSED(r))
return log_tests_skipped_errno(r, "can't set tasks limit");
assert_se(r >= 0);
assert_se(STR_IN_SET(s, "0", "1"));
r = sysctl_write_ip_property(AF_INET, "lo", "forwarding", s, NULL);
- assert_se(r >= 0 || ERRNO_IS_PRIVILEGE(r) || r == -EROFS);
+ assert_se(r >= 0 || ERRNO_IS_NEG_FS_WRITE_REFUSED(r));
s = mfree(s);
assert_se(sysctl_read_ip_property(AF_INET, NULL, "ip_forward", &s));
assert_se(STR_IN_SET(s, "0", "1"));
r = sysctl_write_ip_property(AF_INET, NULL, "ip_forward", s, NULL);
- assert_se(r >= 0 || ERRNO_IS_PRIVILEGE(r) || r == -EROFS);
+ assert_se(r >= 0 || ERRNO_IS_NEG_FS_WRITE_REFUSED(r));
s = mfree(s);
assert_se(sysctl_read("kernel/hostname", &s) >= 0);
ASSERT_STREQ(s, u.nodename);
r = sysctl_write("kernel/hostname", s);
- assert_se(r >= 0 || ERRNO_IS_PRIVILEGE(r) || r == -EROFS);
+ assert_se(r >= 0 || ERRNO_IS_NEG_FS_WRITE_REFUSED(r));
}
DEFINE_TEST_MAIN(LOG_INFO);