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]),
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)
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)
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)
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)
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
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
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
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
d = opendir(_PATH_DEV_MQUEUE);
if (!d) {
+ /* Mount the mqueue filesystem if it is not mounted */
if (errno == ENOENT) {
struct libmnt_context *ctx;
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);
}
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;
free(*msgds);
closedir(d);
+ /* Unmount the mqueue filesystem if it was not mounted by default */
if (mounted) {
struct libmnt_context *ctx;
if (mnt_context_umount(ctx) < 0)
err(EXIT_FAILURE, _("cannot umount %s"), _PATH_DEV_MQUEUE);
+
+ mnt_free_context(ctx);
}
return i;
[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 */