]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
renice: fix numeric uid argument parsing
authorSami Kerola <kerolasa@iki.fi>
Fri, 5 Sep 2014 22:54:17 +0000 (23:54 +0100)
committerSami Kerola <kerolasa@iki.fi>
Fri, 19 Sep 2014 18:31:13 +0000 (19:31 +0100)
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

index d83fc4a17ac36d9ea7b7bc0d9edbb3cc847b60d2..a123ed15f37c8ab147dec3b33cf95809f8140be0 100644 (file)
@@ -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;
 }
-