From: Luca Boccassi Date: Thu, 28 Mar 2024 11:11:45 +0000 (+0000) Subject: Ensure that a portable is not detached when another portable that shares the same... X-Git-Tag: v256-rc1~294^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1cbb79276319923e6f2ebbbc6b5e127a14c16154;p=thirdparty%2Fsystemd.git Ensure that a portable is not detached when another portable that shares the same base is detached The matches line includes all images, but the logic returned immediately with a successful match if the first element matches. --- diff --git a/src/portable/portable.c b/src/portable/portable.c index a83f7b68cbb..a544a013421 100644 --- a/src/portable/portable.c +++ b/src/portable/portable.c @@ -1685,26 +1685,28 @@ static bool marker_matches_images(const char *marker, const char *name_or_path, if (r < 0) return r; - STRV_FOREACH(image_name_or_path, root_and_extensions) { - _cleanup_free_ char *image = NULL, *base_image = NULL, *base_image_name_or_path = NULL; + /* Ensure the number of images passed matches the number of images listed in the marker */ + while (!isempty(marker)) + STRV_FOREACH(image_name_or_path, root_and_extensions) { + _cleanup_free_ char *image = NULL, *base_image = NULL, *base_image_name_or_path = NULL; - r = extract_first_word(&marker, &image, ":", EXTRACT_UNQUOTE|EXTRACT_RETAIN_ESCAPE); - if (r < 0) - return log_debug_errno(r, "Failed to parse marker: %s", marker); - if (r == 0) - return false; + r = extract_first_word(&marker, &image, ":", EXTRACT_UNQUOTE|EXTRACT_RETAIN_ESCAPE); + if (r < 0) + return log_debug_errno(r, "Failed to parse marker: %s", marker); + if (r == 0) + return false; - r = path_extract_image_name(image, &base_image); - if (r < 0) - return log_debug_errno(r, "Failed to extract image name from %s, ignoring: %m", image); + r = path_extract_image_name(image, &base_image); + if (r < 0) + return log_debug_errno(r, "Failed to extract image name from %s, ignoring: %m", image); - r = path_extract_image_name(*image_name_or_path, &base_image_name_or_path); - if (r < 0) - return log_debug_errno(r, "Failed to extract image name from %s, ignoring: %m", *image_name_or_path); + r = path_extract_image_name(*image_name_or_path, &base_image_name_or_path); + if (r < 0) + return log_debug_errno(r, "Failed to extract image name from %s, ignoring: %m", *image_name_or_path); - if (!streq(base_image, base_image_name_or_path)) - return false; - } + if (!streq(base_image, base_image_name_or_path)) + return false; + } return true; } diff --git a/test/units/testsuite-29.sh b/test/units/testsuite-29.sh index adafdbbecc5..d529286c6ce 100755 --- a/test/units/testsuite-29.sh +++ b/test/units/testsuite-29.sh @@ -224,6 +224,30 @@ test -f /run/systemd/system.attached/app0.service test -L /run/systemd/system.attached/app0.service.d/10-profile.conf portablectl detach --runtime --extension /usr/share/app0.raw /usr/share/minimal_0.raw app0 +# Ensure that when two portables share the same base image, removing one doesn't remove the other too + +portablectl "${ARGS[@]}" attach --runtime --extension /usr/share/app0.raw /usr/share/minimal_0.raw app0 +portablectl "${ARGS[@]}" attach --runtime --extension /usr/share/app1.raw /usr/share/minimal_0.raw app1 + +status="$(portablectl is-attached --extension app0 minimal_0)" +[[ "${status}" == "attached-runtime" ]] +status="$(portablectl is-attached --extension app1 minimal_0)" +[[ "${status}" == "attached-runtime" ]] + +(! portablectl detach --runtime /usr/share/minimal_0.raw app) + +status="$(portablectl is-attached --extension app0 minimal_0)" +[[ "${status}" == "attached-runtime" ]] +status="$(portablectl is-attached --extension app1 minimal_0)" +[[ "${status}" == "attached-runtime" ]] + +portablectl detach --runtime --extension /usr/share/app0.raw /usr/share/minimal_0.raw app + +status="$(portablectl is-attached --extension app1 minimal_0)" +[[ "${status}" == "attached-runtime" ]] + +portablectl detach --runtime --extension /usr/share/app1.raw /usr/share/minimal_0.raw app + # portablectl also works with directory paths rather than images mkdir /tmp/rootdir /tmp/app0 /tmp/app1 /tmp/overlay /tmp/os-release-fix /tmp/os-release-fix/etc