bootctl: do not print slash more than once

When bootctl is called by an unprivileged user, then previously we got
```
Failed to read "/boot/EFI/systemd": Permission denied
Failed to open '/boot//loader/loader.conf': Permission denied
```
Now, with this patch, we get
```
Failed to read "/boot/EFI/systemd": Permission denied
Failed to open '/boot/loader/loader.conf': Permission denied
```
This commit is contained in:
Yu Watanabe
2025-05-31 10:24:17 +09:00
committed by Zbigniew Jędrzejewski-Szmek
parent 0af9937691
commit 91c60ff528
3 changed files with 8 additions and 8 deletions

View File

@@ -880,7 +880,7 @@ static int install_variables(
if (r == -ENOENT)
return 0;
if (r < 0)
return log_error_errno(r, "Cannot access \"%s/%s\": %m", esp_path, path);
return log_error_errno(r, "Cannot access \"%s/%s\": %m", esp_path, skip_leading_slash(path));
r = find_slot(uuid, path, &slot);
if (r < 0) {

View File

@@ -215,7 +215,7 @@ static int enumerate_binaries(
if (r == -ENOENT)
return 0;
if (r < 0)
return log_error_errno(r, "Failed to read \"%s/%s\": %m", esp_path, path);
return log_error_errno(r, "Failed to read \"%s/%s\": %m", esp_path, skip_leading_slash(path));
FOREACH_DIRENT(de, d, break) {
_cleanup_free_ char *v = NULL, *filename = NULL;
@@ -855,7 +855,7 @@ static int cleanup_orphaned_files(
if (dir_fd == -ENOENT)
return 0;
if (dir_fd < 0)
return log_error_errno(dir_fd, "Failed to open '%s/%s': %m", root, arg_entry_token);
return log_error_errno(dir_fd, "Failed to open '%s/%s': %m", root, skip_leading_slash(arg_entry_token));
p = path_join("/", arg_entry_token);
if (!p)

View File

@@ -536,7 +536,7 @@ static int boot_loader_read_conf_path(BootConfig *config, const char *root, cons
if (r == -ENOENT)
return 0;
if (r < 0)
return log_error_errno(r, "Failed to open '%s/%s': %m", root, path);
return log_error_errno(r, "Failed to open '%s/%s': %m", root, skip_leading_slash(path));
return boot_loader_read_conf(config, f, full);
}
@@ -648,7 +648,7 @@ static int boot_entries_find_type1(
if (dir_fd == -ENOENT)
return 0;
if (dir_fd < 0)
return log_error_errno(dir_fd, "Failed to open '%s/%s': %m", root, dir);
return log_error_errno(dir_fd, "Failed to open '%s/%s': %m", root, skip_leading_slash(dir));
r = readdir_all(dir_fd, RECURSE_DIR_IGNORE_DOT, &dentries);
if (r < 0)
@@ -1111,7 +1111,7 @@ static int boot_entries_find_unified_addons(
if (r == -ENOENT)
return 0;
if (r < 0)
return log_error_errno(r, "Failed to open '%s/%s': %m", root, addon_dir);
return log_error_errno(r, "Failed to open '%s/%s': %m", root, skip_leading_slash(addon_dir));
FOREACH_DIRENT(de, d, return log_error_errno(errno, "Failed to read %s: %m", full)) {
_cleanup_free_ char *j = NULL, *cmdline = NULL, *location = NULL;
@@ -1173,7 +1173,7 @@ static int boot_entries_find_unified_global_addons(
if (r == -ENOENT)
return 0;
if (r < 0)
return log_error_errno(r, "Failed to open '%s/%s': %m", root, d_name);
return log_error_errno(r, "Failed to open '%s/%s': %m", root, skip_leading_slash(d_name));
return boot_entries_find_unified_addons(config, dirfd(d), d_name, root, ret_addons);
}
@@ -1213,7 +1213,7 @@ static int boot_entries_find_unified(
if (r == -ENOENT)
return 0;
if (r < 0)
return log_error_errno(r, "Failed to open '%s/%s': %m", root, dir);
return log_error_errno(r, "Failed to open '%s/%s': %m", root, skip_leading_slash(dir));
FOREACH_DIRENT(de, d, return log_error_errno(errno, "Failed to read %s: %m", full)) {
if (!dirent_is_file(de))