]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
sys-utils: warns if mqueue fs is not mounted
authorPrasanna Paithankar <paithankarprasanna@gmail.com>
Mon, 3 Feb 2025 13:07:01 +0000 (18:37 +0530)
committerPrasanna Paithankar <paithankarprasanna@gmail.com>
Mon, 3 Feb 2025 13:07:01 +0000 (18:37 +0530)
- 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 <paithankarprasanna@gmail.com>
bash-completion/ipcrm
meson.build
sys-utils/Makemodule.am
sys-utils/ipcutils.c
sys-utils/ipcutils.h
sys-utils/lsipc.c

index 6f4870a607191533c225ad9af4fb22fa97fbccb2..b5cb95a0654d40ccc4f9fb278657b495ac5fe602 100644 (file)
@@ -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
                        ;;
index 58eec9e2491dc9b6bebfb192a6a16e3606630225..a54e1e94ba4a838d0348eda18f59214f3588e5d0 100644 (file)
@@ -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)
index f1236b8a4cc09f73904fd79dfbb3a70d8da937e5..ec3f27f06dbfac6f74aad4c875ec3bb14c0c1dd7 100644 (file)
@@ -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
index cdd42d89cb62c9c66014b949586673eba4a4da3a..3ec2a0383c81ac0a4c22790322b301c0bfcd0c67 100644 (file)
@@ -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;
 }
 
index 7c6963aa57d1afadd273f47cbe2434a5d7383607..16284c1038c0e00c58d66f23fd547fcc890c7233 100644 (file)
@@ -26,7 +26,6 @@
 #include <grp.h>
 #include <pwd.h>
 #include <stdint.h>
-#include <libmount.h>
 
 /*
  * SHM_DEST and SHM_LOCKED are defined in kernel headers, but inside
index c91d03d641f495b3c74f168e2733b3b815086834..2f771f2688807ca160d50417e057af09a5c14759 100644 (file)
@@ -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);