From: Davidlohr Bueso <dave@gnu.org>
To: Karel Zak <kzak@redhat.com>
Cc: kerolasa@gmail.com, util-linux <util-linux@vger.kernel.org>
Subject: Re: [pull] some sys-utils improvements
Date: Wed, 14 Sep 2011 14:04:45 -0300 [thread overview]
Message-ID: <1316019885.2605.1.camel@offbook> (raw)
In-Reply-To: <20110914163506.GC1829@nb.net.home>
On Wed, 2011-09-14 at 18:35 +0200, Karel Zak wrote:
> On Wed, Sep 14, 2011 at 10:21:53AM -0300, Davidlohr Bueso wrote:
> > On Tue, 2011-09-13 at 23:13 +0200, Sami Kerola wrote:
> > Please try the following patch, it fixed it for me. In the case when the
> > errors were shown, the msgctl(2) was returning 0 (success), so errno
> > shouldn't be checked. Remember, this isn't reseted afterwards, so we are
> > running into bogus messages (the msgid's are being correctly deleted).
> >
> > Thanks,
> > Davidlohr
> >
> > From 952d6100c28505005c0a335e3e64f384bd941859 Mon Sep 17 00:00:00 2001
> > From: Davidlohr Bueso <dave@gnu.org>
> > Date: Wed, 14 Sep 2011 10:17:15 -0300
> > Subject: [PATCH] ipcrm: check IPC syscalls
> >
> > It's not enough to check errno for errors as the variable is not reset, we also need to check the last syscall return value to verify a problem.
> > This addresses bogus msgqueue errors when deleting keys.
> >
> > Signed-off-by: Davidlohr Bueso <dave@gnu.org>
> > ---
> > sys-utils/ipcrm.c | 9 +++++----
> > 1 files changed, 5 insertions(+), 4 deletions(-)
> >
> > diff --git a/sys-utils/ipcrm.c b/sys-utils/ipcrm.c
> > index a8d6623..c794cbe 100644
> > --- a/sys-utils/ipcrm.c
> > +++ b/sys-utils/ipcrm.c
> > @@ -65,6 +65,7 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out)
> >
> > int remove_id(int type, int iskey, int id)
> > {
> > + int ret;
> > char *errmsg;
> > /* needed to delete semaphores */
> > union semun arg;
> > @@ -75,24 +76,24 @@ int remove_id(int type, int iskey, int id)
> > case SHM:
> > if (verbose)
> > printf(_("removing shared memory segment id `%d'\n"), id);
> > - shmctl(id, IPC_RMID, NULL);
> > + ret = shmctl(id, IPC_RMID, NULL);
> > break;
> > case MSG:
> > if (verbose)
> > printf(_("removing message queue id `%d'\n"), id);
> > - msgctl(id, IPC_RMID, NULL);
> > + ret = msgctl(id, IPC_RMID, NULL);
> > break;
> > case SEM:
> > if (verbose)
> > printf(_("removing semaphore id `%d'\n"), id);
> > - semctl(id, 0, IPC_RMID, arg);
> > + ret = semctl(id, 0, IPC_RMID, arg);
> > break;
> > default:
> > errx(EXIT_FAILURE, "impossible occurred");
> > }
> >
> > /* how did the removal go? */
> > - switch (errno) {
> > + switch (errno && ret) {
>
> so true/false only ... why we need the "case EACCES" (etc.)?
>
> > case 0:
> > return 0;
> > case EACCES:
>
> why we cannot use:
>
> if (ret < 0)
> switch(errno) {
> case EACCES:
> ...
> break;
>
> ....
> }
Well, yes, the case 0 didn't make much sense, otherwise I don't really
care how we evaluate ret/errno. Is the below patch ok with you?
From: Davidlohr Bueso <dave@gnu.org>
Date: Wed, 14 Sep 2011 14:02:15 -0300
Subject: [PATCH] ipcrm: check IPC syscalls
It's not enough to check errno for errors as the variable is not reset, we also need to check the last syscall return value to verify a problem.
This addresses bogus msgqueue errors when deleting keys.
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
---
sys-utils/ipcrm.c | 51 ++++++++++++++++++++++++++-------------------------
1 files changed, 26 insertions(+), 25 deletions(-)
diff --git a/sys-utils/ipcrm.c b/sys-utils/ipcrm.c
index a8d6623..a176fc7 100644
--- a/sys-utils/ipcrm.c
+++ b/sys-utils/ipcrm.c
@@ -65,6 +65,7 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out)
int remove_id(int type, int iskey, int id)
{
+ int ret;
char *errmsg;
/* needed to delete semaphores */
union semun arg;
@@ -75,46 +76,46 @@ int remove_id(int type, int iskey, int id)
case SHM:
if (verbose)
printf(_("removing shared memory segment id `%d'\n"), id);
- shmctl(id, IPC_RMID, NULL);
+ ret = shmctl(id, IPC_RMID, NULL);
break;
case MSG:
if (verbose)
printf(_("removing message queue id `%d'\n"), id);
- msgctl(id, IPC_RMID, NULL);
+ ret = msgctl(id, IPC_RMID, NULL);
break;
case SEM:
if (verbose)
printf(_("removing semaphore id `%d'\n"), id);
- semctl(id, 0, IPC_RMID, arg);
+ ret = semctl(id, 0, IPC_RMID, arg);
break;
default:
errx(EXIT_FAILURE, "impossible occurred");
}
/* how did the removal go? */
- switch (errno) {
- case 0:
- return 0;
- case EACCES:
- case EPERM:
- errmsg = iskey ? _("permission denied for key")
- : _("permission denied for id");
- break;
- case EINVAL:
- errmsg = iskey ? _("invalid key")
- : _("invalid id");
- break;
- case EIDRM:
- errmsg = iskey ? _("already removed key")
- : _("already removed id");
- break;
- default:
- if (iskey)
- err(EXIT_FAILURE, _("key failed"));
- else
- err(EXIT_FAILURE, _("id failed"));
+ if (ret < 0) {
+ switch (errno) {
+ case EACCES:
+ case EPERM:
+ errmsg = iskey ? _("permission denied for key")
+ : _("permission denied for id");
+ break;
+ case EINVAL:
+ errmsg = iskey ? _("invalid key")
+ : _("invalid id");
+ break;
+ case EIDRM:
+ errmsg = iskey ? _("already removed key")
+ : _("already removed id");
+ break;
+ default:
+ if (iskey)
+ err(EXIT_FAILURE, _("key failed"));
+ else
+ err(EXIT_FAILURE, _("id failed"));
+ }
+ warnx("%s (%d)", errmsg, id);
}
- warnx("%s (%d)", errmsg, id);
return 1;
}
--
1.7.4.1
next prev parent reply other threads:[~2011-09-14 17:04 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-13 21:13 [pull] some sys-utils improvements Sami Kerola
2011-09-14 13:21 ` Davidlohr Bueso
2011-09-14 16:35 ` Karel Zak
2011-09-14 17:04 ` Davidlohr Bueso [this message]
2011-09-14 17:46 ` Karel Zak
2011-09-17 13:10 ` Sami Kerola
2011-09-27 11:30 ` Karel Zak
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=1316019885.2605.1.camel@offbook \
--to=dave@gnu.org \
--cc=kerolasa@gmail.com \
--cc=kzak@redhat.com \
--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