From 3ec6f77833a530a38592ff0c261c4d4c7c42196b Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Sun, 21 Oct 2012 15:33:25 +0100 Subject: ipcs: make individual shared memory id printing to use /proc And reindent the print_shm() function. Signed-off-by: Sami Kerola Signed-off-by: Karel Zak --- sys-utils/ipcs.c | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) (limited to 'sys-utils/ipcs.c') diff --git a/sys-utils/ipcs.c b/sys-utils/ipcs.c index d0ad42fcd..4945d8dcc 100644 --- a/sys-utils/ipcs.c +++ b/sys-utils/ipcs.c @@ -32,10 +32,10 @@ #define PID 5 static void do_shm (char format); +static void print_shm (int id); void do_sem (char format); void do_msg (char format); -void print_shm (int id); void print_msg (int id); void print_sem (int id); @@ -544,29 +544,32 @@ void do_msg (char format) return; } -void print_shm (int shmid) +static void print_shm(int shmid) { - struct shmid_ds shmds; - struct ipc_perm *ipcp = &shmds.shm_perm; + struct shm_data *shmdata; - if (shmctl (shmid, IPC_STAT, &shmds) == -1) - err(EXIT_FAILURE, _("shmctl failed")); + if (ipc_shm_get_info(shmid, &shmdata) < 1) { + warnx(_("id %d not found"), shmid); + return; + } - printf (_("\nShared memory Segment shmid=%d\n"), shmid); - printf (_("uid=%u\tgid=%u\tcuid=%u\tcgid=%u\n"), - ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid); - printf (_("mode=%#o\taccess_perms=%#o\n"), - ipcp->mode, ipcp->mode & 0777); - printf (_("bytes=%lu\tlpid=%d\tcpid=%d\tnattch=%ld\n"), - (unsigned long) shmds.shm_segsz, shmds.shm_lpid, shmds.shm_cpid, - (long) shmds.shm_nattch); - printf (_("att_time=%-26.24s\n"), - shmds.shm_atime ? ctime (&shmds.shm_atime) : _("Not set")); - printf (_("det_time=%-26.24s\n"), - shmds.shm_dtime ? ctime (&shmds.shm_dtime) : _("Not set")); - printf (_("change_time=%-26.24s\n"), ctime (&shmds.shm_ctime)); - printf ("\n"); - return; + printf(_("\nShared memory Segment shmid=%d\n"), shmid); + printf(_("uid=%u\tgid=%u\tcuid=%u\tcgid=%u\n"), + shmdata->shm_perm.uid, shmdata->shm_perm.uid, + shmdata->shm_perm.cuid, shmdata->shm_perm.cgid); + printf(_("mode=%#o\taccess_perms=%#o\n"), shmdata->shm_perm.mode, + shmdata->shm_perm.mode & 0777); + printf(_("bytes=%ju\tlpid=%u\tcpid=%u\tnattch=%jd\n"), + shmdata->shm_segsz, shmdata->shm_lprid, shmdata->shm_cprid, + shmdata->shm_nattch); + printf(_("att_time=%-26.24s\n"), + shmdata->shm_atim ? ctime(&(shmdata->shm_atim)) : _("Not set")); + printf(_("det_time=%-26.24s\n"), + shmdata->shm_dtim ? ctime(&shmdata->shm_dtim) : _("Not set")); + printf(_("change_time=%-26.24s\n"), ctime(&shmdata->shm_ctim)); + printf("\n"); + + ipc_shm_free_info(shmdata); } -- cgit v1.2.3-55-g7522