]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: add test case for masked files in cat_files() v259-stable
authorgvenugo3 <gvenugo3@asu.edu>
Sat, 10 Jan 2026 19:46:18 +0000 (19:46 +0000)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 20 Jan 2026 02:05:54 +0000 (11:05 +0900)
Add a test case to verify that cat_files() correctly handles symlinks
to /dev/null (masked configuration files) and returns success (0)
instead of failing.

This test complements the fix for issue #40313.

Co-authored-by: Yu Watanabe <watanabe.yu+github@gmail.com>
(cherry picked from commit 01efa01dd28b9c47c1f5fe84c684d9d13192ec96)

src/test/test-pretty-print.c

index 71d8799cbfdb098051456d741887dcfebeedd0bf..073930df09d3710ffae6a7529c05aa64d90c0c65 100644 (file)
@@ -4,8 +4,11 @@
 #include <unistd.h>
 
 #include "alloc-util.h"
+#include "path-util.h"
 #include "pretty-print.h"
+#include "rm-rf.h"
 #include "tests.h"
+#include "tmpfile-util.h"
 
 #define CYLON_WIDTH 6
 
@@ -53,6 +56,13 @@ TEST(cat_files) {
 
         if (access("/etc/fstab", R_OK) >= 0)
                 assert_se(cat_files("/etc/fstab", STRV_MAKE("/etc/fstab", "/etc/fstab"), 0) == 0);
+
+        /* Test masked file (symlink to /dev/null) - should succeed with exit code 0 */
+        _cleanup_(rm_rf_physical_and_freep) char *tmp = NULL;
+        ASSERT_OK(mkdtemp_malloc("/tmp/test-cat-files-XXXXXX", &tmp));
+        _cleanup_free_ char *masked_file = ASSERT_NOT_NULL(path_join(tmp, "masked.conf"));
+        ASSERT_OK_ERRNO(symlink("/dev/null", masked_file));
+        ASSERT_OK(cat_files(masked_file, /* dropins= */ NULL, /* flags= */ 0));
 }
 
 TEST(red_green_cross_check_mark) {