public inbox for util-linux@vger.kernel.org
 help / color / mirror / Atom feed
From: Sami Kerola <kerolasa@iki.fi>
To: Karel Zak <kzak@redhat.com>
Cc: util-linux@vger.kernel.org
Subject: Re: [PATCH 5/6] renice: fix numeric uid argument parsing
Date: Tue, 16 Sep 2014 21:17:54 +0100 (BST)	[thread overview]
Message-ID: <alpine.LNX.2.03.1409162114110.3712@kerolasa-home> (raw)
In-Reply-To: <20140912080354.GR21325@x2.net.home>

On Fri, 12 Sep 2014, Karel Zak wrote:

> On Sat, Sep 06, 2014 at 12:24:52PM +0100, Sami Kerola wrote:
>>  		if (which == PRIO_USER) {
>> -			register struct passwd *pwd = getpwnam(*argv);
>> +			struct passwd *pwd = getpwnam(*argv);
>>
>> -			if (pwd == NULL) {
>> -				warnx(_("unknown user %s"), *argv);
>> -				errs = 1;
>> -				continue;
>> +			if (pwd != NULL)
>> +				who = pwd->pw_uid;
>> +			else {
>> +				error_msg = _("unknown user %s");
>> +				goto numeric_pid;
>>  			}
>> -			who = pwd->pw_uid;
>>  		} else {
>> +			error_msg = _("bad value %s");
>> + numeric_pid:
>>  			who = strtol(*argv, &endptr, 10);
>>  			if (who < 0 || *endptr) {
>> -				warnx(_("bad value %s"), *argv);
>> +				warnx(error_msg, *argv);
>>  				errs = 1;
>>  				continue;
>>  			}
>
> The goto is unnecessary. Just set who = -1 by default.
>
>  who = -1;
>  if (which == PRIO_USER) {
>        ...
>        who = pwd->pw_uid;
>  }
>
>  if (who < 0) {
>        who = strtol(*argv, &endptr, 10);
>        ...
>        if (who < 0 || *endptr)
>            warnx(_("failed to parse %s argument"), idtype[which]);
>  }

Hi Karel,

Oh yes, I clearly over complicated the previous version. This ought to be 
a bit closer what one could consider acceptable.

--->8----
From: Sami Kerola <kerolasa@iki.fi>
Date: Fri, 5 Sep 2014 23:54:17 +0100
Subject: [PATCH 5/7] renice: fix numeric uid argument parsing

The following was inconflict with what usage() tells are valid option
arguments.

$ renice 1 -u 1000
renice: unknown user 1000
$ id
uid=1000(kerolasa) ...

Reviewed-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
  sys-utils/renice.c | 10 ++++++----
  1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/sys-utils/renice.c b/sys-utils/renice.c
index d83fc4a..a123ed1 100644
--- a/sys-utils/renice.c
+++ b/sys-utils/renice.c
@@ -160,14 +160,17 @@ int main(int argc, char **argv)
  			continue;
  		}
  		if (which == PRIO_USER) {
-			register struct passwd *pwd = getpwnam(*argv);
+			struct passwd *pwd = getpwnam(*argv);

-			if (pwd == NULL) {
+			if (pwd != NULL)
+				who = pwd->pw_uid;
+			else
+				who = strtol(*argv, &endptr, 10);
+			if (who < 0 || *endptr) {
  				warnx(_("unknown user %s"), *argv);
  				errs = 1;
  				continue;
  			}
-			who = pwd->pw_uid;
  		} else {
  			who = strtol(*argv, &endptr, 10);
  			if (who < 0 || *endptr) {
@@ -180,4 +183,3 @@ int main(int argc, char **argv)
  	}
  	return errs != 0 ? EXIT_FAILURE : EXIT_SUCCESS;
  }
-
-- 
2.1.0


  reply	other threads:[~2014-09-16 20:17 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-06 11:24 [PATCH 0/6] pull: renice changes Sami Kerola
2014-09-06 11:24 ` [PATCH 1/6] renice: reorder functions to avoid need of function prototype Sami Kerola
2014-09-06 11:24 ` [PATCH 2/6] rename: use usage and version print out macros Sami Kerola
2014-09-06 11:24 ` [PATCH 3/6] renice: disallow --priority <arg> without pid argument Sami Kerola
2014-09-06 11:24 ` [PATCH 4/6] renice: avoid having same lines of code twice Sami Kerola
2014-09-12  7:35   ` Karel Zak
2014-09-16 20:13     ` Sami Kerola
2014-09-06 11:24 ` [PATCH 5/6] renice: fix numeric uid argument parsing Sami Kerola
2014-09-12  8:03   ` Karel Zak
2014-09-16 20:17     ` Sami Kerola [this message]
2014-09-06 11:24 ` [PATCH 6/6] rename: add getpriority() message lookup table Sami Kerola
2014-09-16 20:21 ` [PATCH 0/6] pull: renice changes Sami Kerola
2014-09-17  7:57   ` Benno Schulenberg
2014-09-17 10:06     ` Sami Kerola
2014-09-22 12:48 ` 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=alpine.LNX.2.03.1409162114110.3712@kerolasa-home \
    --to=kerolasa@iki.fi \
    --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