From: Prasanna Paithankar Date: Mon, 27 Jan 2025 20:50:00 +0000 (+0530) Subject: sys-utils: fixed build system for POSIX IPC tools X-Git-Tag: v2.42-start~54^2~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=27704d22e5c235019e02233803c1cbda1e2467ac;p=thirdparty%2Futil-linux.git sys-utils: fixed build system for POSIX IPC tools --- diff --git a/configure.ac b/configure.ac index 07b508999..f834652a0 100644 --- a/configure.ac +++ b/configure.ac @@ -2102,6 +2102,13 @@ UL_BUILD_INIT([chmem]) UL_REQUIRES_LINUX([chmem]) AM_CONDITIONAL([BUILD_CHMEM], [test "x$build_chmem" = xyes]) +AC_CHECK_FUNCS([shm_open], [], [ + AC_CHECK_LIB([rt], [shm_open], [POSIXIPC_LIBS="-lrt"]) +]) +AC_CHECK_FUNCS([sem_close], [], [ + AC_CHECK_LIB([pthread], [sem_close], [POSIXIPC_LIBS="$POSIXIPC_LIBS -lpthread"]) +]) +AC_SUBST([POSIXIPC_LIBS]) AC_ARG_ENABLE([ipcmk], AS_HELP_STRING([--disable-ipcmk], [do not build ipcmk]), diff --git a/meson.build b/meson.build index bc505962d..58eec9e24 100644 --- a/meson.build +++ b/meson.build @@ -1463,12 +1463,22 @@ endif has_seminfo_type = cc.has_type('struct seminfo', args : '-D_GNU_SOURCE', prefix : '#include ') +posixipc_libs = [] +if not cc.has_function('shm_open') + posixipc_libs = cc.find_library('rt', required : true) +endif + +if not cc.has_function('sem_close') + posixipc_libs += cc.find_library('pthread', required : true) +endif + opt = get_option('build-ipcmk').require(has_seminfo_type).allowed() exe = executable( 'ipcmk', ipcmk_sources, include_directories : includes, link_with : [lib_common], + dependencies : posixipc_libs, install_dir : usrbin_exec_dir, install : opt, build_by_default : opt) @@ -1484,7 +1494,7 @@ exe = executable( ipcrm_sources, include_directories : includes, link_with : [lib_common], - dependencies : [mount_dep], + dependencies : [mount_dep] + posixipc_libs, install_dir : usrbin_exec_dir, install : opt, build_by_default : opt) @@ -1500,7 +1510,7 @@ exe = executable( ipcs_sources, include_directories : includes, link_with : [lib_common], - dependencies : [mount_dep], + dependencies : [mount_dep] + posixipc_libs, install_dir : usrbin_exec_dir, install : opt, build_by_default : opt) @@ -2206,7 +2216,7 @@ exe = executable( include_directories : includes, link_with : [lib_common, lib_smartcols], - dependencies : [mount_dep], + dependencies : [mount_dep] + posixipc_libs, install_dir : usrbin_exec_dir, install : opt, build_by_default : opt) diff --git a/sys-utils/Makemodule.am b/sys-utils/Makemodule.am index 03955c85c..f1236b8a4 100644 --- a/sys-utils/Makemodule.am +++ b/sys-utils/Makemodule.am @@ -36,7 +36,7 @@ usrbin_exec_PROGRAMS += ipcmk MANPAGES += sys-utils/ipcmk.1 dist_noinst_DATA += sys-utils/ipcmk.1.adoc ipcmk_SOURCES = sys-utils/ipcmk.c -ipcmk_LDADD = $(LDADD) libcommon.la +ipcmk_LDADD = $(LDADD) $(POSIXIPC_LIBS) libcommon.la endif if BUILD_IPCRM @@ -46,7 +46,7 @@ dist_noinst_DATA += sys-utils/ipcrm.1.adoc ipcrm_SOURCES = sys-utils/ipcrm.c \ sys-utils/ipcutils.c \ sys-utils/ipcutils.h -ipcrm_LDADD = $(LDADD) libcommon.la libmount.la +ipcrm_LDADD = $(LDADD) $(POSIXIPC_LIBS) libcommon.la libmount.la ipcrm_CFLAGS = $(AM_CFLAGS) -I$(ul_libmount_incdir) endif @@ -57,7 +57,7 @@ dist_noinst_DATA += sys-utils/ipcs.1.adoc ipcs_SOURCES = sys-utils/ipcs.c \ sys-utils/ipcutils.c \ sys-utils/ipcutils.h -ipcs_LDADD = $(LDADD) libcommon.la libmount.la +ipcs_LDADD = $(LDADD) $(POSIXIPC_LIBS) libcommon.la libmount.la ipcs_CFLAGS = $(AM_CFLAGS) -I$(ul_libmount_incdir) endif @@ -97,7 +97,7 @@ dist_noinst_DATA += sys-utils/lsipc.1.adoc lsipc_SOURCES = sys-utils/lsipc.c \ sys-utils/ipcutils.c \ sys-utils/ipcutils.h -lsipc_LDADD = $(LDADD) libcommon.la libsmartcols.la libmount.la +lsipc_LDADD = $(LDADD) $(POSIXIPC_LIBS) libcommon.la libsmartcols.la libmount.la lsipc_CFLAGS = $(AM_CFLAGS) -I$(ul_libsmartcols_incdir) -I$(ul_libmount_incdir) endif diff --git a/sys-utils/ipcutils.c b/sys-utils/ipcutils.c index 7aeccbeca..cdd42d89c 100644 --- a/sys-utils/ipcutils.c +++ b/sys-utils/ipcutils.c @@ -657,6 +657,7 @@ int posix_ipc_msg_get_info(const char *name, struct posix_msg_data **msgds) d = opendir(_PATH_DEV_MQUEUE); if (!d) { + /* Mount the mqueue filesystem if it is not mounted */ if (errno == ENOENT) { struct libmnt_context *ctx; @@ -676,6 +677,7 @@ int posix_ipc_msg_get_info(const char *name, struct posix_msg_data **msgds) if (mnt_context_mount(ctx) < 0) err(EXIT_FAILURE, _("cannot mount %s"), _PATH_DEV_MQUEUE); + mnt_free_context(ctx); mounted = 1; } else err(EXIT_FAILURE, _("cannot open %s"), _PATH_DEV_MQUEUE); } @@ -689,12 +691,21 @@ int posix_ipc_msg_get_info(const char *name, struct posix_msg_data **msgds) struct stat st; char path[PATH_MAX]; snprintf(path, sizeof(path), "%s/%s", _PATH_DEV_MQUEUE, de->d_name); - if (stat(path, &st) < 0) + + int fd = open(path, O_RDONLY); + if (fd < 0) continue; - f = fopen(path, "r"); - if (!f) + if (fstat(fd, &st) < 0) { + close(fd); continue; + } + + f = fdopen(fd, "r"); + if (!f) { + close(fd); + continue; + } if (fscanf(f, "QSIZE:%"SCNu64, &p->q_cbytes) != 1) { fclose(f); continue; @@ -736,6 +747,7 @@ int posix_ipc_msg_get_info(const char *name, struct posix_msg_data **msgds) free(*msgds); closedir(d); + /* Unmount the mqueue filesystem if it was not mounted by default */ if (mounted) { struct libmnt_context *ctx; @@ -748,6 +760,8 @@ int posix_ipc_msg_get_info(const char *name, struct posix_msg_data **msgds) if (mnt_context_umount(ctx) < 0) err(EXIT_FAILURE, _("cannot umount %s"), _PATH_DEV_MQUEUE); + + mnt_free_context(ctx); } return i; diff --git a/sys-utils/lsipc.c b/sys-utils/lsipc.c index 10bc43351..c91d03d64 100644 --- a/sys-utils/lsipc.c +++ b/sys-utils/lsipc.c @@ -178,7 +178,7 @@ static const struct lsipc_coldesc coldescs[] = [COL_CTIME] = { "CTIME", N_("Time of the last change"), N_("Last change"), 1, SCOLS_FL_RIGHT}, /* posix-common */ - [COL_NAME] = { "NAME", N_("Resource name"), N_("Name"), 1 }, + [COL_NAME] = { "NAME", N_("POSIX resource name"), N_("Name"), 1 }, [COL_MTIME] = { "MTIME", N_("Time of last action"), N_("Last action"), 1, SCOLS_FL_RIGHT}, /* msgq-specific */