]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
bootctl: do not print slash more than once
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 31 May 2025 01:24:17 +0000 (10:24 +0900)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 31 May 2025 11:53:04 +0000 (13:53 +0200)
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
```

src/bootctl/bootctl-install.c
src/bootctl/bootctl-status.c
src/shared/bootspec.c

index c1a08b604903c48ba44c15a8cf800c96372de03e..816a4c8ac0fa406232f16c774630f630b63446c2 100644 (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) {
index 352ab48ce70e5d6c94a2f8c18b41d0dc7a6eea58..9715c91d2690a90d940fedd4f0f322c13fe87a62 100644 (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)
index f57a3d57407035c994363cf31734e72f777b1358..980c8c53ad51aade3c98a1b625ff1d08428749ee 100644 (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))