diff options
author | Karel Zak | 2012-11-05 16:48:12 +0100 |
---|---|---|
committer | Karel Zak | 2012-11-23 14:58:21 +0100 |
commit | 61e14b4a61818568051471075c39fa595b60bb35 (patch) | |
tree | 6532d8ccfd8bb9caf69f09c198679e8953749ff3 /sys-utils/ipcs.c | |
parent | ipcs: read shared memory values from /proc (diff) | |
download | kernel-qcow2-util-linux-61e14b4a61818568051471075c39fa595b60bb35.tar.gz kernel-qcow2-util-linux-61e14b4a61818568051471075c39fa595b60bb35.tar.xz kernel-qcow2-util-linux-61e14b4a61818568051471075c39fa595b60bb35.zip |
ipcs: clean up do_shm()
- don't expect maxid as argument in ipc_shm_get_info()
- if there is @id argument then use it everywhere in ipc_shm_get_info()
- don't call shmctl() if not necessary in do_shm()
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'sys-utils/ipcs.c')
-rw-r--r-- | sys-utils/ipcs.c | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/sys-utils/ipcs.c b/sys-utils/ipcs.c index 496fc334c..d0ad42fcd 100644 --- a/sys-utils/ipcs.c +++ b/sys-utils/ipcs.c @@ -192,20 +192,14 @@ static void print_perms (int id, struct ipc_perm *ipcp) static void do_shm (char format) { - int maxid; - struct shm_info shm_info; struct passwd *pw; - struct ipc_limits lim; struct shm_data *shmds, *shmdsp; - maxid = shmctl (0, SHM_INFO, (struct shmid_ds *) (void *) &shm_info); - if (maxid < 0) { - printf (_("kernel not configured for shared memory\n")); - return; - } - switch (format) { case LIMITS: + { + struct ipc_limits lim; + printf (_("------ Shared Memory Limits --------\n")); if (ipc_shm_get_limits(&lim)) return; @@ -215,8 +209,18 @@ static void do_shm (char format) (lim.shmall / 1024) * getpagesize()); printf (_("min seg size (bytes) = %ju\n"), lim.shmmin); return; - + } case STATUS: + { + int maxid; + struct shm_info shm_info; + + maxid = shmctl (0, SHM_INFO, (struct shmid_ds *) &shm_info); + if (maxid < 0) { + printf (_("kernel not configured for shared memory\n")); + return; + } + printf (_("------ Shared Memory Status --------\n")); /* * TRANSLATORS: This output format is maintained for backward @@ -240,7 +244,11 @@ static void do_shm (char format) shm_info.shm_swp, shm_info.swap_attempts, shm_info.swap_successes); return; + } + /* + * Headers only + */ case CREATOR: printf (_("------ Shared Memory Segment Creators/Owners --------\n")); printf ("%-10s %-10s %-10s %-10s %-10s %-10s\n", @@ -268,7 +276,10 @@ static void do_shm (char format) break; } - if (ipc_shm_get_info(maxid, -1, &shmds) < 1) + /* + * Print data + */ + if (ipc_shm_get_info(-1, &shmds) < 1) return; shmdsp = shmds; |