From: Yu Watanabe Date: Tue, 13 Jan 2026 06:39:39 +0000 (+0900) Subject: pretty-print: do not fail when cat_files() tries to show a masked file X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0d6e3b136d3805a5226e5022d5ba4b72e90fe221;p=thirdparty%2Fsystemd.git pretty-print: do not fail when cat_files() tries to show a masked file 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 (cherry picked from commit f2125229234e798272f0c05ec99ec15e48d10fc0) --- diff --git a/src/shared/pretty-print.c b/src/shared/pretty-print.c index 9829a57cd6d..06b6647327f 100644 --- a/src/shared/pretty-print.c +++ b/src/shared/pretty-print.c @@ -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; }