summaryrefslogtreecommitdiffstats
path: root/sys-utils
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
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')
-rw-r--r--sys-utils/ipcs.c33
-rw-r--r--sys-utils/ipcutils.c13
-rw-r--r--sys-utils/ipcutils.h2
3 files changed, 34 insertions, 14 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;
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;
diff --git a/sys-utils/ipcutils.h b/sys-utils/ipcutils.h
index 8e2bfddfb..45a75d84f 100644
--- a/sys-utils/ipcutils.h
+++ b/sys-utils/ipcutils.h
@@ -129,7 +129,7 @@ struct shm_data {
struct shm_data *next;
};
-extern int ipc_shm_get_info(int maxid, int id, struct shm_data **shmds);
+extern int ipc_shm_get_info(int id, struct shm_data **shmds);
extern void ipc_shm_free_info(struct shm_data *shmds);
#endif /* UTIL_LINUX_IPCUTILS_H */