]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
pretty-print: do not fail when cat_files() tries to show a masked file
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 13 Jan 2026 06:39:39 +0000 (15:39 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 20 Jan 2026 02:05:54 +0000 (11:05 +0900)
Before 661b5bfd216e383ac7836261eea9671875e6709b, cat_files() does not
check if a file is regular. If the file is a symlink to /dev/null, then
cat_files() simply shows an empty contents for the file.
With the offending commit, as the CHASE_MUST_BE_REGULAR flag is set,
hence when we found a masked file, the function fails.

Fixes #40313.
Fixes regression caused by 661b5bfd216e383ac7836261eea9671875e6709b.

Co-authored-by: gvenugo3 <gvenugo3@asu.edu>
(cherry picked from commit f2125229234e798272f0c05ec99ec15e48d10fc0)

src/shared/pretty-print.c

index 9829a57cd6dbd8c63b972eb2ff55cd2b2b92dcbd..06b6647327f596a9a0f30a6c7f4cd29ffca53505 100644 (file)
@@ -324,7 +324,20 @@ static int cat_file_by_path(const char *p, bool *newline, CatFlags flags) {
 
         assert(p);
 
-        r = conf_file_new(p, /* root= */ NULL, CONF_FILES_REGULAR, &c);
+        r = conf_file_new(p, /* root= */ NULL, CONF_FILES_REGULAR | CONF_FILES_FILTER_MASKED, &c);
+        if (r == -ERFKILL) { /* masked */
+                if (newline) {
+                        if (*newline)
+                                putc('\n', stdout);
+                        *newline = true;
+                }
+
+                printf("%s# %s is a mask.%s\n",
+                       ansi_highlight_magenta(),
+                       p,
+                       ansi_normal());
+                return 0;
+        }
         if (r < 0)
                 return log_error_errno(r, "Failed to chase '%s': %m", p);
 
@@ -457,7 +470,8 @@ int conf_files_cat(const char *root, const char *name, CatFlags flags) {
                         if (!p)
                                 return log_oom();
 
-                        if (conf_file_new(p, root, CONF_FILES_REGULAR, &c) >= 0)
+                        r = conf_file_new(p, root, CONF_FILES_REGULAR | CONF_FILES_FILTER_MASKED, &c);
+                        if (r >= 0 || r == -ERFKILL) /* Found a regular file or masked file */
                                 break;
                 }