summaryrefslogtreecommitdiffstats
path: root/sys-utils/ipcutils.c
diff options
context:
space:
mode:
authorKarel Zak2012-11-05 16:48:12 +0100
committerKarel Zak2012-11-23 14:58:21 +0100
commit61e14b4a61818568051471075c39fa595b60bb35 (patch)
tree6532d8ccfd8bb9caf69f09c198679e8953749ff3 /sys-utils/ipcutils.c
parentipcs: read shared memory values from /proc (diff)
downloadkernel-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/ipcutils.c')
-rw-r--r--sys-utils/ipcutils.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/sys-utils/ipcutils.c b/sys-utils/ipcutils.c
index c266ad868..959b70c63 100644
--- a/sys-utils/ipcutils.c
+++ b/sys-utils/ipcutils.c
@@ -91,11 +91,12 @@ int ipc_shm_get_limits(struct ipc_limits *lim)
return 0;
}
-int ipc_shm_get_info(int maxid, int id, struct shm_data **shmds)
+int ipc_shm_get_info(int id, struct shm_data **shmds)
{
FILE *f;
- int i;
+ int i, maxid;
struct shm_data *p;
+ struct shm_info dummy;
p = *shmds = xmalloc(sizeof(struct shm_data));
p->next = NULL;
@@ -129,6 +130,10 @@ int ipc_shm_get_info(int maxid, int id, struct shm_data **shmds)
&p->shm_swp) != 16)
continue;
+ if (id > -1 && id != p->shm_perm.id) {
+ i--;
+ continue; /* id specified, but does not match */
+ }
if (id < 0) {
p->next = xmalloc(sizeof(struct shm_data));
p = p->next;
@@ -145,6 +150,10 @@ int ipc_shm_get_info(int maxid, int id, struct shm_data **shmds)
fallback:
i = id < 0 ? 0 : id;
+ maxid = shmctl(0, SHM_INFO, (struct shmid_ds *) &dummy);
+ if (maxid < 0)
+ return 0;
+
while (i <= maxid) {
int shmid;
struct shmid_ds shmseg;