From: Prasanna Paithankar Date: Mon, 3 Feb 2025 13:07:01 +0000 (+0530) Subject: sys-utils: warns if mqueue fs is not mounted X-Git-Tag: v2.42-start~54^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=64ae7b75c040e8f7ff0ceab5a6a75df160d8c891;p=thirdparty%2Futil-linux.git sys-utils: warns if mqueue fs is not mounted - Add a check to see if mqueue fs is mounted before using it, and warn the user if it is not mounted. - bash completion for ipcrm is fixed to make it independent of awk. Signed-off-by: Prasanna Paithankar --- diff --git a/bash-completion/ipcrm b/bash-completion/ipcrm index 6f4870a60..b5cb95a06 100644 --- a/bash-completion/ipcrm +++ b/bash-completion/ipcrm @@ -6,47 +6,47 @@ _ipcrm_module() prev="${COMP_WORDS[COMP_CWORD-1]}" case $prev in '-m'|'--shmem-id') - KEYIDS="$(lsipc -m | awk 'NR>1 {print $2}')" + KEYIDS="$(lsipc -m --noheadings -o ID)" COMPREPLY=( $(compgen -W "$KEYIDS" -- $cur) ) return 0 ;; '-M'|'--shmem-key') - KEYIDS="$(lsipc -m | awk 'NR>1 {print $1}')" + KEYIDS="$(lsipc -m --noheadings -o KEY)" COMPREPLY=( $(compgen -W "$KEYIDS" -- $cur) ) return 0 ;; '--posix-shmem') - KEYIDS="$(lsipc -M | awk 'NR>1 {print $1}')" + KEYIDS="$(lsipc -M --noheadings -o NAME)" COMPREPLY=( $(compgen -W "$KEYIDS" -- $cur) ) return 0 ;; '-q'|'--queue-id') - KEYIDS="$(lsipc -q | awk 'NR>1 {print $2}')" + KEYIDS="$(lsipc -q --noheadings -o ID)" COMPREPLY=( $(compgen -W "$KEYIDS" -- $cur) ) return 0 ;; '-Q'|'--queue-key') - KEYIDS="$(lsipc -q | awk 'NR>1 {print $1}')" + KEYIDS="$(lsipc -q --noheadings -o KEY)" COMPREPLY=( $(compgen -W "$KEYIDS" -- $cur) ) return 0 ;; '--posix-mqueue') - KEYIDS="$(lsipc -Q | awk 'NR>1 {print $1}')" + KEYIDS="$(lsipc -Q --noheadings -o NAME)" COMPREPLY=( $(compgen -W "$KEYIDS" -- $cur) ) return 0 ;; '-s'|'--semaphore-id') - KEYIDS="$(lsipc -s | awk '{if (3 < NR) {print $2}}')" + KEYIDS="$(lsipc -s --noheadings -o ID)" COMPREPLY=( $(compgen -W "$KEYIDS" -- $cur) ) return 0 ;; '-S'|'--semaphore-key') - KEYIDS="$(lsipc -s | awk '{if (3 < NR) {print $1}}')" + KEYIDS="$(lsipc -s --noheadings -o KEY)" COMPREPLY=( $(compgen -W "$KEYIDS" -- $cur) ) return 0 ;; '--posix-semaphore') - KEYIDS="$(lsipc -S | awk 'NR>1 {print $1}')" + KEYIDS="$(lsipc -S --noheadings -o NAME)" COMPREPLY=( $(compgen -W "$KEYIDS" -- $cur) ) return 0 ;; diff --git a/meson.build b/meson.build index 58eec9e24..a54e1e94b 100644 --- a/meson.build +++ b/meson.build @@ -1494,7 +1494,7 @@ exe = executable( ipcrm_sources, include_directories : includes, link_with : [lib_common], - dependencies : [mount_dep] + posixipc_libs, + dependencies : posixipc_libs, install_dir : usrbin_exec_dir, install : opt, build_by_default : opt) @@ -1510,7 +1510,7 @@ exe = executable( ipcs_sources, include_directories : includes, link_with : [lib_common], - dependencies : [mount_dep] + posixipc_libs, + dependencies : posixipc_libs, install_dir : usrbin_exec_dir, install : opt, build_by_default : opt) @@ -2216,7 +2216,7 @@ exe = executable( include_directories : includes, link_with : [lib_common, lib_smartcols], - dependencies : [mount_dep] + posixipc_libs, + dependencies : 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 f1236b8a4..ec3f27f06 100644 --- a/sys-utils/Makemodule.am +++ b/sys-utils/Makemodule.am @@ -46,8 +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) $(POSIXIPC_LIBS) libcommon.la libmount.la -ipcrm_CFLAGS = $(AM_CFLAGS) -I$(ul_libmount_incdir) +ipcrm_LDADD = $(LDADD) $(POSIXIPC_LIBS) libcommon.la endif if BUILD_IPCS @@ -57,8 +56,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) $(POSIXIPC_LIBS) libcommon.la libmount.la -ipcs_CFLAGS = $(AM_CFLAGS) -I$(ul_libmount_incdir) +ipcs_LDADD = $(LDADD) $(POSIXIPC_LIBS) libcommon.la endif if BUILD_IRQTOP @@ -97,8 +95,8 @@ 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) $(POSIXIPC_LIBS) libcommon.la libsmartcols.la libmount.la -lsipc_CFLAGS = $(AM_CFLAGS) -I$(ul_libsmartcols_incdir) -I$(ul_libmount_incdir) +lsipc_LDADD = $(LDADD) $(POSIXIPC_LIBS) libcommon.la libsmartcols.la +lsipc_CFLAGS = $(AM_CFLAGS) -I$(ul_libsmartcols_incdir) endif if BUILD_RENICE diff --git a/sys-utils/ipcutils.c b/sys-utils/ipcutils.c index cdd42d89c..3ec2a0383 100644 --- a/sys-utils/ipcutils.c +++ b/sys-utils/ipcutils.c @@ -648,38 +648,22 @@ int posix_ipc_msg_get_info(const char *name, struct posix_msg_data **msgds) { FILE *f; DIR *d; - int i = 0, mounted = 0; + int i = 0; struct posix_msg_data *p; struct dirent *de; p = *msgds = xcalloc(1, sizeof(struct msg_data)); p->next = NULL; + if (access(_PATH_DEV_MQUEUE, F_OK) != 0) { + warnx(_("%s does not seem to be mounted. Use 'mount -t mqueue none %s' to mount it."), _PATH_DEV_MQUEUE, _PATH_DEV_MQUEUE); + return -1; + } + d = opendir(_PATH_DEV_MQUEUE); if (!d) { - /* Mount the mqueue filesystem if it is not mounted */ - if (errno == ENOENT) { - struct libmnt_context *ctx; - - ctx = mnt_new_context(); - if (!ctx) - err(EXIT_FAILURE, _("cannot create libmount context")); - - if (mnt_context_set_source(ctx, "none") < 0) - err(EXIT_FAILURE, _("cannot set source")); - - if (mnt_context_set_target(ctx, _PATH_DEV_MQUEUE) < 0) - err(EXIT_FAILURE, _("cannot set target")); - - if (mnt_context_set_fstype(ctx, "mqueue") < 0) - err(EXIT_FAILURE, _("cannot set filesystem type")); - - 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); + warnx(_("cannot open %s"), _PATH_DEV_MQUEUE); + return -1; } while ((de = readdir(d)) != NULL) { @@ -747,23 +731,6 @@ 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; - - ctx = mnt_new_context(); - if (!ctx) - err(EXIT_FAILURE, _("cannot create libmount context")); - - if (mnt_context_set_target(ctx, _PATH_DEV_MQUEUE) < 0) - err(EXIT_FAILURE, _("cannot set target")); - - 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/ipcutils.h b/sys-utils/ipcutils.h index 7c6963aa5..16284c103 100644 --- a/sys-utils/ipcutils.h +++ b/sys-utils/ipcutils.h @@ -26,7 +26,6 @@ #include #include #include -#include /* * SHM_DEST and SHM_LOCKED are defined in kernel headers, but inside diff --git a/sys-utils/lsipc.c b/sys-utils/lsipc.c index c91d03d64..2f771f268 100644 --- a/sys-utils/lsipc.c +++ b/sys-utils/lsipc.c @@ -992,7 +992,11 @@ static void do_posix_msg(const char *name, struct lsipc_control *ctl, struct lib struct posix_msg_data *msgds, *p; char *arg = NULL; - if (posix_ipc_msg_get_info(name, &msgds) < 1) { + int rc = posix_ipc_msg_get_info(name, &msgds); + if (rc == -1) + return; + + if (rc < 1) { if (name != NULL) warnx(_("mqueue %s not found"), name); return; @@ -1106,18 +1110,12 @@ static void do_posix_msg_global(struct lsipc_control *ctl, struct libscols_table { struct posix_msg_data *pmsgds; struct ipc_limits lim; - int pmsgqs = 0; + int pmsgqs = posix_ipc_msg_get_info(NULL, &pmsgds); ipc_msg_get_limits(&lim); - /* count number of used posix queues */ - if (posix_ipc_msg_get_info(NULL, &pmsgds) > 0) { - struct posix_msg_data *p; - - for (p = pmsgds; p->next != NULL; p = p->next) - ++pmsgqs; - posix_ipc_msg_free_info(pmsgds); - } + if (pmsgqs == -1) + pmsgqs = 0; global_set_data(ctl, tb, "MQUMNI", _("Number of POSIX message queues"), pmsgqs, lim.msgmni_posix, 1, 0); global_set_data(ctl, tb, "MQUMAX", _("Max size of POSIX message (bytes)"), 0, lim.msgmax_posix, 0, 1);