From: Masatake YAMATO Date: Mon, 18 Sep 2023 06:39:39 +0000 (+0900) Subject: lsfd: collect the device number for mqueue fs in the initialization stage X-Git-Tag: v2.40-rc1~237^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e3dedb011e1fe578e921c0c6858e9b3d9b79ec84;p=thirdparty%2Futil-linux.git lsfd: collect the device number for mqueue fs in the initialization stage Though lsfd reads device minor numbers for file-systems having "nodev" from /proc/$pid/mountinfo, we observed lsfd failed to resolve the values of SOURCE column for mqueue files on s390 CI/CD env. It seems that /proc/$pid/mountinfo doesn't provide enough information. This change makes lsfd open a mqueue file in lsfd's initialization stage as a new data source for resolving; lsfd can collect an actually-used minor number from the file descriptor with fstat(2). Signed-off-by: Masatake YAMATO --- diff --git a/meson.build b/meson.build index 8e3d6bb1d9..6c23797beb 100644 --- a/meson.build +++ b/meson.build @@ -2615,12 +2615,16 @@ if not is_disabler(exe) bashcompletions += ['lsblk'] endif +mq_libs = [] +mq_libs += cc.find_library('rt', required : true) + exe = executable( 'lsfd', lsfd_sources, include_directories : includes, link_with : [lib_common, lib_smartcols], + dependencies : mq_libs, install_dir : usrbin_exec_dir, install : true) if not is_disabler(exe) @@ -3377,9 +3381,6 @@ exe = executable( build_by_default: program_tests) exes += exe -mq_libs = [] -mq_libs += cc.find_library('rt', required : true) - if LINUX exe = executable( 'test_mkfds', diff --git a/misc-utils/Makemodule.am b/misc-utils/Makemodule.am index dd6204afdd..e794d8cb12 100644 --- a/misc-utils/Makemodule.am +++ b/misc-utils/Makemodule.am @@ -267,7 +267,7 @@ lsfd_SOURCES = \ misc-utils/lsfd-sock-xinfo.c \ misc-utils/lsfd-unkn.c \ misc-utils/lsfd-fifo.c -lsfd_LDADD = $(LDADD) libsmartcols.la libcommon.la +lsfd_LDADD = $(LDADD) $(MQ_LIBS) libsmartcols.la libcommon.la lsfd_CFLAGS = $(AM_CFLAGS) -I$(ul_libsmartcols_incdir) endif diff --git a/misc-utils/lsfd-file.c b/misc-utils/lsfd-file.c index 186ce62e5e..f65910d31c 100644 --- a/misc-utils/lsfd-file.c +++ b/misc-utils/lsfd-file.c @@ -34,6 +34,10 @@ #include #include +#include +#include +#include /* mq_open */ + #include "buffer.h" #include "idcache.h" #include "strutils.h" @@ -460,6 +464,34 @@ static unsigned long get_minor_for_sysvipc(void) return m; } +static unsigned long get_minor_for_mqueue(void) +{ + mqd_t mq; + char mq_name[BUFSIZ]; + struct mq_attr attr = { + .mq_maxmsg = 1, + .mq_msgsize = 1, + }; + + pid_t self = getpid(); + struct stat sb; + + snprintf(mq_name, sizeof(mq_name), "/.lsfd-mqueue-nodev-test:%d", self); + mq = mq_open(mq_name, O_CREAT|O_EXCL | O_RDONLY, S_IRUSR | S_IWUSR, &attr); + if (mq < 0) + return 0; + + if (fstat((int)mq, &sb) < 0) { + mq_close(mq); + mq_unlink(mq_name); + return 0; + } + + mq_close(mq); + mq_unlink(mq_name); + return minor(sb.st_dev); +} + static void file_class_initialize(void) { unsigned long m; @@ -474,6 +506,10 @@ static void file_class_initialize(void) m = get_minor_for_sysvipc(); if (m) add_nodev(m, "tmpfs"); + + m = get_minor_for_mqueue(); + if (m) + add_nodev(m, "mqueue"); } static void file_class_finalize(void)