Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/landlock: Fix fs_test build with old libc

One issue comes up while building selftest/landlock/fs_test on my side
(gcc 7.3/glibc-2.28/kernel-4.19).

gcc -Wall -O2 -isystem fs_test.c -lcap -o selftests/landlock/fs_test
fs_test.c:4575:9: error: initializer element is not constant
.mnt = mnt_tmp,
^~~~~~~

Signed-off-by: Hu Yadi <hu.yadi@h3c.com>
Suggested-by: Jiao <jiaoxupo@h3c.com>
Reviewed-by: Berlin <berlin@h3c.com>
Link: https://lore.kernel.org/r/20240124022908.42100-1-hu.yadi@h3c.com
Fixes: 04f9070e99a4 ("selftests/landlock: Add tests for pseudo filesystems")
[mic: Factor out mount's data string and make mnt_tmp static]
Signed-off-by: Mickaël Salaün <mic@digikod.net>

authored by

Hu Yadi and committed by
Mickaël Salaün
40b7835e 116099ed

+8 -3
+8 -3
tools/testing/selftests/landlock/fs_test.c
··· 241 241 const char *const data; 242 242 }; 243 243 244 - const struct mnt_opt mnt_tmp = { 244 + #define MNT_TMP_DATA "size=4m,mode=700" 245 + 246 + static const struct mnt_opt mnt_tmp = { 245 247 .type = "tmpfs", 246 - .data = "size=4m,mode=700", 248 + .data = MNT_TMP_DATA, 247 249 }; 248 250 249 251 static int mount_opt(const struct mnt_opt *const mnt, const char *const target) ··· 4634 4632 /* clang-format off */ 4635 4633 FIXTURE_VARIANT_ADD(layout3_fs, tmpfs) { 4636 4634 /* clang-format on */ 4637 - .mnt = mnt_tmp, 4635 + .mnt = { 4636 + .type = "tmpfs", 4637 + .data = MNT_TMP_DATA, 4638 + }, 4638 4639 .file_path = file1_s1d1, 4639 4640 }; 4640 4641