]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
sys-utils: fixed build system for POSIX IPC tools
authorPrasanna Paithankar <paithankarprasanna@gmail.com>
Mon, 27 Jan 2025 20:50:00 +0000 (02:20 +0530)
committerPrasanna Paithankar <paithankarprasanna@gmail.com>
Mon, 27 Jan 2025 20:50:00 +0000 (02:20 +0530)
configure.ac
meson.build
sys-utils/Makemodule.am
sys-utils/ipcutils.c
sys-utils/lsipc.c

index 07b50899952281107e9f76a8ac1a743353e39a45..f834652a04b43bf187ce379df0a1f45e6356e537 100644 (file)
@@ -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]),
index bc505962d4f5ac9af4d000488b1dfbf6f93a5fd1..58eec9e2491dc9b6bebfb192a6a16e3606630225 100644 (file)
@@ -1463,12 +1463,22 @@ endif
 
 has_seminfo_type = cc.has_type('struct seminfo', args : '-D_GNU_SOURCE', prefix : '#include <sys/sem.h>')
 
+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)
index 03955c85c2b4d3b552c21afa83d339cacfa5fa07..f1236b8a4cc09f73904fd79dfbb3a70d8da937e5 100644 (file)
@@ -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
 
index 7aeccbeca07902e972de29b0554089664f36b7a9..cdd42d89cb62c9c66014b949586673eba4a4da3a 100644 (file)
@@ -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;
index 10bc43351e2d0b73bf165acde09301bd67ca0673..c91d03d641f495b3c74f168e2733b3b815086834 100644 (file)
@@ -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 */