From 6bbae9f8b33081b3647b7314497067e78363adc1 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 5 Jul 2021 14:48:16 +0200 Subject: [PATCH] repart: don't prefix /sysroot/ twice For some reason I first commited a73b2ad041469bf20e3771725dcf70069451e116 and then 8f47e32a3eefa1a366510b5d752875dd56bd7708. But the latter makes the former obsolete and causes us to suffix paths twice. Let's hence revert a73b2ad041469bf20e3771725dcf70069451e116 and stick to 8f47e32a3eefa1a366510b5d752875dd56bd7708 as the latter is the ore generic solution of the two. --- src/partition/repart.c | 56 +++--------------------------------------- 1 file changed, 3 insertions(+), 53 deletions(-) diff --git a/src/partition/repart.c b/src/partition/repart.c index 589acaa49d..a53d0fbe8e 100644 --- a/src/partition/repart.c +++ b/src/partition/repart.c @@ -4529,49 +4529,14 @@ static int acquire_root_devno( if (r < 0) return log_debug_errno(r, "Failed to determine canonical path for '%s': %m", p); - /* Only if we still lock at the same block device we can reuse the fd. Otherwise return an + /* Only if we still look at the same block device we can reuse the fd. Otherwise return an * invalidated fd. */ *ret_fd = fd_devno != MODE_INVALID && fd_devno == devno ? TAKE_FD(fd) : -1; return 0; } -static int find_os_prefix(const char **ret) { - int r; - - assert(ret); - - /* Searches for the right place to look for the OS root. This is relevant in the initrd: in the - * initrd the host OS is typically mounted to /sysroot/ — except in setups where /usr/ is a separate - * partition, in which case it is mounted to /sysusr/usr/ before being moved to /sysroot/usr/. */ - - if (!in_initrd()) { - *ret = NULL; /* no prefix */ - return 0; - } - - r = path_is_mount_point("/sysroot", NULL, 0); - if (r < 0 && r != -ENOENT) - log_debug_errno(r, "Failed to determine whether /sysroot/ is a mount point, assuming it is not: %m"); - else if (r > 0) { - log_debug("/sysroot/ is a mount point, assuming it's the prefix."); - *ret = "/sysroot"; - return 0; - } - - r = path_is_mount_point("/sysusr/usr", NULL, 0); - if (r < 0 && r != -ENOENT) - log_debug_errno(r, "Failed to determine whether /sysusr/usr is a mount point, assuming it is not: %m"); - else if (r > 0) { - log_debug("/sysusr/usr/ is a mount point, assuming /sysusr/ is the prefix."); - *ret = "/sysusr"; - return 0; - } - - return -ENOENT; -} - static int find_root(char **ret, int *ret_fd) { - const char *t, *prefix; + const char *p; int r; assert(ret); @@ -4612,22 +4577,7 @@ static int find_root(char **ret, int *ret_fd) { * latter we check for cases where / is a tmpfs and only /usr is an actual persistent block device * (think: volatile setups) */ - r = find_os_prefix(&prefix); - if (r < 0) - return log_error_errno(r, "Failed to determine OS prefix: %m"); - - FOREACH_STRING(t, "/", "/usr") { - _cleanup_free_ char *j = NULL; - const char *p; - - if (prefix) { - j = path_join(prefix, t); - if (!j) - return log_oom(); - - p = j; - } else - p = t; + FOREACH_STRING(p, "/", "/usr") { r = acquire_root_devno(p, arg_root, O_RDONLY|O_DIRECTORY|O_CLOEXEC, ret, ret_fd); if (r < 0) { -- 2.25.1