1
0
mirror of https://github.com/systemd/systemd synced 2026-04-03 13:44:55 +02:00

Compare commits

..

No commits in common. "6681eb021a0b56ef0dc849e3b358a515ece16482" and "2db32618fe8e7305aa6f25db8b1d4a00aaafa264" have entirely different histories.

9 changed files with 26 additions and 137 deletions

View File

@ -465,18 +465,10 @@ struct mount_attr;
#define MOUNT_ATTR_IDMAP 0x00100000 #define MOUNT_ATTR_IDMAP 0x00100000
#endif #endif
#ifndef MOUNT_ATTR_NOSYMFOLLOW
#define MOUNT_ATTR_NOSYMFOLLOW 0x00200000
#endif
#ifndef AT_RECURSIVE #ifndef AT_RECURSIVE
#define AT_RECURSIVE 0x8000 #define AT_RECURSIVE 0x8000
#endif #endif
#ifndef MOUNT_ATTR_SIZE_VER0
#define MOUNT_ATTR_SIZE_VER0 32
#endif
static inline int missing_mount_setattr( static inline int missing_mount_setattr(
int dfd, int dfd,
const char *path, const char *path,

View File

@ -3043,15 +3043,12 @@ int unit_check_oom(Unit *u) {
return 0; return 0;
r = cg_get_keyed_attribute("memory", u->cgroup_path, "memory.events", STRV_MAKE("oom_kill"), &oom_kill); r = cg_get_keyed_attribute("memory", u->cgroup_path, "memory.events", STRV_MAKE("oom_kill"), &oom_kill);
if (IN_SET(r, -ENOENT, -ENXIO)) /* Handle gracefully if cgroup or oom_kill attribute don't exist */ if (r < 0)
c = 0;
else if (r < 0)
return log_unit_debug_errno(u, r, "Failed to read oom_kill field of memory.events cgroup attribute: %m"); return log_unit_debug_errno(u, r, "Failed to read oom_kill field of memory.events cgroup attribute: %m");
else {
r = safe_atou64(oom_kill, &c); r = safe_atou64(oom_kill, &c);
if (r < 0) if (r < 0)
return log_unit_debug_errno(u, r, "Failed to parse oom_kill field: %m"); return log_unit_debug_errno(u, r, "Failed to parse oom_kill field: %m");
}
increased = c > u->oom_kill_last; increased = c > u->oom_kill_last;
u->oom_kill_last = c; u->oom_kill_last = c;

View File

@ -562,9 +562,6 @@ static int manager_varlink_init_user(Manager *m) {
if (m->managed_oom_varlink) if (m->managed_oom_varlink)
return 1; return 1;
if (MANAGER_IS_TEST_RUN(m))
return 0;
r = varlink_connect_address(&link, VARLINK_ADDR_PATH_MANAGED_OOM_USER); r = varlink_connect_address(&link, VARLINK_ADDR_PATH_MANAGED_OOM_USER);
if (r == -ENOENT || ERRNO_IS_DISCONNECT(r)) { if (r == -ENOENT || ERRNO_IS_DISCONNECT(r)) {
log_debug("systemd-oomd varlink unix socket not found, skipping user manager varlink setup"); log_debug("systemd-oomd varlink unix socket not found, skipping user manager varlink setup");

View File

@ -134,31 +134,6 @@ int umount_recursive(const char *prefix, int flags) {
return n; return n;
} }
#define MS_CONVERTIBLE_FLAGS (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_NOSYMFOLLOW)
static uint64_t ms_flags_to_mount_attr(unsigned long a) {
uint64_t f = 0;
if (FLAGS_SET(a, MS_RDONLY))
f |= MOUNT_ATTR_RDONLY;
if (FLAGS_SET(a, MS_NOSUID))
f |= MOUNT_ATTR_NOSUID;
if (FLAGS_SET(a, MS_NODEV))
f |= MOUNT_ATTR_NODEV;
if (FLAGS_SET(a, MS_NOEXEC))
f |= MOUNT_ATTR_NOEXEC;
if (FLAGS_SET(a, MS_NOSYMFOLLOW))
f |= MOUNT_ATTR_NOSYMFOLLOW;
return f;
}
static bool skip_mount_set_attr = false;
/* Use this function only if you do not have direct access to /proc/self/mountinfo but the caller can open it /* Use this function only if you do not have direct access to /proc/self/mountinfo but the caller can open it
* for you. This is the case when /proc is masked or not mounted. Otherwise, use bind_remount_recursive. */ * for you. This is the case when /proc is masked or not mounted. Otherwise, use bind_remount_recursive. */
int bind_remount_recursive_with_mountinfo( int bind_remount_recursive_with_mountinfo(
@ -168,44 +143,12 @@ int bind_remount_recursive_with_mountinfo(
char **deny_list, char **deny_list,
FILE *proc_self_mountinfo) { FILE *proc_self_mountinfo) {
_cleanup_fclose_ FILE *proc_self_mountinfo_opened = NULL;
_cleanup_set_free_ Set *done = NULL; _cleanup_set_free_ Set *done = NULL;
unsigned n_tries = 0; unsigned n_tries = 0;
int r; int r;
assert(prefix); assert(prefix);
assert(proc_self_mountinfo);
if ((flags_mask & ~MS_CONVERTIBLE_FLAGS) == 0 && strv_isempty(deny_list) && !skip_mount_set_attr) {
/* Let's take a shortcut for all the flags we know how to convert into mount_setattr() flags */
if (mount_setattr(AT_FDCWD, prefix, AT_SYMLINK_NOFOLLOW|AT_RECURSIVE,
&(struct mount_attr) {
.attr_set = ms_flags_to_mount_attr(new_flags & flags_mask),
.attr_clr = ms_flags_to_mount_attr(~new_flags & flags_mask),
}, MOUNT_ATTR_SIZE_VER0) < 0) {
log_debug_errno(errno, "mount_setattr() failed, falling back to classic remounting: %m");
/* We fall through to classic behaviour if not supported (i.e. kernel < 5.12). We
* also do this for all other kinds of errors since they are so many different, and
* mount_setattr() has no graceful mode where it continues despite seeing errors one
* some mounts, but we want that. Moreover mount_setattr() only works on the mount
* point inode itself, not a non-mount point inode, and we want to support arbitrary
* prefixes here. */
if (ERRNO_IS_NOT_SUPPORTED(errno)) /* if not supported, then don't bother at all anymore */
skip_mount_set_attr = true;
} else
return 0; /* Nice, this worked! */
}
if (!proc_self_mountinfo) {
r = fopen_unlocked("/proc/self/mountinfo", "re", &proc_self_mountinfo_opened);
if (r < 0)
return r;
proc_self_mountinfo = proc_self_mountinfo_opened;
}
/* Recursively remount a directory (and all its submounts) with desired flags (MS_READONLY, /* Recursively remount a directory (and all its submounts) with desired flags (MS_READONLY,
* MS_NOSUID, MS_NOEXEC). If the directory is already mounted, we reuse the mount and simply mark it * MS_NOSUID, MS_NOEXEC). If the directory is already mounted, we reuse the mount and simply mark it
@ -400,6 +343,22 @@ int bind_remount_recursive_with_mountinfo(
} }
} }
int bind_remount_recursive(
const char *prefix,
unsigned long new_flags,
unsigned long flags_mask,
char **deny_list) {
_cleanup_fclose_ FILE *proc_self_mountinfo = NULL;
int r;
r = fopen_unlocked("/proc/self/mountinfo", "re", &proc_self_mountinfo);
if (r < 0)
return r;
return bind_remount_recursive_with_mountinfo(prefix, new_flags, flags_mask, deny_list, proc_self_mountinfo);
}
int bind_remount_one_with_mountinfo( int bind_remount_one_with_mountinfo(
const char *path, const char *path,
unsigned long new_flags, unsigned long new_flags,
@ -415,23 +374,6 @@ int bind_remount_one_with_mountinfo(
assert(path); assert(path);
assert(proc_self_mountinfo); assert(proc_self_mountinfo);
if ((flags_mask & ~MS_CONVERTIBLE_FLAGS) == 0 && !skip_mount_set_attr) {
/* Let's take a shortcut for all the flags we know how to convert into mount_setattr() flags */
if (mount_setattr(AT_FDCWD, path, AT_SYMLINK_NOFOLLOW,
&(struct mount_attr) {
.attr_set = ms_flags_to_mount_attr(new_flags & flags_mask),
.attr_clr = ms_flags_to_mount_attr(~new_flags & flags_mask),
}, MOUNT_ATTR_SIZE_VER0) < 0) {
log_debug_errno(errno, "mount_setattr() didn't work, falling back to classic remounting: %m");
if (ERRNO_IS_NOT_SUPPORTED(errno)) /* if not supported, then don't bother at all anymore */
skip_mount_set_attr = true;
} else
return 0; /* Nice, this worked! */
}
rewind(proc_self_mountinfo); rewind(proc_self_mountinfo);
table = mnt_new_table(); table = mnt_new_table();

View File

@ -40,12 +40,8 @@ int mount_nofollow(const char *source, const char *target, const char *filesyste
int repeat_unmount(const char *path, int flags); int repeat_unmount(const char *path, int flags);
int umount_recursive(const char *target, int flags); int umount_recursive(const char *target, int flags);
int bind_remount_recursive(const char *prefix, unsigned long new_flags, unsigned long flags_mask, char **deny_list);
int bind_remount_recursive_with_mountinfo(const char *prefix, unsigned long new_flags, unsigned long flags_mask, char **deny_list, FILE *proc_self_mountinfo); int bind_remount_recursive_with_mountinfo(const char *prefix, unsigned long new_flags, unsigned long flags_mask, char **deny_list, FILE *proc_self_mountinfo);
static inline int bind_remount_recursive(const char *prefix, unsigned long new_flags, unsigned long flags_mask, char **deny_list) {
return bind_remount_recursive_with_mountinfo(prefix, new_flags, flags_mask, deny_list, NULL);
}
int bind_remount_one_with_mountinfo(const char *path, unsigned long new_flags, unsigned long flags_mask, FILE *proc_self_mountinfo); int bind_remount_one_with_mountinfo(const char *path, unsigned long new_flags, unsigned long flags_mask, FILE *proc_self_mountinfo);
int mount_move_root(const char *path); int mount_move_root(const char *path);

View File

@ -169,7 +169,7 @@ static void test_bind_remount_recursive(void) {
assert_se(!FLAGS_SET(svfs.f_flag, ST_RDONLY)); assert_se(!FLAGS_SET(svfs.f_flag, ST_RDONLY));
/* Now mark the path we currently run for read-only */ /* Now mark the path we currently run for read-only */
assert_se(bind_remount_recursive(p, MS_RDONLY, MS_RDONLY, path_equal(p, "/sys") ? STRV_MAKE("/sys/kernel") : NULL) >= 0); assert_se(bind_remount_recursive(p, MS_RDONLY, MS_RDONLY, STRV_MAKE("/sys/kernel")) >= 0);
/* Ensure that this worked on the top-level */ /* Ensure that this worked on the top-level */
assert_se(statvfs(p, &svfs) >= 0); assert_se(statvfs(p, &svfs) >= 0);
@ -209,7 +209,6 @@ static void test_bind_remount_one(void) {
assert_se(fopen_unlocked("/proc/self/mountinfo", "re", &proc_self_mountinfo) >= 0); assert_se(fopen_unlocked("/proc/self/mountinfo", "re", &proc_self_mountinfo) >= 0);
assert_se(bind_remount_one_with_mountinfo("/run", MS_RDONLY, MS_RDONLY, proc_self_mountinfo) >= 0); assert_se(bind_remount_one_with_mountinfo("/run", MS_RDONLY, MS_RDONLY, proc_self_mountinfo) >= 0);
assert_se(bind_remount_one_with_mountinfo("/run", MS_NOEXEC, MS_RDONLY|MS_NOEXEC, proc_self_mountinfo) >= 0);
assert_se(bind_remount_one_with_mountinfo("/proc/idontexist", MS_RDONLY, MS_RDONLY, proc_self_mountinfo) == -ENOENT); assert_se(bind_remount_one_with_mountinfo("/proc/idontexist", MS_RDONLY, MS_RDONLY, proc_self_mountinfo) == -ENOENT);
assert_se(bind_remount_one_with_mountinfo("/proc/self", MS_RDONLY, MS_RDONLY, proc_self_mountinfo) == -EINVAL); assert_se(bind_remount_one_with_mountinfo("/proc/self", MS_RDONLY, MS_RDONLY, proc_self_mountinfo) == -EINVAL);
assert_se(bind_remount_one_with_mountinfo("/", MS_RDONLY, MS_RDONLY, proc_self_mountinfo) >= 0); assert_se(bind_remount_one_with_mountinfo("/", MS_RDONLY, MS_RDONLY, proc_self_mountinfo) >= 0);

View File

@ -827,7 +827,6 @@ int udev_event_spawn(UdevEvent *event,
static int rename_netif(UdevEvent *event) { static int rename_netif(UdevEvent *event) {
sd_device *dev = event->dev; sd_device *dev = event->dev;
const char *oldname; const char *oldname;
unsigned flags;
int ifindex, r; int ifindex, r;
if (!event->name) if (!event->name)
@ -855,16 +854,6 @@ static int rename_netif(UdevEvent *event) {
return 0; return 0;
} }
r = rtnl_get_link_info(&event->rtnl, ifindex, NULL, &flags);
if (r < 0)
return log_device_warning_errno(dev, r, "Failed to get link flags: %m");
if (FLAGS_SET(flags, IFF_UP)) {
log_device_info(dev, "Network interface '%s' is already up, refusing to rename to '%s'.",
oldname, event->name);
return 0;
}
/* Set ID_RENAMING boolean property here, and drop it in the corresponding move uevent later. */ /* Set ID_RENAMING boolean property here, and drop it in the corresponding move uevent later. */
r = device_add_property(dev, "ID_RENAMING", "1"); r = device_add_property(dev, "ID_RENAMING", "1");
if (r < 0) if (r < 0)

View File

@ -7,16 +7,4 @@ TEST_DESCRIPTION="https://github.com/systemd/systemd/issues/2467"
# shellcheck source=test/test-functions # shellcheck source=test/test-functions
. "${TEST_BASE_DIR:?}/test-functions" . "${TEST_BASE_DIR:?}/test-functions"
test_append_files() {
(
# Collecting coverage slows this particular test quite a bit, causing
# it to fail with the default settings (20 triggers per 2 secs)
# to trip over the default limit. Let's help it a bit in such case.
if get_bool "$IS_BUILT_WITH_COVERAGE"; then
mkdir -p "${initdir:?}/etc/systemd/system/test10.socket.d"
printf "[Socket]\nTriggerLimitIntervalSec=10\n" >"${initdir:?}/etc/systemd/system/test10.socket.d/coverage-override.conf"
fi
)
}
do_test "$@" do_test "$@"

View File

@ -1316,19 +1316,8 @@ check_coverage_reports() {
# Create a coverage report that will later be uploaded. Remove info about # Create a coverage report that will later be uploaded. Remove info about
# system libraries/headers, as we don't really care about them. # system libraries/headers, as we don't really care about them.
if [[ -f "$dest" ]]; then lcov --directory "${root}/${BUILD_DIR:?}" --capture --output-file "${dest}"
# If the destination report file already exists, don't overwrite it, but lcov --remove "${dest}" -o "${dest}" '/usr/include/*' '/usr/lib/*'
# dump the new report in a temporary file and then merge it with the already
# present one - this usually happens when running both "parts" of a test
# in one run (the qemu and the nspawn part).
lcov --directory "${root}/${BUILD_DIR:?}" --capture --output-file "${dest}.new"
lcov --remove "${dest}.new" -o "${dest}.new" '/usr/include/*' '/usr/lib/*'
lcov --add-tracefile "${dest}" --add-tracefile "${dest}.new" -o "${dest}"
rm -f "${dest}.new"
else
lcov --directory "${root}/${BUILD_DIR:?}" --capture --output-file "${dest}"
lcov --remove "${dest}" -o "${dest}" '/usr/include/*' '/usr/lib/*'
fi
return 0 return 0
} }