Sophie

Sophie

distrib > Fedora > 18 > i386 > by-pkgid > 79189b04a38903d452658742101e5bc4 > files > 13

util-linux-2.22.2-7.fc18.src.rpm

diff -up util-linux-2.22.2/sys-utils/ipcs.c.kzak util-linux-2.22.2/sys-utils/ipcs.c
--- util-linux-2.22.2/sys-utils/ipcs.c.kzak	2012-12-12 21:04:47.976355744 +0100
+++ util-linux-2.22.2/sys-utils/ipcs.c	2013-02-19 16:12:54.712551108 +0100
@@ -264,6 +264,27 @@ static void print_perms (int id, struct
 		printf(" %-10u\n", ipcp->gid);
 }
 
+static unsigned long long
+shminfo_from_proc(const char *name, unsigned long def)
+{
+	char path[256];
+	char buf[64];
+	FILE *f;
+	unsigned long long res = def;
+
+	if (!name)
+		return res;
+
+	snprintf(path, sizeof(path), "/proc/sys/kernel/%s", name);
+
+	if (!(f = fopen(path, "r")))
+		return res;
+	if (fgets(buf, sizeof(buf), f))
+		res = atoll(buf);
+	fclose(f);
+	return res;
+}
+
 void do_shm (char format)
 {
 	int maxid, shmid, id;
@@ -288,12 +309,12 @@ void do_shm (char format)
 		 * glibc 2.1.3 and all earlier libc's have ints as fields of
 		 * struct shminfo; glibc 2.1.91 has unsigned long; ach
 		 */
-		printf (_("max number of segments = %lu\n"),
-			(unsigned long) shminfo.shmmni);
-		printf (_("max seg size (kbytes) = %lu\n"),
-			(unsigned long) (shminfo.shmmax >> 10));
+		printf (_("max number of segments = %llu\n"),
+			shminfo_from_proc("shmmni", shminfo.shmmni));
+		printf (_("max seg size (kbytes) = %llu\n"),
+			(shminfo_from_proc("shmmax", shminfo.shmmax) >> 10));
 		printf (_("max total shared memory (kbytes) = %llu\n"),
-			getpagesize() / 1024 * (unsigned long long) shminfo.shmall);
+			getpagesize() / 1024 * shminfo_from_proc("shmall", shminfo.shmall));
 		printf (_("min seg size (bytes) = %lu\n"),
 			(unsigned long) shminfo.shmmin);
 		return;