From: Sami Kerola <kerolasa@iki.fi>
To: util-linux@vger.kernel.org
Cc: kerolasa@iki.fi
Subject: [PATCH 10/13] ipcs: make individual message queue id printing to use /proc
Date: Sun, 14 Oct 2012 21:22:22 +0100 [thread overview]
Message-ID: <1350246145-10600-11-git-send-email-kerolasa@iki.fi> (raw)
In-Reply-To: <1350246145-10600-1-git-send-email-kerolasa@iki.fi>
And reindent the print_msg() function.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
sys-utils/ipcs.c | 57 ++++++++++++++++++++++++++++++--------------------------
1 file changed, 31 insertions(+), 26 deletions(-)
diff --git a/sys-utils/ipcs.c b/sys-utils/ipcs.c
index cd3d14d..33759fe 100644
--- a/sys-utils/ipcs.c
+++ b/sys-utils/ipcs.c
@@ -403,6 +403,10 @@ static int msgctl_info_wrapper(int maxid, int id, struct msg_data **msgds,
&(msgdsp->q_rtime),
&(msgdsp->q_ctime)
);
+ if (-1 < id && id != msgdsp->msg_perm.id) {
+ i--;
+ continue;
+ }
if (id < 0) {
msgdsp->next = xmalloc(sizeof(struct msg_data));
msgdsp = msgdsp->next;
@@ -562,7 +566,7 @@ static void do_shm (char format, int use_proc);
static void do_sem (char format, int use_proc);
static void do_msg (char format, int use_proc);
static void print_shm (int id, int use_proc);
-void print_msg (int id);
+static void print_msg (int id, int use_proc);
void print_sem (int id);
static void __attribute__ ((__noreturn__)) usage(FILE * out)
@@ -671,7 +675,7 @@ int main (int argc, char **argv)
if (sem)
print_sem (id);
if (msg)
- print_msg (id);
+ print_msg (id, use_proc);
if (!shm && !sem && !msg )
usage (stderr);
} else {
@@ -1107,33 +1111,34 @@ static void print_shm(int shmid, int use_proc)
return;
}
-
-void print_msg (int msqid)
+static void print_msg(int msqid, int use_proc)
{
- struct msqid_ds buf;
- struct ipc_perm *ipcp = &buf.msg_perm;
+ struct msg_data *msgdata;
- if (msgctl (msqid, IPC_STAT, &buf) == -1)
- err(EXIT_FAILURE, _("msgctl failed"));
+ if (msgctl_info_wrapper(-1, msqid, &msgdata, use_proc) < 1) {
+ warnx(_("id %d not found"), msqid);
+ return;
+ }
- printf (_("\nMessage Queue msqid=%d\n"), msqid);
- printf (_("uid=%u\tgid=%u\tcuid=%u\tcgid=%u\tmode=%#o\n"),
- ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid, ipcp->mode);
- printf (_("cbytes=%ld\tqbytes=%ld\tqnum=%ld\tlspid=%d\tlrpid=%d\n"),
- /*
- * glibc-2.1.3 and earlier has unsigned short. glibc-2.1.91
- * has variation between unsigned short, unsigned long.
- * Austin has msgqnum_t (for msg_qbytes)
- */
- (long) buf.msg_cbytes, (long) buf.msg_qbytes,
- (long) buf.msg_qnum, buf.msg_lspid, buf.msg_lrpid);
- printf (_("send_time=%-26.24s\n"),
- buf.msg_stime ? ctime (&buf.msg_stime) : _("Not set"));
- printf (_("rcv_time=%-26.24s\n"),
- buf.msg_rtime ? ctime (&buf.msg_rtime) : _("Not set"));
- printf (_("change_time=%-26.24s\n"),
- buf.msg_ctime ? ctime (&buf.msg_ctime) : _("Not set"));
- printf ("\n");
+ printf(_("\nMessage Queue msqid=%d\n"), msqid);
+ printf(_("uid=%u\tgid=%u\tcuid=%u\tcgid=%u\tmode=%#o\n"),
+ msgdata->msg_perm.uid, msgdata->msg_perm.uid,
+ msgdata->msg_perm.cuid, msgdata->msg_perm.cgid,
+ msgdata->msg_perm.mode & 0777);
+ printf(_("cbytes=%ld\tqbytes=%ld\tqnum=%ld\tlspid=%d\tlrpid=%d\n"),
+ /* Old msqid_ds.msg_lqbytes is the same as
+ * msgdata->q_cbytes. See copy_msqid_to_user() from
+ * http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=ipc/msg.c */
+ msgdata->q_cbytes, msgdata->q_cbytes,
+ msgdata->q_qnum, msgdata->q_lspid, msgdata->q_lrpid);
+ printf(_("send_time=%-26.24s\n"),
+ msgdata->q_stime ? ctime(&msgdata->q_stime) : _("Not set"));
+ printf(_("rcv_time=%-26.24s\n"),
+ msgdata->q_rtime ? ctime(&msgdata->q_rtime) : _("Not set"));
+ printf(_("change_time=%-26.24s\n"),
+ msgdata->q_ctime ? ctime(&msgdata->q_ctime) : _("Not set"));
+ printf("\n");
+ free(msgdata);
return;
}
--
1.7.12.3
next prev parent reply other threads:[~2012-10-14 20:22 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-14 20:22 [PATCH 00/13] make ipcs to use proc Sami Kerola
2012-10-14 20:22 ` [PATCH 01/13] ipcs: add data structures to read state from /proc & /sys Sami Kerola
2012-10-14 20:22 ` [PATCH 02/13] ipcs: add /proc and /sys path definitions Sami Kerola
2012-11-05 16:43 ` Karel Zak
2012-10-14 20:22 ` [PATCH 03/13] ipcs: determine ipc limits from /proc Sami Kerola
2012-10-15 2:00 ` Mike Frysinger
2012-11-05 16:49 ` Karel Zak
2012-10-14 20:22 ` [PATCH 04/13] ipcs: add new permissions printing function Sami Kerola
2012-10-14 20:22 ` [PATCH 05/13] ipcs: read shared memory values from /proc Sami Kerola
2012-10-15 2:07 ` Mike Frysinger
2012-10-14 20:22 ` [PATCH 06/13] ipcs: read message queue " Sami Kerola
2012-10-14 20:22 ` [PATCH 07/13] ipsc: read semaphore " Sami Kerola
2012-10-14 20:22 ` [PATCH 08/13] ipcs: clean up permissions printing Sami Kerola
2012-10-14 20:22 ` [PATCH 09/13] ipcs: make individual shared memory id printing to use /proc Sami Kerola
2012-11-05 16:53 ` Karel Zak
2012-10-14 20:22 ` Sami Kerola [this message]
2012-10-14 20:22 ` [PATCH 11/13] ipcs: make individual semaphore " Sami Kerola
2012-10-14 20:22 ` [PATCH 12/13] ipcs: validate numeric user input Sami Kerola
2012-10-14 20:22 ` [PATCH 13/13] docs: update TODO Sami Kerola
[not found] ` <20121015153924.GL18377@x2.net.home>
2012-10-22 20:23 ` [PATCH 00/13] make ipcs to use proc Sami Kerola
2012-11-05 16:42 ` Karel Zak
2012-11-07 9:40 ` Sami Kerola
2012-11-07 10:01 ` Karel Zak
2012-11-11 23:01 ` Sami Kerola
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1350246145-10600-11-git-send-email-kerolasa@iki.fi \
--to=kerolasa@iki.fi \
--cc=util-linux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).