cdown / rpms / util-linux

Forked from rpms/util-linux 2 years ago
Clone
05ad79
From 9f643efe377d2a39929f19cc09e8890afc74d9a4 Mon Sep 17 00:00:00 2001
05ad79
From: Karel Zak <kzak@redhat.com>
05ad79
Date: Fri, 24 Jun 2016 12:57:13 +0200
05ad79
Subject: [PATCH 78/84] lsipc: backport new command
05ad79
05ad79
Addresses: http://bugzilla.redhat.com/show_bug.cgi?id=1153770
05ad79
Signed-off-by: Karel Zak <kzak@redhat.com>
05ad79
---
05ad79
 bash-completion/lsipc   |   64 +++
05ad79
 configure.ac            |    6 +
05ad79
 include/xalloc.h        |    7 +
05ad79
 sys-utils/Makemodule.am |   10 +
05ad79
 sys-utils/ipcs.c        |    2 +-
05ad79
 sys-utils/ipcutils.c    |  116 ++---
05ad79
 sys-utils/ipcutils.h    |   13 +-
05ad79
 sys-utils/lsipc.1       |  133 +++++
05ad79
 sys-utils/lsipc.c       | 1316 +++++++++++++++++++++++++++++++++++++++++++++++
05ad79
 tests/functions.sh      |   16 +-
05ad79
 tests/ts/ipcs/limits2   |    9 +-
05ad79
 11 files changed, 1613 insertions(+), 79 deletions(-)
05ad79
 create mode 100644 bash-completion/lsipc
05ad79
 create mode 100644 sys-utils/lsipc.1
05ad79
 create mode 100644 sys-utils/lsipc.c
05ad79
05ad79
diff --git a/bash-completion/lsipc b/bash-completion/lsipc
05ad79
new file mode 100644
05ad79
index 0000000..6a87393
05ad79
--- /dev/null
05ad79
+++ b/bash-completion/lsipc
05ad79
@@ -0,0 +1,64 @@
05ad79
+_lsipc_module()
05ad79
+{
05ad79
+	local cur prev OPTS ARG
05ad79
+	COMPREPLY=()
05ad79
+	cur="${COMP_WORDS[COMP_CWORD]}"
05ad79
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
05ad79
+	case $prev in
05ad79
+		'-i'|'--id')
05ad79
+			COMPREPLY=( $(compgen -W "id" -- $cur) )
05ad79
+			return 0
05ad79
+			;;
05ad79
+		'-h'|'--help'|'-V'|'--version')
05ad79
+			return 0
05ad79
+			;;
05ad79
+		'-o'|'--output')
05ad79
+			local prefix realcur OUTPUT_ALL OUTPUT
05ad79
+			realcur="${cur##*,}"
05ad79
+			prefix="${cur%$realcur}"
05ad79
+			OUTPUT_ALL="GENERAL KEY ID OWNER PERMS CUID
05ad79
+			CGID UID GID CHANGE MESSAGE USEDBYTES
05ad79
+			MSGS SEND RECV LSPID LRPID SHARED BYTES
05ad79
+			NATTCH STATUS ATTACH DETACH CPID LPID NSEMS
05ad79
+			LASTOP"
05ad79
+			for WORD in $OUTPUT_ALL; do
05ad79
+				if ! [[ $prefix == *"$WORD"* ]]; then
05ad79
+					OUTPUT="$WORD $OUTPUT"
05ad79
+				fi
05ad79
+			done
05ad79
+			compopt -o nospace
05ad79
+			COMPREPLY=( $(compgen -P "$prefix" -W "$OUTPUT" -S ',' -- $realcur) )
05ad79
+			return 0
05ad79
+			;;
05ad79
+	esac
05ad79
+	case $cur in
05ad79
+		-*)
05ad79
+			OPTS="--id
05ad79
+				--help
05ad79
+				--version
05ad79
+				--shmems
05ad79
+				--queues
05ad79
+				--semaphores
05ad79
+				--colon-separate
05ad79
+				--creator
05ad79
+				--export
05ad79
+				--global
05ad79
+				--newline
05ad79
+				--noheadings
05ad79
+				--notruncate
05ad79
+				--output
05ad79
+				--pid
05ad79
+				--print0
05ad79
+				--raw
05ad79
+				--time
05ad79
+				--time-format"
05ad79
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
05ad79
+			return 0
05ad79
+			;;
05ad79
+	esac
05ad79
+	local IFS=$'\n'
05ad79
+	compopt -o filenames
05ad79
+	COMPREPLY=( $(compgen -f -- $cur) )
05ad79
+	return 0
05ad79
+}
05ad79
+complete -F _lsipc_module lsipc
05ad79
diff --git a/configure.ac b/configure.ac
05ad79
index 5d9ea39..fe0a011 100644
05ad79
--- a/configure.ac
05ad79
+++ b/configure.ac
05ad79
@@ -1038,6 +1038,12 @@ UL_REQUIRES_BUILD([lsns], [libsmartcols])
05ad79
 AM_CONDITIONAL([BUILD_LSNS], [test "x$build_lsns" = xyes])
05ad79
 
05ad79
 
05ad79
+UL_BUILD_INIT([lsipc], [check])
05ad79
+UL_REQUIRES_LINUX([lsipc])
05ad79
+UL_REQUIRES_BUILD([lsipc], [libsmartcols])
05ad79
+AM_CONDITIONAL([BUILD_LSIPC], [test "x$build_lsipc" = xyes])
05ad79
+
05ad79
+
05ad79
 UL_BUILD_INIT([chcpu], [check])
05ad79
 UL_REQUIRES_LINUX([chcpu])
05ad79
 UL_REQUIRES_HAVE([chcpu], [cpu_set_t], [cpu_set_t type])
05ad79
diff --git a/include/xalloc.h b/include/xalloc.h
05ad79
index 6342793..1a1799a 100644
05ad79
--- a/include/xalloc.h
05ad79
+++ b/include/xalloc.h
05ad79
@@ -19,6 +19,13 @@
05ad79
 # define XALLOC_EXIT_CODE EXIT_FAILURE
05ad79
 #endif
05ad79
 
05ad79
+static inline void __err_oom(const char *file, unsigned int line)
05ad79
+{
05ad79
+	err(XALLOC_EXIT_CODE, "%s: %u: cannot allocate memory", file, line);
05ad79
+}
05ad79
+
05ad79
+#define err_oom()	__err_oom(__FILE__, __LINE__)
05ad79
+
05ad79
 static inline __ul_alloc_size(1)
05ad79
 void *xmalloc(const size_t size)
05ad79
 {
05ad79
diff --git a/sys-utils/Makemodule.am b/sys-utils/Makemodule.am
05ad79
index 9baf5a3..6badd17 100644
05ad79
--- a/sys-utils/Makemodule.am
05ad79
+++ b/sys-utils/Makemodule.am
05ad79
@@ -22,6 +22,16 @@ ipcs_SOURCES =	sys-utils/ipcs.c \
05ad79
 ipcs_LDADD = $(LDADD) libcommon.la
05ad79
 
05ad79
 
05ad79
+if BUILD_LSIPC
05ad79
+usrbin_exec_PROGRAMS += lsipc
05ad79
+dist_man_MANS += sys-utils/lsipc.1
05ad79
+lsipc_SOURCES =	sys-utils/lsipc.c \
05ad79
+		sys-utils/ipcutils.c \
05ad79
+		sys-utils/ipcutils.h
05ad79
+lsipc_LDADD = $(LDADD) libcommon.la libsmartcols.la
05ad79
+lsipc_CFLAGS = $(AM_CFLAGS) -I$(ul_libsmartcols_incdir)
05ad79
+endif
05ad79
+
05ad79
 usrbin_exec_PROGRAMS += renice
05ad79
 dist_man_MANS += sys-utils/renice.1
05ad79
 renice_SOURCES = sys-utils/renice.c
05ad79
diff --git a/sys-utils/ipcs.c b/sys-utils/ipcs.c
05ad79
index 14f5f0b..1843cd5 100644
05ad79
--- a/sys-utils/ipcs.c
05ad79
+++ b/sys-utils/ipcs.c
05ad79
@@ -201,7 +201,7 @@ static void do_shm (char format, int unit)
05ad79
 			       _("max seg size"), lim.shmmax, "\n", 0);
05ad79
 		ipc_print_size(unit == IPC_UNIT_DEFAULT ? IPC_UNIT_KB : unit,
05ad79
 			       _("max total shared memory"),
05ad79
-			       lim.shmall * getpagesize(), "\n", 0);
05ad79
+			       (uint64_t) lim.shmall * getpagesize(), "\n", 0);
05ad79
 		ipc_print_size(unit == IPC_UNIT_DEFAULT ? IPC_UNIT_BYTES : unit,
05ad79
 			       _("min seg size"), lim.shmmin, "\n", 0);
05ad79
 		return;
05ad79
diff --git a/sys-utils/ipcutils.c b/sys-utils/ipcutils.c
05ad79
index 62d7428..51fce7b 100644
05ad79
--- a/sys-utils/ipcutils.c
05ad79
+++ b/sys-utils/ipcutils.c
05ad79
@@ -1,4 +1,3 @@
05ad79
-
05ad79
 #include <inttypes.h>
05ad79
 
05ad79
 #include "c.h"
05ad79
@@ -54,8 +53,8 @@ int ipc_sem_get_limits(struct ipc_limits *lim)
05ad79
 
05ad79
 	}
05ad79
 
05ad79
-	if (rc == 4) {
05ad79
-		struct seminfo seminfo;
05ad79
+	if (rc != 4) {
05ad79
+		struct seminfo seminfo = { .semmni = 0 };
05ad79
 		union semun arg = { .array = (ushort *) &seminfo };
05ad79
 
05ad79
 		if (semctl(0, 0, IPC_INFO, arg) < 0)
05ad79
@@ -82,12 +81,15 @@ int ipc_shm_get_limits(struct ipc_limits *lim)
05ad79
 		lim->shmmni = path_read_u64(_PATH_PROC_IPC_SHMMNI);
05ad79
 
05ad79
 	} else {
05ad79
-		struct shminfo shminfo;
05ad79
+		struct shminfo *shminfo;
05ad79
+		struct shmid_ds shmbuf;
05ad79
 
05ad79
-		if (shmctl(0, IPC_INFO, (struct shmid_ds *) &shminfo) < 0)
05ad79
+		if (shmctl(0, IPC_INFO, &shmbuf) < 0)
05ad79
 			return 1;
05ad79
-		lim->shmmni = shminfo.shmmni;
05ad79
-		lim->shmall = shminfo.shmall;
05ad79
+		shminfo = (struct shminfo *) &shmbuf;
05ad79
+		lim->shmmni = shminfo->shmmni;
05ad79
+		lim->shmall = shminfo->shmall;
05ad79
+		lim->shmmax = shminfo->shmmax;
05ad79
 	}
05ad79
 
05ad79
 	return 0;
05ad79
@@ -97,20 +99,24 @@ int ipc_shm_get_info(int id, struct shm_data **shmds)
05ad79
 {
05ad79
 	FILE *f;
05ad79
 	int i = 0, maxid;
05ad79
+	char buf[BUFSIZ];
05ad79
 	struct shm_data *p;
05ad79
-	struct shm_info dummy;
05ad79
+	struct shmid_ds dummy;
05ad79
 
05ad79
 	p = *shmds = xcalloc(1, sizeof(struct shm_data));
05ad79
 	p->next = NULL;
05ad79
 
05ad79
 	f = path_fopen("r", 0, _PATH_PROC_SYSV_SHM);
05ad79
 	if (!f)
05ad79
-		goto fallback;
05ad79
+		goto shm_fallback;
05ad79
 
05ad79
 	while (fgetc(f) != '\n');		/* skip header */
05ad79
 
05ad79
-	while (feof(f) == 0) {
05ad79
-		if (fscanf(f,
05ad79
+	while (fgets(buf, sizeof(buf), f) != NULL) {
05ad79
+		/* scan for the first 14-16 columns (e.g. Linux 2.6.32 has 14) */
05ad79
+		p->shm_rss = 0xdead;
05ad79
+		p->shm_swp = 0xdead;
05ad79
+		if (sscanf(buf,
05ad79
 			  "%d %d  %o %"SCNu64 " %u %u  "
05ad79
 			  "%"SCNu64 " %u %u %u %u %"SCNi64 " %"SCNi64 " %"SCNi64
05ad79
 			  " %"SCNu64 " %"SCNu64 "\n",
05ad79
@@ -129,8 +135,8 @@ int ipc_shm_get_info(int id, struct shm_data **shmds)
05ad79
 			   &p->shm_dtim,
05ad79
 			   &p->shm_ctim,
05ad79
 			   &p->shm_rss,
05ad79
-			   &p->shm_swp) != 16)
05ad79
-			continue;
05ad79
+			   &p->shm_swp) < 14)
05ad79
+			continue; /* invalid line, skipped */
05ad79
 
05ad79
 		if (id > -1) {
05ad79
 			/* ID specified */
05ad79
@@ -153,28 +159,20 @@ int ipc_shm_get_info(int id, struct shm_data **shmds)
05ad79
 	return i;
05ad79
 
05ad79
 	/* Fallback; /proc or /sys file(s) missing. */
05ad79
-fallback:
05ad79
-	i = id < 0 ? 0 : id;
05ad79
-
05ad79
-	maxid = shmctl(0, SHM_INFO, (struct shmid_ds *) &dummy);
05ad79
-	if (maxid < 0)
05ad79
-		return 0;
05ad79
+shm_fallback:
05ad79
+	maxid = shmctl(0, SHM_INFO, &dummy);
05ad79
 
05ad79
-	while (i <= maxid) {
05ad79
+	for (int j = 0; j <= maxid; j++) {
05ad79
 		int shmid;
05ad79
 		struct shmid_ds shmseg;
05ad79
 		struct ipc_perm *ipcp = &shmseg.shm_perm;
05ad79
 
05ad79
-		shmid = shmctl(i, SHM_STAT, &shmseg);
05ad79
-		if (shmid < 0) {
05ad79
-			if (-1 < id) {
05ad79
-				free(*shmds);
05ad79
-				return 0;
05ad79
-			}
05ad79
-			i++;
05ad79
+		shmid = shmctl(j, SHM_STAT, &shmseg);
05ad79
+		if (shmid < 0 || (id > -1 && shmid != id)) {
05ad79
 			continue;
05ad79
 		}
05ad79
 
05ad79
+		i++;
05ad79
 		p->shm_perm.key = ipcp->KEY;
05ad79
 		p->shm_perm.id = shmid;
05ad79
 		p->shm_perm.mode = ipcp->mode;
05ad79
@@ -196,11 +194,12 @@ fallback:
05ad79
 			p->next = xcalloc(1, sizeof(struct shm_data));
05ad79
 			p = p->next;
05ad79
 			p->next = NULL;
05ad79
-			i++;
05ad79
 		} else
05ad79
-			return 1;
05ad79
+			break;
05ad79
 	}
05ad79
 
05ad79
+	if (i == 0)
05ad79
+		free(*shmds);
05ad79
 	return i;
05ad79
 }
05ad79
 
05ad79
@@ -299,30 +298,22 @@ int ipc_sem_get_info(int id, struct sem_data **semds)
05ad79
 	return i;
05ad79
 
05ad79
 	/* Fallback; /proc or /sys file(s) missing. */
05ad79
- sem_fallback:
05ad79
-	i = id < 0 ? 0 : id;
05ad79
-
05ad79
+sem_fallback:
05ad79
 	arg.array = (ushort *) (void *)&dummy;
05ad79
 	maxid = semctl(0, 0, SEM_INFO, arg);
05ad79
-	if (maxid < 0)
05ad79
-		return 0;
05ad79
 
05ad79
-	while (i <= maxid) {
05ad79
+	for (int j = 0; j <= maxid; j++) {
05ad79
 		int semid;
05ad79
 		struct semid_ds semseg;
05ad79
 		struct ipc_perm *ipcp = &semseg.sem_perm;
05ad79
 		arg.buf = (struct semid_ds *)&semseg;
05ad79
 
05ad79
-		semid = semctl(i, 0, SEM_STAT, arg);
05ad79
-		if (semid < 0) {
05ad79
-			if (-1 < id) {
05ad79
-				free(*semds);
05ad79
-				return 0;
05ad79
-			}
05ad79
-			i++;
05ad79
+		semid = semctl(j, 0, SEM_STAT, arg);
05ad79
+		if (semid < 0 || (id > -1 && semid != id)) {
05ad79
 			continue;
05ad79
 		}
05ad79
 
05ad79
+		i++;
05ad79
 		p->sem_perm.key = ipcp->KEY;
05ad79
 		p->sem_perm.id = semid;
05ad79
 		p->sem_perm.mode = ipcp->mode;
05ad79
@@ -341,10 +332,12 @@ int ipc_sem_get_info(int id, struct sem_data **semds)
05ad79
 			i++;
05ad79
 		} else {
05ad79
 			get_sem_elements(p);
05ad79
-			return 1;
05ad79
+			break;
05ad79
 		}
05ad79
 	}
05ad79
 
05ad79
+	if (i == 0)
05ad79
+		free(*semds);
05ad79
 	return i;
05ad79
 }
05ad79
 
05ad79
@@ -398,10 +391,6 @@ int ipc_msg_get_info(int id, struct msg_data **msgds)
05ad79
 		if (id > -1) {
05ad79
 			/* ID specified */
05ad79
 			if (id == p->msg_perm.id) {
05ad79
-				/*
05ad79
-				 * FIXME: q_qbytes are not in /proc
05ad79
-				 *
05ad79
-				 */
05ad79
 				if (msgctl(id, IPC_STAT, &msgseg) != -1)
05ad79
 					p->q_qbytes = msgseg.msg_qbytes;
05ad79
 				i = 1;
05ad79
@@ -422,27 +411,19 @@ int ipc_msg_get_info(int id, struct msg_data **msgds)
05ad79
 	return i;
05ad79
 
05ad79
 	/* Fallback; /proc or /sys file(s) missing. */
05ad79
- msg_fallback:
05ad79
-	i = id < 0 ? 0 : id;
05ad79
-
05ad79
-	maxid = msgctl(id, MSG_STAT, &dummy);
05ad79
-	if (maxid < 0)
05ad79
-		return 0;
05ad79
+msg_fallback:
05ad79
+	maxid = msgctl(0, MSG_INFO, &dummy);
05ad79
 
05ad79
-	while (i <= maxid) {
05ad79
+	for (int j = 0; j <= maxid; j++) {
05ad79
 		int msgid;
05ad79
 		struct ipc_perm *ipcp = &msgseg.msg_perm;
05ad79
 
05ad79
-		msgid = msgctl(i, MSG_STAT, &msgseg);
05ad79
-		if (msgid < 0) {
05ad79
-			if (-1 < id) {
05ad79
-				free(*msgds);
05ad79
-				return 0;
05ad79
-			}
05ad79
-			i++;
05ad79
+		msgid = msgctl(j, MSG_STAT, &msgseg);
05ad79
+		if (msgid < 0 || (id > -1 && msgid != id)) {
05ad79
 			continue;
05ad79
 		}
05ad79
 
05ad79
+		i++;
05ad79
 		p->msg_perm.key = ipcp->KEY;
05ad79
 		p->msg_perm.id = msgid;
05ad79
 		p->msg_perm.mode = ipcp->mode;
05ad79
@@ -463,11 +444,12 @@ int ipc_msg_get_info(int id, struct msg_data **msgds)
05ad79
 			p->next = xcalloc(1, sizeof(struct msg_data));
05ad79
 			p = p->next;
05ad79
 			p->next = NULL;
05ad79
-			i++;
05ad79
 		} else
05ad79
-			return 1;
05ad79
+			break;
05ad79
 	}
05ad79
 
05ad79
+	if (i == 0)
05ad79
+		free(*msgds);
05ad79
 	return i;
05ad79
 }
05ad79
 
05ad79
@@ -508,10 +490,10 @@ void ipc_print_perms(FILE *f, struct ipc_stat *is)
05ad79
 		fprintf(f, " %-10u\n", is->gid);
05ad79
 }
05ad79
 
05ad79
-void ipc_print_size(int unit, char *msg, size_t size, const char *end,
05ad79
+void ipc_print_size(int unit, char *msg, uint64_t size, const char *end,
05ad79
 		    int width)
05ad79
 {
05ad79
-	char format[16];
05ad79
+	char format[32];
05ad79
 
05ad79
 	if (!msg)
05ad79
 		/* NULL */ ;
05ad79
@@ -527,11 +509,11 @@ void ipc_print_size(int unit, char *msg, size_t size, const char *end,
05ad79
 	switch (unit) {
05ad79
 	case IPC_UNIT_DEFAULT:
05ad79
 	case IPC_UNIT_BYTES:
05ad79
-		sprintf(format, "%%%dzu", width);
05ad79
+		sprintf(format, "%%%dju", width);
05ad79
 		printf(format, size);
05ad79
 		break;
05ad79
 	case IPC_UNIT_KB:
05ad79
-		sprintf(format, "%%%dzu", width);
05ad79
+		sprintf(format, "%%%dju", width);
05ad79
 		printf(format, size / 1024);
05ad79
 		break;
05ad79
 	case IPC_UNIT_HUMAN:
05ad79
diff --git a/sys-utils/ipcutils.h b/sys-utils/ipcutils.h
05ad79
index d2e5972..444065a 100644
05ad79
--- a/sys-utils/ipcutils.h
05ad79
+++ b/sys-utils/ipcutils.h
05ad79
@@ -12,6 +12,7 @@
05ad79
 #include <unistd.h>
05ad79
 #include <grp.h>
05ad79
 #include <pwd.h>
05ad79
+#include <stdint.h>
05ad79
 
05ad79
 /*
05ad79
  * SHM_DEST and SHM_LOCKED are defined in kernel headers, but inside
05ad79
@@ -34,11 +35,11 @@
05ad79
 # define SHM_INFO	14
05ad79
 struct shm_info {
05ad79
 	int used_ids;
05ad79
-	ulong shm_tot;		/* total allocated shm */
05ad79
-	ulong shm_rss;		/* total resident shm */
05ad79
-	ulong shm_swp;		/* total swapped shm */
05ad79
-	ulong swap_attempts;
05ad79
-	ulong swap_successes;
05ad79
+	unsigned long shm_tot;		/* total allocated shm */
05ad79
+	unsigned long shm_rss;		/* total resident shm */
05ad79
+	unsigned long shm_swp;		/* total swapped shm */
05ad79
+	unsigned long swap_attempts;
05ad79
+	unsigned long swap_successes;
05ad79
 };
05ad79
 #endif
05ad79
 
05ad79
@@ -118,7 +119,7 @@ struct ipc_stat {
05ad79
 };
05ad79
 
05ad79
 extern void ipc_print_perms(FILE *f, struct ipc_stat *is);
05ad79
-extern void ipc_print_size(int unit, char *msg, size_t size, const char *end, int width);
05ad79
+extern void ipc_print_size(int unit, char *msg, uint64_t size, const char *end, int width);
05ad79
 
05ad79
 /* See 'struct shmid_kernel' in kernel sources
05ad79
  */
05ad79
diff --git a/sys-utils/lsipc.1 b/sys-utils/lsipc.1
05ad79
new file mode 100644
05ad79
index 0000000..98449cb
05ad79
--- /dev/null
05ad79
+++ b/sys-utils/lsipc.1
05ad79
@@ -0,0 +1,133 @@
05ad79
+.\" Copyright 2015 Ondrej Oprala(ooprala@redhat.com)
05ad79
+.\" May be distributed under the GNU General Public License
05ad79
+.TH LSIPC "1" "November 2015" "util-linux" "User Commands"
05ad79
+.SH NAME
05ad79
+lsipc \- show information on IPC facilities currently employed in the system
05ad79
+.SH SYNOPSIS
05ad79
+.B lsipc
05ad79
+[options]
05ad79
+.SH DESCRIPTION
05ad79
+.B lsipc
05ad79
+shows information on the inter-process communication facilities
05ad79
+for which the calling process has read access.
05ad79
+.SH OPTIONS
05ad79
+.TP
05ad79
+\fB\-i\fR, \fB\-\-id\fR \fIid\fR
05ad79
+Show full details on just the one resource element identified by
05ad79
+.IR id .
05ad79
+This option needs to be combined with one of the three resource options:
05ad79
+.BR \-m ,
05ad79
+.BR \-q " or"
05ad79
+.BR \-s .
05ad79
+It is possible to override the default output format for this option with the
05ad79
+\fB\-\-list\fR, \fB\-\-raw\fR, \fB\-\-json\fR or \fB\-\-export\fR option.
05ad79
+.TP
05ad79
+\fB\-g\fR, \fB\-\-global\fR
05ad79
+Show system-wide usage and limits of IPC resources.
05ad79
+This option may be combined with one of the three resource options:
05ad79
+.BR \-m ,
05ad79
+.BR \-q " or"
05ad79
+.BR \-s .
05ad79
+The default is to show information about all resources.
05ad79
+.TP
05ad79
+\fB\-h\fR, \fB\-\-help\fR
05ad79
+Display help text and exit.
05ad79
+.TP
05ad79
+\fB\-V\fR, \fB\-\-version\fR
05ad79
+Display version information and exit.
05ad79
+.SS "Resource options"
05ad79
+.TP
05ad79
+\fB\-m\fR, \fB\-\-shmems\fR
05ad79
+Write information about active shared memory segments.
05ad79
+.TP
05ad79
+\fB\-q\fR, \fB\-\-queues\fR
05ad79
+Write information about active message queues.
05ad79
+.TP
05ad79
+\fB\-s\fR, \fB\-\-semaphores\fR
05ad79
+Write information about active semaphore sets.
05ad79
+.SS "Output formatting"
05ad79
+.TP
05ad79
+\fB\-c\fR, \fB\-\-creator\fR
05ad79
+Show creator and owner.
05ad79
+.TP
05ad79
+\fB\-e\fR, \fB\-\-export\fR
05ad79
+Output data in the format of NAME=VALUE.
05ad79
+.TP
05ad79
+\fB\-l\fR, \fB\-\-list\fR
05ad79
+Use the list output format.  This is the default, except when \fB\-\-id\fR
05ad79
+is used.
05ad79
+.TP
05ad79
+\fB\-n\fR, \fB\-\-newline\fR
05ad79
+Display each piece of information on a separate line.
05ad79
+.TP
05ad79
+\fB\-\-noheadings\fR
05ad79
+Do not print a header line.
05ad79
+.TP
05ad79
+\fB\-\-notruncate\fR
05ad79
+Don't truncate output.
05ad79
+.TP
05ad79
+\fB\-o\fR, \fB\-\-output \fIlist\fP
05ad79
+Specify which output columns to print.  Use
05ad79
+.B \-\-help
05ad79
+to get a list of all supported columns.
05ad79
+.TP
05ad79
+\fB\-p\fR, \fB\-\-pid\fR
05ad79
+Show PIDs of creator and last operator.
05ad79
+.TP
05ad79
+\fB\-r\fR, \fB\-\-raw\fR
05ad79
+Raw output (no columnation).
05ad79
+.TP
05ad79
+\fB\-t\fR, \fB\-\-time\fR
05ad79
+Write time information.  The time of the last control operation that changed
05ad79
+the access permissions for all facilities, the time of the last
05ad79
+.I msgsnd()
05ad79
+and
05ad79
+.I msgrcv()
05ad79
+operations on message queues, the time of the last
05ad79
+.I shmat()
05ad79
+and
05ad79
+.I shmdt()
05ad79
+operations on shared memory, and the time of the last
05ad79
+.I semop()
05ad79
+operation on semaphores.
05ad79
+.TP
05ad79
+\fB\-\-time\-format\fR \fItype\fP
05ad79
+Display dates in short, full or iso format.  The default is short, this time
05ad79
+format is designed to be space efficient and human readable.
05ad79
+
05ad79
+.SH EXIT STATUS
05ad79
+.TP
05ad79
+0
05ad79
+if OK,
05ad79
+.TP
05ad79
+1
05ad79
+if incorrect arguments specified,
05ad79
+.TP
05ad79
+2
05ad79
+if a serious error occurs.
05ad79
+.SH SEE ALSO
05ad79
+.BR ipcrm (1),
05ad79
+.BR ipcmk (1),
05ad79
+.BR msgrcv (2),
05ad79
+.BR msgsnd (2),
05ad79
+.BR semget (2),
05ad79
+.BR semop (2),
05ad79
+.BR shmat (2),
05ad79
+.BR shmdt (2),
05ad79
+.BR shmget (2)
05ad79
+.SH HISTORY
05ad79
+The \fBlsipc\fP utility is inspired by the \fBipcs\fP utility.
05ad79
+.SH AUTHORS
05ad79
+.MT ooprala@redhat.com
05ad79
+Ondrej Oprala
05ad79
+.ME
05ad79
+.br
05ad79
+.MT kzak@redhat.com
05ad79
+Karel Zak
05ad79
+.ME
05ad79
+
05ad79
+.SH AVAILABILITY
05ad79
+The lsipc command is part of the util-linux package and is available from
05ad79
+.UR ftp://\:ftp.kernel.org\:/pub\:/linux\:/utils\:/util-linux/
05ad79
+Linux Kernel Archive
05ad79
+.UE .
05ad79
diff --git a/sys-utils/lsipc.c b/sys-utils/lsipc.c
05ad79
new file mode 100644
05ad79
index 0000000..0be9d91
05ad79
--- /dev/null
05ad79
+++ b/sys-utils/lsipc.c
05ad79
@@ -0,0 +1,1316 @@
05ad79
+/*
05ad79
+ * lsipc - List information about IPC instances employed in the system
05ad79
+ *
05ad79
+ * Copyright (C) 2015 Ondrej Oprala <ooprala@redhat.com>
05ad79
+ * Copyright (C) 2015 Karel Zak <ooprala@redhat.com>
05ad79
+ *
05ad79
+ * This program is free software; you can redistribute it and/or modify
05ad79
+ * it under the terms of the GNU General Public License as published by
05ad79
+ * the Free Software Foundation; either version 2 of the License, or
05ad79
+ * (at your option) any later version.
05ad79
+ *
05ad79
+ * This program is distributed in the hope that it would be useful,
05ad79
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
05ad79
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
05ad79
+ * GNU General Public License for more details.
05ad79
+ *
05ad79
+ * You should have received a copy of the GNU General Public License along
05ad79
+ * with this program; if not, write to the Free Software Foundation, Inc.,
05ad79
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
05ad79
+ *
05ad79
+ *
05ad79
+ * lsipc is inspired by the ipcs utility. The aim is to create
05ad79
+ * a utility unencumbered by a standard to provide more flexible
05ad79
+ * means of controlling the output.
05ad79
+ */
05ad79
+
05ad79
+#include <errno.h>
05ad79
+#include <getopt.h>
05ad79
+#include <sys/time.h>
05ad79
+#include <unistd.h>
05ad79
+
05ad79
+#include <libsmartcols.h>
05ad79
+
05ad79
+#include "c.h"
05ad79
+#include "nls.h"
05ad79
+#include "closestream.h"
05ad79
+#include "strutils.h"
05ad79
+#include "optutils.h"
05ad79
+#include "xalloc.h"
05ad79
+#include "procutils.h"
05ad79
+#include "ipcutils.h"
05ad79
+
05ad79
+/*
05ad79
+ * time modes
05ad79
+ * */
05ad79
+enum {
05ad79
+	TIME_INVALID = 0,
05ad79
+	TIME_SHORT,
05ad79
+	TIME_FULL,
05ad79
+	TIME_ISO
05ad79
+};
05ad79
+
05ad79
+/*
05ad79
+ * IDs
05ad79
+ */
05ad79
+enum {
05ad79
+	/* generic */
05ad79
+	COLDESC_IDX_GEN_FIRST = 0,
05ad79
+		COL_KEY = COLDESC_IDX_GEN_FIRST,
05ad79
+		COL_ID,
05ad79
+		COL_OWNER,
05ad79
+		COL_PERMS,
05ad79
+		COL_CUID,
05ad79
+		COL_CUSER,
05ad79
+		COL_CGID,
05ad79
+		COL_CGROUP,
05ad79
+		COL_UID,
05ad79
+		COL_USER,
05ad79
+		COL_GID,
05ad79
+		COL_GROUP,
05ad79
+		COL_CTIME,
05ad79
+	COLDESC_IDX_GEN_LAST = COL_CTIME,
05ad79
+
05ad79
+	/* msgq-specific */
05ad79
+	COLDESC_IDX_MSG_FIRST,
05ad79
+		COL_USEDBYTES = COLDESC_IDX_MSG_FIRST,
05ad79
+		COL_MSGS,
05ad79
+		COL_SEND,
05ad79
+		COL_RECV,
05ad79
+		COL_LSPID,
05ad79
+		COL_LRPID,
05ad79
+	COLDESC_IDX_MSG_LAST = COL_LRPID,
05ad79
+
05ad79
+	/* shm-specific */
05ad79
+	COLDESC_IDX_SHM_FIRST,
05ad79
+		COL_SIZE = COLDESC_IDX_SHM_FIRST,
05ad79
+		COL_NATTCH,
05ad79
+		COL_STATUS,
05ad79
+		COL_ATTACH,
05ad79
+		COL_DETACH,
05ad79
+		COL_COMMAND,
05ad79
+		COL_CPID,
05ad79
+		COL_LPID,
05ad79
+	COLDESC_IDX_SHM_LAST = COL_LPID,
05ad79
+
05ad79
+	/* sem-specific */
05ad79
+	COLDESC_IDX_SEM_FIRST,
05ad79
+		COL_NSEMS = COLDESC_IDX_SEM_FIRST,
05ad79
+		COL_OTIME,
05ad79
+	COLDESC_IDX_SEM_LAST = COL_OTIME,
05ad79
+
05ad79
+	/* summary (--global) */
05ad79
+	COLDESC_IDX_SUM_FIRST,
05ad79
+		COL_RESOURCE = COLDESC_IDX_SUM_FIRST,
05ad79
+		COL_DESC,
05ad79
+		COL_LIMIT,
05ad79
+		COL_USED,
05ad79
+		COL_USEPERC,
05ad79
+	COLDESC_IDX_SUM_LAST = COL_USEPERC
05ad79
+};
05ad79
+
05ad79
+/* not all columns apply to all options, so we specify a legal range for each */
05ad79
+static size_t LOWER, UPPER;
05ad79
+
05ad79
+/*
05ad79
+ * output modes
05ad79
+ */
05ad79
+enum {
05ad79
+	OUT_EXPORT = 1,
05ad79
+	OUT_NEWLINE,
05ad79
+	OUT_RAW,
05ad79
+	OUT_PRETTY,
05ad79
+	OUT_LIST
05ad79
+};
05ad79
+
05ad79
+struct lsipc_control {
05ad79
+	int outmode;
05ad79
+	unsigned int noheadings : 1,		/* don't print header line */
05ad79
+		     notrunc : 1,		/* don't truncate columns */
05ad79
+		     bytes : 1,			/* SIZE in bytes */
05ad79
+		     numperms : 1,		/* numeric permissions */
05ad79
+		     time_mode : 2;
05ad79
+};
05ad79
+
05ad79
+struct lsipc_coldesc {
05ad79
+	const char *name;
05ad79
+	const char *help;
05ad79
+	const char *pretty_name;
05ad79
+
05ad79
+	double whint;	/* width hint */
05ad79
+	long flag;
05ad79
+};
05ad79
+
05ad79
+static const struct lsipc_coldesc coldescs[] =
05ad79
+{
05ad79
+	/* common */
05ad79
+	[COL_KEY]	= { "KEY",	N_("Resource key"), N_("Key"), 1},
05ad79
+	[COL_ID]	= { "ID",	N_("Resource ID"), N_("ID"), 1},
05ad79
+	[COL_OWNER]	= { "OWNER",	N_("Owner's username or UID"), N_("Owner"), 1, SCOLS_FL_RIGHT},
05ad79
+	[COL_PERMS]	= { "PERMS",	N_("Permissions"), N_("Permissions"), 1, SCOLS_FL_RIGHT},
05ad79
+	[COL_CUID]	= { "CUID",	N_("Creator UID"), N_("Creator UID"), 1, SCOLS_FL_RIGHT},
05ad79
+	[COL_CUSER]     = { "CUSER",    N_("Creator user"), N_("Creator user"), 1 },
05ad79
+	[COL_CGID]	= { "CGID",	N_("Creator GID"), N_("Creator GID"), 1, SCOLS_FL_RIGHT},
05ad79
+	[COL_CGROUP]    = { "CGROUP",   N_("Creator group"), N_("Creator group"), 1 },
05ad79
+	[COL_UID]	= { "UID",	N_("User ID"), N_("UID"), 1, SCOLS_FL_RIGHT},
05ad79
+	[COL_USER]	= { "USER",	N_("User name"), N_("User name"), 1},
05ad79
+	[COL_GID]	= { "GID",	N_("Group ID"), N_("GID"), 1, SCOLS_FL_RIGHT},
05ad79
+	[COL_GROUP]	= { "GROUP",	N_("Group name"), N_("Group name"), 1},
05ad79
+	[COL_CTIME]	= { "CTIME",	N_("Time of the last change"), N_("Last change"), 1, SCOLS_FL_RIGHT},
05ad79
+
05ad79
+	/* msgq-specific */
05ad79
+	[COL_USEDBYTES]	= { "USEDBYTES",N_("Bytes used"), N_("Bytes used"), 1, SCOLS_FL_RIGHT},
05ad79
+	[COL_MSGS]	= { "MSGS",	N_("Number of messages"), N_("Messages"), 1},
05ad79
+	[COL_SEND]	= { "SEND",	N_("Time of last msg sent"), N_("Msg sent"), 1, SCOLS_FL_RIGHT},
05ad79
+	[COL_RECV]	= { "RECV",	N_("Time of last msg received"), N_("Msg received"), 1, SCOLS_FL_RIGHT},
05ad79
+	[COL_LSPID]	= { "LSPID",	N_("PID of the last msg sender"), N_("Msg sender"), 1, SCOLS_FL_RIGHT},
05ad79
+	[COL_LRPID]	= { "LRPID",	N_("PID of the last msg receiver"), N_("Msg receiver"), 1, SCOLS_FL_RIGHT},
05ad79
+
05ad79
+	/* shm-specific */
05ad79
+	[COL_SIZE]	= { "SIZE",	N_("Segment size"), N_("Segment size"), 1, SCOLS_FL_RIGHT},
05ad79
+	[COL_NATTCH]	= { "NATTCH",	N_("Number of attached processes"), N_("Attached processes"), 1, SCOLS_FL_RIGHT},
05ad79
+	[COL_STATUS]	= { "STATUS",	N_("Status"), N_("Status"), 1, SCOLS_FL_NOEXTREMES},
05ad79
+	[COL_ATTACH]	= { "ATTACH",	N_("Attach time"), N_("Attach time"), 1, SCOLS_FL_RIGHT},
05ad79
+	[COL_DETACH]	= { "DETACH",	N_("Detach time"), N_("Detach time"), 1, SCOLS_FL_RIGHT},
05ad79
+	[COL_COMMAND]	= { "COMMAND",  N_("Creator command line"), N_("Creator command"), 0, SCOLS_FL_TRUNC},
05ad79
+	[COL_CPID]	= { "CPID",	N_("PID of the creator"), N_("Creator PID"), 1, SCOLS_FL_RIGHT},
05ad79
+	[COL_LPID]	= { "LPID",	N_("PID of last user"), N_("Last user PID"), 1, SCOLS_FL_RIGHT},
05ad79
+
05ad79
+	/* sem-specific */
05ad79
+	[COL_NSEMS]	= { "NSEMS",	N_("Number of semaphores"), N_("Semaphores"), 1, SCOLS_FL_RIGHT},
05ad79
+	[COL_OTIME]	= { "OTIME",	N_("Time of the last operation"), N_("Last operation"), 1, SCOLS_FL_RIGHT},
05ad79
+
05ad79
+	/* cols for summarized information */
05ad79
+	[COL_RESOURCE]  = { "RESOURCE", N_("Resource name"), N_("Resource"), 1 },
05ad79
+	[COL_DESC]      = { "DESCRIPTION",N_("Resource description"), N_("Description"), 1 },
05ad79
+	[COL_USED]      = { "USED",     N_("Currently used"), N_("Used"), 1, SCOLS_FL_RIGHT },
05ad79
+	[COL_USEPERC]	= { "USE%",     N_("Currently use percentage"), N_("Use"), 1, SCOLS_FL_RIGHT },
05ad79
+	[COL_LIMIT]     = { "LIMIT",    N_("System-wide limit"), N_("Limit"), 1, SCOLS_FL_RIGHT },
05ad79
+};
05ad79
+
05ad79
+
05ad79
+/* columns[] array specifies all currently wanted output column. The columns
05ad79
+ * are defined by coldescs[] array and you can specify (on command line) each
05ad79
+ * column twice. That's enough, dynamically allocated array of the columns is
05ad79
+ * unnecessary overkill and over-engineering in this case */
05ad79
+static int columns[ARRAY_SIZE(coldescs) * 2];
05ad79
+static size_t ncolumns;
05ad79
+
05ad79
+static inline size_t err_columns_index(size_t arysz, size_t idx)
05ad79
+{
05ad79
+	if (idx >= arysz)
05ad79
+		errx(EXIT_FAILURE, _("too many columns specified, "
05ad79
+				     "the limit is %zu columns"),
05ad79
+				arysz - 1);
05ad79
+	return idx;
05ad79
+}
05ad79
+
05ad79
+#define add_column(ary, n, id)	\
05ad79
+		((ary)[ err_columns_index(ARRAY_SIZE(ary), (n)) ] = (id))
05ad79
+
05ad79
+static int column_name_to_id(const char *name, size_t namesz)
05ad79
+{
05ad79
+	size_t i;
05ad79
+
05ad79
+	for (i = 0; i < ARRAY_SIZE(coldescs); i++) {
05ad79
+		const char *cn = coldescs[i].name;
05ad79
+
05ad79
+		if (!strncasecmp(name, cn, namesz) && !*(cn + namesz)) {
05ad79
+			if (i > COL_CTIME) {
05ad79
+				if (i >= LOWER && i <= UPPER)
05ad79
+					return i;
05ad79
+				else {
05ad79
+					warnx(_("column %s does not apply to the specified IPC"), name);
05ad79
+					return -1;
05ad79
+				}
05ad79
+			} else
05ad79
+				return i;
05ad79
+		}
05ad79
+	}
05ad79
+	warnx(_("unknown column: %s"), name);
05ad79
+	return -1;
05ad79
+}
05ad79
+
05ad79
+static char *get_username(struct passwd **pw, uid_t id)
05ad79
+{
05ad79
+	if (!*pw || (*pw)->pw_uid != id)
05ad79
+		*pw = getpwuid(id);
05ad79
+
05ad79
+	return *pw ? xstrdup((*pw)->pw_name) : NULL;
05ad79
+}
05ad79
+
05ad79
+static char *get_groupname(struct group **gr, gid_t id)
05ad79
+{
05ad79
+	if (!*gr || (*gr)->gr_gid != id)
05ad79
+		*gr = getgrgid(id);
05ad79
+
05ad79
+	return *gr ? xstrdup((*gr)->gr_name) : NULL;
05ad79
+}
05ad79
+
05ad79
+static int parse_time_mode(const char *optarg)
05ad79
+{
05ad79
+	struct lsipc_timefmt {
05ad79
+		const char *name;
05ad79
+		const int val;
05ad79
+	};
05ad79
+	static const struct lsipc_timefmt timefmts[] = {
05ad79
+		{"iso", TIME_ISO},
05ad79
+		{"full", TIME_FULL},
05ad79
+		{"short", TIME_SHORT},
05ad79
+	};
05ad79
+	size_t i;
05ad79
+
05ad79
+	for (i = 0; i < ARRAY_SIZE(timefmts); i++) {
05ad79
+		if (strcmp(timefmts[i].name, optarg) == 0)
05ad79
+			return timefmts[i].val;
05ad79
+	}
05ad79
+	errx(EXIT_FAILURE, _("unknown time format: %s"), optarg);
05ad79
+}
05ad79
+
05ad79
+static void __attribute__ ((__noreturn__)) usage(FILE * out)
05ad79
+{
05ad79
+	size_t i;
05ad79
+
05ad79
+	fputs(USAGE_HEADER, out);
05ad79
+	fprintf(out, _(" %s [options]\n"), program_invocation_short_name);
05ad79
+
05ad79
+	fputs(USAGE_SEPARATOR, out);
05ad79
+	fputs(_("Show information on IPC facilities.\n"), out);
05ad79
+
05ad79
+	fputs(USAGE_SEPARATOR, out);
05ad79
+	fputs(_("Resource options:\n"), out);
05ad79
+	fputs(_(" -m, --shmems      shared memory segments\n"), out);
05ad79
+	fputs(_(" -q, --queues      message queues\n"), out);
05ad79
+	fputs(_(" -s, --semaphores  semaphores\n"), out);
05ad79
+	fputs(_(" -g, --global      info about system-wide usage (may be used with -m, -q and -s)\n"), out);
05ad79
+	fputs(_(" -i, --id <id>     print details on resource identified by <id>\n"), out);
05ad79
+
05ad79
+	fputs(USAGE_OPTIONS, out);
05ad79
+	fputs(_("     --noheadings         don't print headings\n"), out);
05ad79
+	fputs(_("     --notruncate         don't truncate output\n"), out);
05ad79
+	fputs(_("     --time-format=<type> display dates in short, full or iso format\n"), out);
05ad79
+	fputs(_(" -b, --bytes              print SIZE in bytes rather than in human readable format\n"), out);
05ad79
+	fputs(_(" -c, --creator            show creator and owner\n"), out);
05ad79
+	fputs(_(" -e, --export             display in an export-able output format\n"), out);
05ad79
+	fputs(_(" -n, --newline            display each piece of information on a new line\n"), out);
05ad79
+	fputs(_(" -l, --list               force list output format (for example with --id)\n"), out);
05ad79
+	fputs(_(" -o, --output[=<list>]    define the columns to output\n"), out);
05ad79
+	fputs(_(" -P, --numeric-perms      print numeric permissions (PERMS column)\n"), out);
05ad79
+	fputs(_(" -r, --raw                display in raw mode\n"), out);
05ad79
+	fputs(_(" -t, --time               show attach, detach and change times\n"), out);
05ad79
+
05ad79
+	fputs(USAGE_SEPARATOR, out);
05ad79
+	fputs(USAGE_HELP, out);
05ad79
+	fputs(USAGE_VERSION, out);
05ad79
+
05ad79
+	fprintf(out, _("\nGeneric columns:\n"));
05ad79
+	for (i = COLDESC_IDX_GEN_FIRST; i <= COLDESC_IDX_GEN_LAST; i++)
05ad79
+		fprintf(out, " %14s  %s\n", coldescs[i].name, _(coldescs[i].help));
05ad79
+
05ad79
+	fprintf(out, _("\nShared-memory columns (--shmems):\n"));
05ad79
+	for (i = COLDESC_IDX_SHM_FIRST; i <= COLDESC_IDX_SHM_LAST; i++)
05ad79
+		fprintf(out, " %14s  %s\n", coldescs[i].name, _(coldescs[i].help));
05ad79
+
05ad79
+	fprintf(out, _("\nMessage-queue columns (--queues):\n"));
05ad79
+	for (i = COLDESC_IDX_MSG_FIRST; i <= COLDESC_IDX_MSG_LAST; i++)
05ad79
+		fprintf(out, " %14s  %s\n", coldescs[i].name, _(coldescs[i].help));
05ad79
+
05ad79
+	fprintf(out, _("\nSemaphore columns (--semaphores):\n"));
05ad79
+	for (i = COLDESC_IDX_SEM_FIRST; i <= COLDESC_IDX_SEM_LAST; i++)
05ad79
+		fprintf(out, " %14s  %s\n", coldescs[i].name, _(coldescs[i].help));
05ad79
+
05ad79
+	fprintf(out, _("\nSummary columns (--global):\n"));
05ad79
+	for (i = COLDESC_IDX_SUM_FIRST; i <= COLDESC_IDX_SUM_LAST; i++)
05ad79
+		fprintf(out, " %14s  %s\n", coldescs[i].name, _(coldescs[i].help));
05ad79
+
05ad79
+	fprintf(out, USAGE_MAN_TAIL("lsipc(1)"));
05ad79
+	exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
05ad79
+}
05ad79
+
05ad79
+static struct libscols_table *new_table(struct lsipc_control *ctl)
05ad79
+{
05ad79
+	struct libscols_table *table = scols_new_table();
05ad79
+
05ad79
+	if (!table)
05ad79
+		errx(EXIT_FAILURE, _("failed to initialize output table"));
05ad79
+	if (ctl->noheadings)
05ad79
+		scols_table_enable_noheadings(table, 1);
05ad79
+
05ad79
+	switch(ctl->outmode) {
05ad79
+	case OUT_NEWLINE:
05ad79
+		scols_table_set_column_separator(table, "\n");
05ad79
+		/* fallthrough */
05ad79
+	case OUT_EXPORT:
05ad79
+		scols_table_enable_export(table, 1);
05ad79
+		break;
05ad79
+	case OUT_RAW:
05ad79
+		scols_table_enable_raw(table, 1);
05ad79
+		break;
05ad79
+	case OUT_PRETTY:
05ad79
+		scols_table_enable_noheadings(table, 1);
05ad79
+		break;
05ad79
+	default:
05ad79
+		break;
05ad79
+	}
05ad79
+	return table;
05ad79
+}
05ad79
+
05ad79
+static struct libscols_table *setup_table(struct lsipc_control *ctl)
05ad79
+{
05ad79
+	struct libscols_table *table = new_table(ctl);
05ad79
+	size_t n;
05ad79
+
05ad79
+	for (n = 0; n < ncolumns; n++) {
05ad79
+		int flags = coldescs[columns[n]].flag;
05ad79
+
05ad79
+		if (ctl->notrunc)
05ad79
+			flags &= ~SCOLS_FL_TRUNC;
05ad79
+
05ad79
+		if (!scols_table_new_column(table,
05ad79
+				coldescs[columns[n]].name,
05ad79
+				coldescs[columns[n]].whint,
05ad79
+				flags))
05ad79
+			goto fail;
05ad79
+	}
05ad79
+	return table;
05ad79
+fail:
05ad79
+	scols_unref_table(table);
05ad79
+	return NULL;
05ad79
+}
05ad79
+
05ad79
+static int print_pretty(struct libscols_table *table)
05ad79
+{
05ad79
+	struct libscols_iter *itr = scols_new_iter(SCOLS_ITER_FORWARD);
05ad79
+	struct libscols_column *col;
05ad79
+	struct libscols_cell *data;
05ad79
+	struct libscols_line *ln;
05ad79
+	const char *hstr, *dstr;
05ad79
+	int n = 0;
05ad79
+
05ad79
+	ln = scols_table_get_line(table, 0);
05ad79
+	while (!scols_table_next_column(table, itr, &col)) {
05ad79
+
05ad79
+		data = scols_line_get_cell(ln, n);
05ad79
+
05ad79
+		hstr = N_(coldescs[columns[n]].pretty_name);
05ad79
+		dstr = scols_cell_get_data(data);
05ad79
+
05ad79
+		if (dstr)
05ad79
+			printf("%s:%*c%-36s\n", hstr, 35 - (int)strlen(hstr), ' ', dstr);
05ad79
+		++n;
05ad79
+	}
05ad79
+
05ad79
+	/* this is used to pretty-print detailed info about a semaphore array */
05ad79
+	if (ln) {
05ad79
+		struct libscols_table *subtab = scols_line_get_userdata(ln);
05ad79
+		if (subtab) {
05ad79
+			printf(_("Elements:\n\n"));
05ad79
+			scols_print_table(subtab);
05ad79
+		}
05ad79
+	}
05ad79
+
05ad79
+	scols_free_iter(itr);
05ad79
+	return 0;
05ad79
+
05ad79
+}
05ad79
+
05ad79
+static int print_table(struct lsipc_control *ctl, struct libscols_table *tb)
05ad79
+{
05ad79
+	if (ctl->outmode == OUT_PRETTY)
05ad79
+		print_pretty(tb);
05ad79
+	else
05ad79
+		scols_print_table(tb);
05ad79
+	return 0;
05ad79
+}
05ad79
+static struct timeval now;
05ad79
+
05ad79
+static int date_is_today(time_t t)
05ad79
+{
05ad79
+	if (now.tv_sec == 0)
05ad79
+		gettimeofday(&now, NULL);
05ad79
+	return t / (3600 * 24) == now.tv_sec / (3600 * 24);
05ad79
+}
05ad79
+
05ad79
+static int date_is_thisyear(time_t t)
05ad79
+{
05ad79
+	if (now.tv_sec == 0)
05ad79
+		gettimeofday(&now, NULL);
05ad79
+	return t / (3600 * 24 * 365) == now.tv_sec / (3600 * 24 * 365);
05ad79
+}
05ad79
+
05ad79
+static char *make_time(int mode, time_t time)
05ad79
+{
05ad79
+	char *s;
05ad79
+	struct tm tm;
05ad79
+	char buf[64] = {0};
05ad79
+
05ad79
+	localtime_r(&time, &tm;;
05ad79
+
05ad79
+	switch(mode) {
05ad79
+	case TIME_FULL:
05ad79
+		asctime_r(&tm, buf);
05ad79
+		if (*(s = buf + strlen(buf) - 1) == '\n')
05ad79
+			*s = '\0';
05ad79
+		break;
05ad79
+	case TIME_SHORT:
05ad79
+		if (date_is_today(time))
05ad79
+			strftime(buf, sizeof(buf), "%H:%M", &tm;;
05ad79
+		else if (date_is_thisyear(time))
05ad79
+			strftime(buf, sizeof(buf), "%b%d", &tm;;
05ad79
+		else
05ad79
+			strftime(buf, sizeof(buf), "%Y-%b%d", &tm;;
05ad79
+		break;
05ad79
+	case TIME_ISO:
05ad79
+		strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%S%z", &tm;;
05ad79
+		break;
05ad79
+	default:
05ad79
+		errx(EXIT_FAILURE, _("unsupported time type"));
05ad79
+	}
05ad79
+	return xstrdup(buf);
05ad79
+}
05ad79
+
05ad79
+static void global_set_data(struct libscols_table *tb, const char *resource,
05ad79
+			    const char *desc, uintmax_t used, uintmax_t limit, int usage)
05ad79
+{
05ad79
+	struct libscols_line *ln;
05ad79
+	size_t n;
05ad79
+
05ad79
+	ln = scols_table_new_line(tb, NULL);
05ad79
+	if (!ln)
05ad79
+		err_oom();
05ad79
+
05ad79
+	for (n = 0; n < ncolumns; n++) {
05ad79
+		int rc = 0;
05ad79
+		char *arg = NULL;
05ad79
+
05ad79
+		switch (columns[n]) {
05ad79
+		case COL_RESOURCE:
05ad79
+			rc = scols_line_set_data(ln, n, resource);
05ad79
+			break;
05ad79
+		case COL_DESC:
05ad79
+			rc = scols_line_set_data(ln, n, desc);
05ad79
+			break;
05ad79
+		case COL_USED:
05ad79
+			if (usage) {
05ad79
+				xasprintf(&arg, "%ju", used);
05ad79
+				rc = scols_line_refer_data(ln, n, arg);
05ad79
+			} else
05ad79
+				rc = scols_line_set_data(ln, n, "-");
05ad79
+			break;
05ad79
+		case COL_USEPERC:
05ad79
+			if (usage) {
05ad79
+				xasprintf(&arg, "%2.2f%%", (double) used / limit * 100);
05ad79
+				rc = scols_line_refer_data(ln, n, arg);
05ad79
+			} else
05ad79
+				rc = scols_line_set_data(ln, n, "-");
05ad79
+			break;
05ad79
+		case COL_LIMIT:
05ad79
+			xasprintf(&arg, "%ju", limit);
05ad79
+			rc = scols_line_refer_data(ln, n, arg);
05ad79
+			break;
05ad79
+		}
05ad79
+
05ad79
+		if (rc != 0)
05ad79
+			err(EXIT_FAILURE, _("failed to set data"));
05ad79
+	}
05ad79
+}
05ad79
+
05ad79
+static void setup_sem_elements_columns(struct libscols_table *tb)
05ad79
+{
05ad79
+	if (!scols_table_new_column(tb, "SEMNUM", 0, SCOLS_FL_RIGHT))
05ad79
+		err_oom();
05ad79
+	if (!scols_table_new_column(tb, "VALUE", 0, SCOLS_FL_RIGHT))
05ad79
+		err_oom();
05ad79
+	if (!scols_table_new_column(tb, "NCOUNT", 0, SCOLS_FL_RIGHT))
05ad79
+		err_oom();
05ad79
+	if (!scols_table_new_column(tb, "ZCOUNT", 0, SCOLS_FL_RIGHT))
05ad79
+		err_oom();
05ad79
+	if (!scols_table_new_column(tb, "PID", 0, SCOLS_FL_RIGHT))
05ad79
+		err_oom();
05ad79
+	if (!scols_table_new_column(tb, "COMMAND", 0, SCOLS_FL_RIGHT))
05ad79
+		err_oom();
05ad79
+}
05ad79
+
05ad79
+static void do_sem(int id, struct lsipc_control *ctl, struct libscols_table *tb)
05ad79
+{
05ad79
+	struct libscols_line *ln;
05ad79
+	struct passwd *pw = NULL, *cpw = NULL;
05ad79
+	struct group *gr = NULL, *cgr = NULL;
05ad79
+	struct sem_data *semds, *semdsp;
05ad79
+	char *arg = NULL;
05ad79
+
05ad79
+	if (ipc_sem_get_info(id, &semds) < 1) {
05ad79
+		if (id > -1)
05ad79
+			warnx(_("id %d not found"), id);
05ad79
+		return;
05ad79
+	}
05ad79
+	for (semdsp = semds;  semdsp->next != NULL || id > -1; semdsp = semdsp->next) {
05ad79
+		size_t n;
05ad79
+		ln = scols_table_new_line(tb, NULL);
05ad79
+
05ad79
+		for (n = 0; n < ncolumns; n++) {
05ad79
+			int rc = 0;
05ad79
+			switch (columns[n]) {
05ad79
+			case COL_KEY:
05ad79
+				xasprintf(&arg, "0x%08x",semdsp->sem_perm.key);
05ad79
+				rc = scols_line_refer_data(ln, n, arg);
05ad79
+				break;
05ad79
+			case COL_ID:
05ad79
+				xasprintf(&arg, "%d",semdsp->sem_perm.id);
05ad79
+				rc = scols_line_refer_data(ln, n, arg);
05ad79
+				break;
05ad79
+			case COL_OWNER:
05ad79
+				arg = get_username(&pw, semdsp->sem_perm.uid);
05ad79
+				if (!arg)
05ad79
+					xasprintf(&arg, "%u", semdsp->sem_perm.uid);
05ad79
+				rc = scols_line_refer_data(ln, n, arg);
05ad79
+				break;
05ad79
+			case COL_PERMS:
05ad79
+				if (ctl->numperms)
05ad79
+					xasprintf(&arg, "%#o", semdsp->sem_perm.mode & 0777);
05ad79
+				else {
05ad79
+					arg = xmalloc(11);
05ad79
+					strmode(semdsp->sem_perm.mode & 0777, arg);
05ad79
+				}
05ad79
+				rc = scols_line_refer_data(ln, n, arg);
05ad79
+				break;
05ad79
+			case COL_CUID:
05ad79
+				xasprintf(&arg, "%u", semdsp->sem_perm.cuid);
05ad79
+				rc = scols_line_refer_data(ln, n, arg);
05ad79
+				break;
05ad79
+			case COL_CUSER:
05ad79
+				arg = get_username(&cpw, semdsp->sem_perm.cuid);
05ad79
+				if (arg)
05ad79
+					rc = scols_line_refer_data(ln, n, arg);
05ad79
+				break;
05ad79
+			case COL_CGID:
05ad79
+				xasprintf(&arg, "%u", semdsp->sem_perm.cgid);
05ad79
+				rc = scols_line_refer_data(ln, n, arg);
05ad79
+				break;
05ad79
+			case COL_CGROUP:
05ad79
+				arg = get_groupname(&cgr, semdsp->sem_perm.cgid);
05ad79
+				if (arg)
05ad79
+					rc = scols_line_refer_data(ln, n, arg);
05ad79
+				break;
05ad79
+			case COL_UID:
05ad79
+				xasprintf(&arg, "%u", semdsp->sem_perm.uid);
05ad79
+				rc = scols_line_refer_data(ln, n, arg);
05ad79
+				break;
05ad79
+			case COL_USER:
05ad79
+				arg = get_username(&pw, semdsp->sem_perm.uid);
05ad79
+				if (arg)
05ad79
+					rc = scols_line_refer_data(ln, n, arg);
05ad79
+				break;
05ad79
+			case COL_GID:
05ad79
+				xasprintf(&arg, "%u", semdsp->sem_perm.gid);
05ad79
+				rc = scols_line_refer_data(ln, n, arg);
05ad79
+				break;
05ad79
+			case COL_GROUP:
05ad79
+				arg = get_groupname(&gr, semdsp->sem_perm.gid);
05ad79
+				if (arg)
05ad79
+					rc = scols_line_refer_data(ln, n, arg);
05ad79
+				break;
05ad79
+			case COL_CTIME:
05ad79
+				if (semdsp->sem_ctime != 0) {
05ad79
+					rc = scols_line_refer_data(ln, n,
05ad79
+							make_time(ctl->time_mode,
05ad79
+							  (time_t)semdsp->sem_ctime));
05ad79
+				}
05ad79
+				break;
05ad79
+			case COL_NSEMS:
05ad79
+				xasprintf(&arg, "%ju", semdsp->sem_nsems);
05ad79
+				rc = scols_line_refer_data(ln, n, arg);
05ad79
+				break;
05ad79
+			case COL_OTIME:
05ad79
+				if (semdsp->sem_otime != 0) {
05ad79
+					rc = scols_line_refer_data(ln, n,
05ad79
+							make_time(ctl->time_mode,
05ad79
+							  (time_t)semdsp->sem_otime));
05ad79
+				}
05ad79
+				break;
05ad79
+			}
05ad79
+			if (rc != 0)
05ad79
+				err(EXIT_FAILURE, _("failed to set data"));
05ad79
+			arg = NULL;
05ad79
+		}
05ad79
+
05ad79
+		if (id > -1 && semds->sem_nsems) {
05ad79
+			/* Create extra table with ID specific semaphore elements */
05ad79
+			struct libscols_table *sub = new_table(ctl);
05ad79
+			size_t i;
05ad79
+			int rc = 0;
05ad79
+
05ad79
+			scols_table_enable_noheadings(sub, 0);
05ad79
+			setup_sem_elements_columns(sub);
05ad79
+
05ad79
+			for (i = 0; i < semds->sem_nsems; i++) {
05ad79
+				struct sem_elem *e = &semds->elements[i];
05ad79
+				struct libscols_line *sln = scols_table_new_line(sub, NULL);
05ad79
+
05ad79
+				/* SEMNUM */
05ad79
+				xasprintf(&arg, "%zu", i);
05ad79
+				rc = scols_line_refer_data(sln, 0, arg);
05ad79
+				if (rc)
05ad79
+					break;
05ad79
+
05ad79
+				/* VALUE */
05ad79
+				xasprintf(&arg, "%d", e->semval);
05ad79
+				rc = scols_line_refer_data(sln, 1, arg);
05ad79
+				if (rc)
05ad79
+					break;
05ad79
+
05ad79
+				/* NCOUNT */
05ad79
+				xasprintf(&arg, "%d", e->ncount);
05ad79
+				rc = scols_line_refer_data(sln, 2, arg);
05ad79
+				if (rc)
05ad79
+					break;
05ad79
+
05ad79
+				/* ZCOUNT */
05ad79
+				xasprintf(&arg, "%d", e->zcount);
05ad79
+				rc = scols_line_refer_data(sln, 3, arg);
05ad79
+				if (rc)
05ad79
+					break;
05ad79
+
05ad79
+				/* PID */
05ad79
+				xasprintf(&arg, "%d", e->pid);
05ad79
+				rc = scols_line_refer_data(sln, 4, arg);
05ad79
+				if (rc)
05ad79
+					break;
05ad79
+
05ad79
+				/* COMMAND */
05ad79
+				arg = proc_get_command(e->pid);
05ad79
+				rc = scols_line_refer_data(sln, 5, arg);
05ad79
+				if (rc)
05ad79
+					break;
05ad79
+			}
05ad79
+
05ad79
+			if (rc != 0)
05ad79
+				err(EXIT_FAILURE, _("failed to set data"));
05ad79
+
05ad79
+			scols_line_set_userdata(ln, (void *)sub);
05ad79
+			break;
05ad79
+		}
05ad79
+	}
05ad79
+	ipc_sem_free_info(semds);
05ad79
+}
05ad79
+
05ad79
+static void do_sem_global(struct libscols_table *tb)
05ad79
+{
05ad79
+	struct sem_data *semds, *semdsp;
05ad79
+	struct ipc_limits lim;
05ad79
+	int nsems = 0, nsets = 0;
05ad79
+
05ad79
+	ipc_sem_get_limits(&lim);
05ad79
+
05ad79
+	if (ipc_sem_get_info(-1, &semds) > 0) {
05ad79
+		for (semdsp = semds; semdsp->next != NULL; semdsp = semdsp->next) {
05ad79
+			++nsets;
05ad79
+			nsems += semds->sem_nsems;
05ad79
+		}
05ad79
+		ipc_sem_free_info(semds);
05ad79
+	}
05ad79
+
05ad79
+	global_set_data(tb, "SEMMNI", _("Number of semaphore identifiers"), nsets, lim.semmni, 1);
05ad79
+	global_set_data(tb, "SEMMNS", _("Total number of semaphores"), nsems, lim.semmns, 1);
05ad79
+	global_set_data(tb, "SEMMSL", _("Max semaphores per semaphore set."), 0, lim.semmsl, 0);
05ad79
+	global_set_data(tb, "SEMOPM", _("Max number of operations per semop(2)"), 0, lim.semopm, 0);
05ad79
+	global_set_data(tb, "SEMVMX", _("Semaphore max value"), 0, lim.semvmx, 0);
05ad79
+}
05ad79
+
05ad79
+static void do_msg(int id, struct lsipc_control *ctl, struct libscols_table *tb)
05ad79
+{
05ad79
+	struct libscols_line *ln;
05ad79
+	struct passwd *pw = NULL;
05ad79
+	struct group *gr = NULL;
05ad79
+	struct msg_data *msgds, *msgdsp;
05ad79
+	char *arg = NULL;
05ad79
+
05ad79
+	if (ipc_msg_get_info(id, &msgds) < 1) {
05ad79
+		if (id > -1)
05ad79
+			warnx(_("id %d not found"), id);
05ad79
+		return;
05ad79
+	}
05ad79
+
05ad79
+	for (msgdsp = msgds; msgdsp->next != NULL || id > -1 ; msgdsp = msgdsp->next) {
05ad79
+		size_t n;
05ad79
+		ln = scols_table_new_line(tb, NULL);
05ad79
+
05ad79
+		/* no need to call getpwuid() for the same user */
05ad79
+		if (!(pw && pw->pw_uid == msgdsp->msg_perm.uid))
05ad79
+			pw = getpwuid(msgdsp->msg_perm.uid);
05ad79
+
05ad79
+		/* no need to call getgrgid() for the same user */
05ad79
+		if (!(gr && gr->gr_gid == msgdsp->msg_perm.gid))
05ad79
+			gr = getgrgid(msgdsp->msg_perm.gid);
05ad79
+
05ad79
+		for (n = 0; n < ncolumns; n++) {
05ad79
+			int rc = 0;
05ad79
+
05ad79
+			switch (columns[n]) {
05ad79
+			case COL_KEY:
05ad79
+				xasprintf(&arg, "0x%08x",msgdsp->msg_perm.key);
05ad79
+				rc = scols_line_refer_data(ln, n, arg);
05ad79
+				break;
05ad79
+			case COL_ID:
05ad79
+				xasprintf(&arg, "%d",msgdsp->msg_perm.id);
05ad79
+				rc = scols_line_refer_data(ln, n, arg);
05ad79
+				break;
05ad79
+			case COL_OWNER:
05ad79
+				arg = get_username(&pw, msgdsp->msg_perm.uid);
05ad79
+				if (!arg)
05ad79
+					xasprintf(&arg, "%u", msgdsp->msg_perm.uid);
05ad79
+				rc = scols_line_refer_data(ln, n, arg);
05ad79
+				break;
05ad79
+			case COL_PERMS:
05ad79
+				if (ctl->numperms)
05ad79
+					xasprintf(&arg, "%#o", msgdsp->msg_perm.mode & 0777);
05ad79
+				else {
05ad79
+					arg = xmalloc(11);
05ad79
+					strmode(msgdsp->msg_perm.mode & 0777, arg);
05ad79
+					rc = scols_line_refer_data(ln, n, arg);
05ad79
+				}
05ad79
+				break;
05ad79
+			case COL_CUID:
05ad79
+				xasprintf(&arg, "%u", msgdsp->msg_perm.cuid);
05ad79
+				rc = scols_line_refer_data(ln, n, arg);
05ad79
+				break;
05ad79
+			case COL_CUSER:
05ad79
+				arg = get_username(&pw, msgdsp->msg_perm.cuid);
05ad79
+				if (arg)
05ad79
+					rc = scols_line_refer_data(ln, n, arg);
05ad79
+				break;
05ad79
+			case COL_CGID:
05ad79
+				xasprintf(&arg, "%u", msgdsp->msg_perm.cuid);
05ad79
+				rc = scols_line_refer_data(ln, n, arg);
05ad79
+				break;
05ad79
+			case COL_CGROUP:
05ad79
+				arg = get_groupname(&gr, msgdsp->msg_perm.cgid);
05ad79
+				if (arg)
05ad79
+					rc = scols_line_refer_data(ln, n, arg);
05ad79
+				break;
05ad79
+			case COL_UID:
05ad79
+				xasprintf(&arg, "%u", msgdsp->msg_perm.uid);
05ad79
+				rc = scols_line_refer_data(ln, n, arg);
05ad79
+				break;
05ad79
+			case COL_USER:
05ad79
+				arg = get_username(&pw, msgdsp->msg_perm.uid);
05ad79
+				if (arg)
05ad79
+					rc = scols_line_refer_data(ln, n, arg);
05ad79
+				break;
05ad79
+			case COL_GID:
05ad79
+				xasprintf(&arg, "%u", msgdsp->msg_perm.gid);
05ad79
+				rc = scols_line_refer_data(ln, n, arg);
05ad79
+				break;
05ad79
+			case COL_GROUP:
05ad79
+				arg = get_groupname(&gr,msgdsp->msg_perm.gid);
05ad79
+				if (arg)
05ad79
+					rc = scols_line_refer_data(ln, n, arg);
05ad79
+				break;
05ad79
+			case COL_CTIME:
05ad79
+				if (msgdsp->q_ctime != 0)
05ad79
+					rc = scols_line_refer_data(ln, n,
05ad79
+						make_time(ctl->time_mode,
05ad79
+							  (time_t)msgdsp->q_ctime));
05ad79
+				break;
05ad79
+			case COL_USEDBYTES:
05ad79
+				xasprintf(&arg, "%ju", msgdsp->q_cbytes);
05ad79
+				rc = scols_line_refer_data(ln, n, arg);
05ad79
+				break;
05ad79
+			case COL_MSGS:
05ad79
+				xasprintf(&arg, "%ju", msgdsp->q_qnum);
05ad79
+				rc = scols_line_refer_data(ln, n, arg);
05ad79
+				break;
05ad79
+			case COL_SEND:
05ad79
+				if (msgdsp->q_stime != 0)
05ad79
+					rc = scols_line_refer_data(ln, n,
05ad79
+						make_time(ctl->time_mode,
05ad79
+							  (time_t)msgdsp->q_stime));
05ad79
+				break;
05ad79
+			case COL_RECV:
05ad79
+				if (msgdsp->q_rtime != 0)
05ad79
+					rc = scols_line_refer_data(ln, n,
05ad79
+						make_time(ctl->time_mode,
05ad79
+							  (time_t)msgdsp->q_rtime));
05ad79
+				break;
05ad79
+			case COL_LSPID:
05ad79
+				xasprintf(&arg, "%u", msgdsp->q_lspid);
05ad79
+				rc = scols_line_refer_data(ln, n, arg);
05ad79
+				break;
05ad79
+			case COL_LRPID:
05ad79
+				xasprintf(&arg, "%u", msgdsp->q_lrpid);
05ad79
+				rc = scols_line_refer_data(ln, n, arg);
05ad79
+				break;
05ad79
+			}
05ad79
+			if (rc != 0)
05ad79
+				err(EXIT_FAILURE, _("failed to set data"));
05ad79
+			arg = NULL;
05ad79
+		}
05ad79
+		if (id > -1)
05ad79
+			break;
05ad79
+	}
05ad79
+	ipc_msg_free_info(msgds);
05ad79
+}
05ad79
+
05ad79
+
05ad79
+static void do_msg_global(struct libscols_table *tb)
05ad79
+{
05ad79
+	struct msg_data *msgds, *msgdsp;
05ad79
+	struct ipc_limits lim;
05ad79
+	int msgqs = 0;
05ad79
+
05ad79
+	ipc_msg_get_limits(&lim);
05ad79
+
05ad79
+	/* count number of used queues */
05ad79
+	if (ipc_msg_get_info(-1, &msgds) > 0) {
05ad79
+		for (msgdsp = msgds; msgdsp->next != NULL; msgdsp = msgdsp->next)
05ad79
+			++msgqs;
05ad79
+		ipc_msg_free_info(msgds);
05ad79
+	}
05ad79
+
05ad79
+	global_set_data(tb, "MSGMNI", _("Number of message queues"), msgqs, lim.msgmni, 1);
05ad79
+	global_set_data(tb, "MSGMAX", _("Max size of message (bytes)"),	0, lim.msgmax, 0);
05ad79
+	global_set_data(tb, "MSGMNB", _("Default max size of queue (bytes)"), 0, lim.msgmnb, 0);
05ad79
+}
05ad79
+
05ad79
+
05ad79
+static void do_shm(int id, struct lsipc_control *ctl, struct libscols_table *tb)
05ad79
+{
05ad79
+	struct libscols_line *ln;
05ad79
+	struct passwd *pw = NULL;
05ad79
+	struct group *gr = NULL;
05ad79
+	struct shm_data *shmds, *shmdsp;
05ad79
+	char *arg = NULL;
05ad79
+
05ad79
+	if (ipc_shm_get_info(id, &shmds) < 1) {
05ad79
+		if (id > -1)
05ad79
+			warnx(_("id %d not found"), id);
05ad79
+		return;
05ad79
+	}
05ad79
+
05ad79
+	for (shmdsp = shmds; shmdsp->next != NULL || id > -1 ; shmdsp = shmdsp->next) {
05ad79
+		size_t n;
05ad79
+		ln = scols_table_new_line(tb, NULL);
05ad79
+		if (!ln)
05ad79
+			err_oom();
05ad79
+
05ad79
+		for (n = 0; n < ncolumns; n++) {
05ad79
+			int rc = 0;
05ad79
+
05ad79
+			switch (columns[n]) {
05ad79
+			case COL_KEY:
05ad79
+				xasprintf(&arg, "0x%08x",shmdsp->shm_perm.key);
05ad79
+				rc = scols_line_refer_data(ln, n, arg);
05ad79
+				break;
05ad79
+			case COL_ID:
05ad79
+				xasprintf(&arg, "%d",shmdsp->shm_perm.id);
05ad79
+				rc = scols_line_refer_data(ln, n, arg);
05ad79
+				break;
05ad79
+			case COL_OWNER:
05ad79
+				arg = get_username(&pw, shmdsp->shm_perm.uid);
05ad79
+				if (!arg)
05ad79
+					xasprintf(&arg, "%u", shmdsp->shm_perm.uid);
05ad79
+				rc = scols_line_refer_data(ln, n, arg);
05ad79
+				break;
05ad79
+			case COL_PERMS:
05ad79
+				if (ctl->numperms)
05ad79
+					xasprintf(&arg, "%#o", shmdsp->shm_perm.mode & 0777);
05ad79
+				else {
05ad79
+					arg = xmalloc(11);
05ad79
+					strmode(shmdsp->shm_perm.mode & 0777, arg);
05ad79
+				}
05ad79
+				rc = scols_line_refer_data(ln, n, arg);
05ad79
+				break;
05ad79
+			case COL_CUID:
05ad79
+				xasprintf(&arg, "%u", shmdsp->shm_perm.cuid);
05ad79
+				rc = scols_line_refer_data(ln, n, arg);
05ad79
+				break;
05ad79
+			case COL_CUSER:
05ad79
+				arg = get_username(&pw, shmdsp->shm_perm.cuid);
05ad79
+				if (arg)
05ad79
+					rc = scols_line_refer_data(ln, n, arg);
05ad79
+				break;
05ad79
+			case COL_CGID:
05ad79
+				xasprintf(&arg, "%u", shmdsp->shm_perm.cuid);
05ad79
+				rc = scols_line_refer_data(ln, n, arg);
05ad79
+				break;
05ad79
+			case COL_CGROUP:
05ad79
+				arg = get_groupname(&gr, shmdsp->shm_perm.cgid);
05ad79
+				if (arg)
05ad79
+					rc = scols_line_refer_data(ln, n, arg);
05ad79
+				break;
05ad79
+			case COL_UID:
05ad79
+				xasprintf(&arg, "%u", shmdsp->shm_perm.uid);
05ad79
+				rc = scols_line_refer_data(ln, n, arg);
05ad79
+				break;
05ad79
+			case COL_USER:
05ad79
+				arg = get_username(&pw, shmdsp->shm_perm.uid);
05ad79
+				if (arg)
05ad79
+					rc = scols_line_refer_data(ln, n, arg);
05ad79
+				break;
05ad79
+			case COL_GID:
05ad79
+				xasprintf(&arg, "%u", shmdsp->shm_perm.gid);
05ad79
+				rc = scols_line_refer_data(ln, n, arg);
05ad79
+				break;
05ad79
+			case COL_GROUP:
05ad79
+				arg = get_groupname(&gr, shmdsp->shm_perm.gid);
05ad79
+				if (arg)
05ad79
+					rc = scols_line_refer_data(ln, n, arg);
05ad79
+				break;
05ad79
+			case COL_CTIME:
05ad79
+				if (shmdsp->shm_ctim != 0)
05ad79
+					rc = scols_line_refer_data(ln, n,
05ad79
+						make_time(ctl->time_mode,
05ad79
+							  (time_t)shmdsp->shm_ctim));
05ad79
+				break;
05ad79
+			case COL_SIZE:
05ad79
+				if (ctl->bytes)
05ad79
+					xasprintf(&arg, "%ju", shmdsp->shm_segsz);
05ad79
+				else
05ad79
+					arg = size_to_human_string(SIZE_SUFFIX_1LETTER, shmdsp->shm_segsz);
05ad79
+				rc = scols_line_refer_data(ln, n, arg);
05ad79
+				break;
05ad79
+			case COL_NATTCH:
05ad79
+				xasprintf(&arg, "%ju", shmdsp->shm_nattch);
05ad79
+				rc = scols_line_refer_data(ln, n, arg);
05ad79
+				break;
05ad79
+			case COL_STATUS: {
05ad79
+					int comma = 0;
05ad79
+					size_t offt = 0;
05ad79
+
05ad79
+					free(arg);
05ad79
+					arg = xcalloc(1, sizeof(char) * strlen(_("dest"))
05ad79
+							+ strlen(_("locked"))
05ad79
+							+ strlen(_("hugetlb"))
05ad79
+							+ strlen(_("noreserve")) + 4);
05ad79
+#ifdef SHM_DEST
05ad79
+					if (shmdsp->shm_perm.mode & SHM_DEST) {
05ad79
+						offt += sprintf(arg, "%s", _("dest"));
05ad79
+						comma++;
05ad79
+					}
05ad79
+#endif
05ad79
+#ifdef SHM_LOCKED
05ad79
+					if (shmdsp->shm_perm.mode & SHM_LOCKED) {
05ad79
+						if (comma)
05ad79
+							arg[offt++] = ',';
05ad79
+						offt += sprintf(arg + offt, "%s", _("locked"));
05ad79
+					}
05ad79
+#endif
05ad79
+#ifdef SHM_HUGETLB
05ad79
+					if (shmdsp->shm_perm.mode & SHM_HUGETLB) {
05ad79
+						if (comma)
05ad79
+							arg[offt++] = ',';
05ad79
+						offt += sprintf(arg + offt, "%s", _("hugetlb"));
05ad79
+					}
05ad79
+#endif
05ad79
+#ifdef SHM_NORESERVE
05ad79
+					if (shmdsp->shm_perm.mode & SHM_NORESERVE) {
05ad79
+						if (comma)
05ad79
+							arg[offt++] = ',';
05ad79
+						sprintf(arg + offt, "%s", _("noreserve"));
05ad79
+					}
05ad79
+#endif
05ad79
+					rc = scols_line_refer_data(ln, n, arg);
05ad79
+				}
05ad79
+				break;
05ad79
+			case COL_ATTACH:
05ad79
+				if (shmdsp->shm_atim != 0)
05ad79
+					rc = scols_line_refer_data(ln, n,
05ad79
+							make_time(ctl->time_mode,
05ad79
+							  (time_t)shmdsp->shm_atim));
05ad79
+				break;
05ad79
+			case COL_DETACH:
05ad79
+				if (shmdsp->shm_dtim != 0)
05ad79
+					rc = scols_line_refer_data(ln, n,
05ad79
+							make_time(ctl->time_mode,
05ad79
+							  (time_t)shmdsp->shm_dtim));
05ad79
+				break;
05ad79
+			case COL_CPID:
05ad79
+				xasprintf(&arg, "%u", shmdsp->shm_cprid);
05ad79
+				rc = scols_line_refer_data(ln, n, arg);
05ad79
+				break;
05ad79
+			case COL_LPID:
05ad79
+				xasprintf(&arg, "%u", shmdsp->shm_lprid);
05ad79
+				rc = scols_line_refer_data(ln, n, arg);
05ad79
+				break;
05ad79
+			case COL_COMMAND:
05ad79
+				arg = proc_get_command(shmdsp->shm_cprid);
05ad79
+				rc = scols_line_refer_data(ln, n, arg);
05ad79
+				break;
05ad79
+			}
05ad79
+			if (rc != 0)
05ad79
+				err(EXIT_FAILURE, _("failed to set data"));
05ad79
+			arg = NULL;
05ad79
+		}
05ad79
+		if (id > -1)
05ad79
+			break;
05ad79
+	}
05ad79
+	ipc_shm_free_info(shmds);
05ad79
+}
05ad79
+
05ad79
+static void do_shm_global(struct libscols_table *tb)
05ad79
+{
05ad79
+	struct shm_data *shmds, *shmdsp;
05ad79
+	uint64_t nsegs = 0, sum_segsz = 0;
05ad79
+	struct ipc_limits lim;
05ad79
+
05ad79
+	ipc_shm_get_limits(&lim);
05ad79
+
05ad79
+	if (ipc_shm_get_info(-1, &shmds) > 0) {
05ad79
+		for (shmdsp = shmds; shmdsp->next != NULL; shmdsp = shmdsp->next) {
05ad79
+			++nsegs;
05ad79
+			sum_segsz += shmdsp->shm_segsz;
05ad79
+		}
05ad79
+		ipc_shm_free_info(shmds);
05ad79
+	}
05ad79
+
05ad79
+	global_set_data(tb, "SHMMNI", _("Shared memory segments"), nsegs, lim.shmmni, 1);
05ad79
+	global_set_data(tb, "SHMALL", _("Shared memory pages"), sum_segsz / getpagesize(), lim.shmall, 1);
05ad79
+	global_set_data(tb, "SHMMAX", _("Max size of shared memory segment (bytes)"), 0, lim.shmmax, 0);
05ad79
+	global_set_data(tb, "SHMMIN", _("Min size of shared memory segment (bytes)"), 0, lim.shmmin, 0);
05ad79
+}
05ad79
+
05ad79
+int main(int argc, char *argv[])
05ad79
+{
05ad79
+	int opt, msg = 0, sem = 0, shm = 0, id = -1;
05ad79
+	int show_time = 0, show_creat = 0, global = 0;
05ad79
+	size_t i;
05ad79
+	struct lsipc_control *ctl = xcalloc(1, sizeof(struct lsipc_control));
05ad79
+	static struct libscols_table *tb;
05ad79
+	char *outarg = NULL;
05ad79
+
05ad79
+	/* long only options. */
05ad79
+	enum {
05ad79
+		OPT_NOTRUNC = CHAR_MAX + 1,
05ad79
+		OPT_NOHEAD,
05ad79
+		OPT_TIME_FMT
05ad79
+	};
05ad79
+
05ad79
+	static const struct option longopts[] = {
05ad79
+		{ "bytes",          no_argument,        0, 'b' },
05ad79
+		{ "creator",        no_argument,	0, 'c' },
05ad79
+		{ "export",         no_argument,	0, 'e' },
05ad79
+		{ "global",         no_argument,	0, 'g' },
05ad79
+		{ "help",           no_argument,	0, 'h' },
05ad79
+		{ "id",             required_argument,	0, 'i' },
05ad79
+		{ "list",           no_argument,        0, 'l' },
05ad79
+		{ "newline",        no_argument,	0, 'n' },
05ad79
+		{ "noheadings",     no_argument,	0, OPT_NOHEAD },
05ad79
+		{ "notruncate",     no_argument,	0, OPT_NOTRUNC },
05ad79
+		{ "numeric-perms",  no_argument,	0, 'P' },
05ad79
+		{ "output",         required_argument,	0, 'o' },
05ad79
+		{ "pid",            no_argument,	0, 'p' },
05ad79
+		{ "queues",         no_argument,	0, 'q' },
05ad79
+		{ "raw",            no_argument,	0, 'r' },
05ad79
+		{ "semaphores",     no_argument,	0, 's' },
05ad79
+		{ "shmems",         no_argument,	0, 'm' },
05ad79
+		{ "time",           no_argument,	0, 't' },
05ad79
+		{ "time-format",    required_argument,	0, OPT_TIME_FMT },
05ad79
+		{ "version",        no_argument,	0, 'V' },
05ad79
+		{NULL, 0, NULL, 0}
05ad79
+	};
05ad79
+
05ad79
+	static const ul_excl_t excl[] = {	/* rows and cols in ASCII order */
05ad79
+		{ 'J', 'e', 'l', 'n', 'r' },
05ad79
+		{ 'g', 'i' },
05ad79
+		{ 'c', 'o', 't' },
05ad79
+		{ 'm', 'q', 's' },
05ad79
+		{ 0 }
05ad79
+	};
05ad79
+	int excl_st[ARRAY_SIZE(excl)] = UL_EXCL_STATUS_INIT;
05ad79
+
05ad79
+	setlocale(LC_ALL, "");
05ad79
+	bindtextdomain(PACKAGE, LOCALEDIR);
05ad79
+	textdomain(PACKAGE);
05ad79
+	atexit(close_stdout);
05ad79
+
05ad79
+	ctl->time_mode = 0;
05ad79
+
05ad79
+	scols_init_debug(0);
05ad79
+
05ad79
+	while ((opt = getopt_long(argc, argv, "bceghi:lmno:PqrstuV", longopts, NULL)) != -1) {
05ad79
+
05ad79
+		err_exclusive_options(opt, longopts, excl, excl_st);
05ad79
+
05ad79
+		switch (opt) {
05ad79
+		case 'b':
05ad79
+			ctl->bytes = 1;
05ad79
+			break;
05ad79
+		case 'i':
05ad79
+			id = strtos32_or_err(optarg, _("failed to parse IPC identifier"));
05ad79
+			break;
05ad79
+		case 'e':
05ad79
+			ctl->outmode = OUT_EXPORT;
05ad79
+			break;
05ad79
+		case 'r':
05ad79
+			ctl->outmode = OUT_RAW;
05ad79
+			break;
05ad79
+		case 'o':
05ad79
+			outarg = optarg;
05ad79
+			break;
05ad79
+		case 'g':
05ad79
+			global = 1;
05ad79
+			break;
05ad79
+		case 'q':
05ad79
+			msg = 1;
05ad79
+			add_column(columns, ncolumns++, COL_KEY);
05ad79
+			add_column(columns, ncolumns++, COL_ID);
05ad79
+			add_column(columns, ncolumns++, COL_PERMS);
05ad79
+			add_column(columns, ncolumns++, COL_OWNER);
05ad79
+			add_column(columns, ncolumns++, COL_USEDBYTES);
05ad79
+			add_column(columns, ncolumns++, COL_MSGS);
05ad79
+			add_column(columns, ncolumns++, COL_LSPID);
05ad79
+			add_column(columns, ncolumns++, COL_LRPID);
05ad79
+			LOWER = COLDESC_IDX_MSG_FIRST;
05ad79
+			UPPER = COLDESC_IDX_MSG_LAST;
05ad79
+			break;
05ad79
+		case 'l':
05ad79
+			ctl->outmode = OUT_LIST;
05ad79
+			break;
05ad79
+		case 'm':
05ad79
+			shm = 1;
05ad79
+			add_column(columns, ncolumns++, COL_KEY);
05ad79
+			add_column(columns, ncolumns++, COL_ID);
05ad79
+			add_column(columns, ncolumns++, COL_PERMS);
05ad79
+			add_column(columns, ncolumns++, COL_OWNER);
05ad79
+			add_column(columns, ncolumns++, COL_SIZE);
05ad79
+			add_column(columns, ncolumns++, COL_NATTCH);
05ad79
+			add_column(columns, ncolumns++, COL_STATUS);
05ad79
+			add_column(columns, ncolumns++, COL_CTIME);
05ad79
+			add_column(columns, ncolumns++, COL_CPID);
05ad79
+			add_column(columns, ncolumns++, COL_LPID);
05ad79
+			add_column(columns, ncolumns++, COL_COMMAND);
05ad79
+			LOWER = COLDESC_IDX_SHM_FIRST;
05ad79
+			UPPER = COLDESC_IDX_SHM_LAST;
05ad79
+			break;
05ad79
+		case 'n':
05ad79
+			ctl->outmode = OUT_NEWLINE;
05ad79
+			break;
05ad79
+		case 'P':
05ad79
+			ctl->numperms = 1;
05ad79
+			break;
05ad79
+		case 's':
05ad79
+			sem = 1;
05ad79
+			add_column(columns, ncolumns++, COL_KEY);
05ad79
+			add_column(columns, ncolumns++, COL_ID);
05ad79
+			add_column(columns, ncolumns++, COL_PERMS);
05ad79
+			add_column(columns, ncolumns++, COL_OWNER);
05ad79
+			add_column(columns, ncolumns++, COL_NSEMS);
05ad79
+			LOWER = COLDESC_IDX_SEM_FIRST;
05ad79
+			UPPER = COLDESC_IDX_SEM_LAST;
05ad79
+			break;
05ad79
+		case OPT_NOTRUNC:
05ad79
+			ctl->notrunc = 1;
05ad79
+			break;
05ad79
+		case OPT_NOHEAD:
05ad79
+			ctl->noheadings = 1;
05ad79
+			break;
05ad79
+		case OPT_TIME_FMT:
05ad79
+			ctl->time_mode = parse_time_mode(optarg);
05ad79
+			break;
05ad79
+		case 't':
05ad79
+			show_time = 1;
05ad79
+			break;
05ad79
+		case 'c':
05ad79
+			show_creat = 1;
05ad79
+			break;
05ad79
+		case 'h':
05ad79
+			usage(stdout);
05ad79
+		case 'V':
05ad79
+			printf(UTIL_LINUX_VERSION);
05ad79
+			return EXIT_SUCCESS;
05ad79
+		default:
05ad79
+			usage(stderr);
05ad79
+		}
05ad79
+	}
05ad79
+
05ad79
+	/* default is global */
05ad79
+	if (msg + shm + sem == 0) {
05ad79
+		msg = shm = sem = global = 1;
05ad79
+		if (show_time || show_creat || id != -1)
05ad79
+			errx(EXIT_FAILURE, _("--global is mutually exclusive with --creator, --id and --time"));
05ad79
+	}
05ad79
+	if (global) {
05ad79
+		add_column(columns, ncolumns++, COL_RESOURCE);
05ad79
+		add_column(columns, ncolumns++, COL_DESC);
05ad79
+		add_column(columns, ncolumns++, COL_LIMIT);
05ad79
+		add_column(columns, ncolumns++, COL_USED);
05ad79
+		add_column(columns, ncolumns++, COL_USEPERC);
05ad79
+		LOWER = COLDESC_IDX_SUM_FIRST;
05ad79
+		UPPER = COLDESC_IDX_SUM_LAST;
05ad79
+	}
05ad79
+
05ad79
+	/* default to pretty-print if --id specified */
05ad79
+	if (id != -1 && !ctl->outmode)
05ad79
+		ctl->outmode = OUT_PRETTY;
05ad79
+
05ad79
+	if (!ctl->time_mode)
05ad79
+		ctl->time_mode = ctl->outmode == OUT_PRETTY ? TIME_FULL : TIME_SHORT;
05ad79
+
05ad79
+	if (ctl->outmode == OUT_PRETTY && !(optarg || show_creat || show_time)) {
05ad79
+		/* all columns for lsipc --<RESOURCE> --id <ID> */
05ad79
+		for (ncolumns = 0, i = 0; i < ARRAY_SIZE(coldescs); i++)
05ad79
+			 columns[ncolumns++] = i;
05ad79
+	} else {
05ad79
+		if (show_creat) {
05ad79
+			add_column(columns, ncolumns++, COL_CUID);
05ad79
+			add_column(columns, ncolumns++, COL_CGID);
05ad79
+			add_column(columns, ncolumns++, COL_UID);
05ad79
+			add_column(columns, ncolumns++, COL_GID);
05ad79
+		}
05ad79
+		if (msg && show_time) {
05ad79
+			add_column(columns, ncolumns++, COL_SEND);
05ad79
+			add_column(columns, ncolumns++, COL_RECV);
05ad79
+			add_column(columns, ncolumns++, COL_CTIME);
05ad79
+		}
05ad79
+		if (shm && show_time) {
05ad79
+			/* keep "COMMAND" as last column */
05ad79
+			size_t cmd = columns[ncolumns - 1] == COL_COMMAND;
05ad79
+
05ad79
+			if (cmd)
05ad79
+				ncolumns--;
05ad79
+			add_column(columns, ncolumns++, COL_ATTACH);
05ad79
+			add_column(columns, ncolumns++, COL_DETACH);
05ad79
+			if (cmd)
05ad79
+				add_column(columns, ncolumns++, COL_COMMAND);
05ad79
+		}
05ad79
+		if (sem && show_time) {
05ad79
+			add_column(columns, ncolumns++, COL_OTIME);
05ad79
+			add_column(columns, ncolumns++, COL_CTIME);
05ad79
+		}
05ad79
+	}
05ad79
+
05ad79
+	if (outarg && string_add_to_idarray(outarg, columns, ARRAY_SIZE(columns),
05ad79
+					 (int *) &ncolumns, column_name_to_id) < 0)
05ad79
+		return EXIT_FAILURE;
05ad79
+
05ad79
+	tb = setup_table(ctl);
05ad79
+	if (!tb)
05ad79
+		return EXIT_FAILURE;
05ad79
+
05ad79
+	if (msg) {
05ad79
+		if (global)
05ad79
+			do_msg_global(tb);
05ad79
+		else
05ad79
+			do_msg(id, ctl, tb);
05ad79
+	}
05ad79
+	if (shm) {
05ad79
+		if (global)
05ad79
+			do_shm_global(tb);
05ad79
+		else
05ad79
+			do_shm(id, ctl, tb);
05ad79
+	}
05ad79
+	if (sem) {
05ad79
+		if (global)
05ad79
+			do_sem_global(tb);
05ad79
+		else
05ad79
+			do_sem(id, ctl, tb);
05ad79
+	}
05ad79
+
05ad79
+	print_table(ctl, tb);
05ad79
+
05ad79
+	scols_unref_table(tb);
05ad79
+	free(ctl);
05ad79
+
05ad79
+	return EXIT_SUCCESS;
05ad79
+}
05ad79
+
05ad79
diff --git a/tests/functions.sh b/tests/functions.sh
05ad79
index 123f6c3..b2d493c 100644
05ad79
--- a/tests/functions.sh
05ad79
+++ b/tests/functions.sh
05ad79
@@ -50,16 +50,25 @@ function ts_skip_nonroot {
05ad79
 }
05ad79
 
05ad79
 function ts_failed_subtest {
05ad79
+	local msg="FAILED"
05ad79
+	local ret=1
05ad79
+	if [ "$TS_KNOWN_FAIL" = "yes" ]; then
05ad79
+		msg="KNOWN FAILED"
05ad79
+		ret=0
05ad79
+	fi
05ad79
+
05ad79
 	if [ x"$1" == x"" ]; then
05ad79
-		echo " FAILED ($TS_NS)"
05ad79
+		echo " $msg ($TS_NS)"
05ad79
 	else
05ad79
-		echo " FAILED ($1)"
05ad79
+		echo " $msg ($1)"
05ad79
 	fi
05ad79
+
05ad79
+	return $ret
05ad79
 }
05ad79
 
05ad79
 function ts_failed {
05ad79
 	ts_failed_subtest "$1"
05ad79
-	exit 1
05ad79
+	exit $?
05ad79
 }
05ad79
 
05ad79
 function ts_ok_subtest {
05ad79
@@ -150,6 +159,7 @@ function ts_init_env {
05ad79
 	TS_SUBDIR=$(dirname $TS_SCRIPT)
05ad79
 	TS_TESTNAME=$(basename $TS_SCRIPT)
05ad79
 	TS_COMPONENT=$(basename $TS_SUBDIR)
05ad79
+	TS_KNOWN_FAIL="no"
05ad79
 
05ad79
 	TS_NSUBTESTS=0
05ad79
 	TS_NSUBFAILED=0
05ad79
diff --git a/tests/ts/ipcs/limits2 b/tests/ts/ipcs/limits2
05ad79
index f99a354..63f834d 100755
05ad79
--- a/tests/ts/ipcs/limits2
05ad79
+++ b/tests/ts/ipcs/limits2
05ad79
@@ -16,15 +16,20 @@
05ad79
 # GNU General Public License for more details.
05ad79
 #
05ad79
 
05ad79
-TS_TOPDIR="$(dirname $0)/../.."
05ad79
+TS_TOPDIR="${0%/*}/../.."
05ad79
 TS_DESC="basic limits"
05ad79
 
05ad79
 . $TS_TOPDIR/functions.sh
05ad79
 ts_init "$*"
05ad79
-type bc >/dev/null 2>&1 || ts_skip "cannot find bc command"
05ad79
 
05ad79
 . $TS_SELF/functions.sh
05ad79
 
05ad79
+# TODO https://github.com/karelzak/util-linux/issues/51
05ad79
+SHMALL=$(
05ad79
+if [ $(bc <<<"(2^64 / $PAGE_SIZE) <= $SHMALL") -eq 1 ]; then
05ad79
+	TS_KNOWN_FAIL="yes"
05ad79
+fi
05ad79
+
05ad79
 ts_log "check for difference between kernel and IPC"
05ad79
 ipcs_limits_check >> $TS_OUTPUT
05ad79
 
05ad79
-- 
05ad79
2.7.4
05ad79