From a8fe8e83447a39831a23d82a82614fc19f2b9b46 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Fri, 4 Jul 2025 17:05:38 +0200 Subject: [PATCH 1/2] core/mount: remove one more unused temporary variable Similar to 3cea9c403c6d5ff0edb2b8fc99884f2243b1456e, but for mount_get_what_escaped(). --- src/core/mount.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/core/mount.c b/src/core/mount.c index 801d2195b3..edbf7d201c 100644 --- a/src/core/mount.c +++ b/src/core/mount.c @@ -2415,7 +2415,6 @@ char* mount_get_where_escaped(const Mount *m) { } char* mount_get_what_escaped(const Mount *m) { - _cleanup_free_ char *escaped = NULL; const char *s = NULL; assert(m); @@ -2424,14 +2423,10 @@ char* mount_get_what_escaped(const Mount *m) { s = m->parameters_proc_self_mountinfo.what; else if (m->from_fragment && m->parameters_fragment.what) s = m->parameters_fragment.what; + if (!s) + return strdup(""); - if (s) { - escaped = utf8_escape_invalid(s); - if (!escaped) - return NULL; - } - - return escaped ? TAKE_PTR(escaped) : strdup(""); + return utf8_escape_invalid(s); } char* mount_get_options_escaped(const Mount *m) { From 6ebb91d92fb5ea7d43b22bec1b76cde1230b0e12 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Sun, 9 Feb 2025 23:12:15 +0100 Subject: [PATCH 2/2] core/mount: properly handle REMOUNTING_* states in mount_stop() Currently, mount_stop() simply turns REMOUNTING_* into corresponding UNMOUNTING_* states. However the transition is bogus, because the interruption of remount does not bring down the mount. Let's instead follow the logic of service_stop(), i.e. terminate the remount process and spawn umount. --- src/core/mount.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/core/mount.c b/src/core/mount.c index edbf7d201c..6e536ecc6b 100644 --- a/src/core/mount.c +++ b/src/core/mount.c @@ -1390,6 +1390,7 @@ static int mount_start(Unit *u) { static int mount_stop(Unit *u) { Mount *m = ASSERT_PTR(MOUNT(u)); + int r; switch (m->state) { @@ -1401,21 +1402,22 @@ static int mount_stop(Unit *u) { case MOUNT_MOUNTING: case MOUNT_MOUNTING_DONE: - case MOUNT_REMOUNTING: /* If we are still waiting for /bin/mount, we go directly into kill mode. */ mount_enter_signal(m, MOUNT_UNMOUNTING_SIGTERM, MOUNT_SUCCESS); return 0; + case MOUNT_REMOUNTING: case MOUNT_REMOUNTING_SIGTERM: - /* If we are already waiting for a hung remount, convert this to the matching unmounting state */ - mount_set_state(m, MOUNT_UNMOUNTING_SIGTERM); - return 0; + assert(pidref_is_set(&m->control_pid)); + r = pidref_kill_and_sigcont(&m->control_pid, SIGKILL); + if (r < 0) + log_unit_debug_errno(u, r, + "Failed to kill remount process " PID_FMT ", ignoring: %m", + m->control_pid.pid); + + _fallthrough_; case MOUNT_REMOUNTING_SIGKILL: - /* as above */ - mount_set_state(m, MOUNT_UNMOUNTING_SIGKILL); - return 0; - case MOUNT_MOUNTED: mount_enter_unmounting(m); return 1;