]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
rename: add getpriority() message lookup table
authorSami Kerola <kerolasa@iki.fi>
Fri, 5 Sep 2014 23:16:05 +0000 (00:16 +0100)
committerSami Kerola <kerolasa@iki.fi>
Fri, 19 Sep 2014 18:31:13 +0000 (19:31 +0100)
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
sys-utils/renice.c

index a123ed15f37c8ab147dec3b33cf95809f8140be0..994c9ded41739a89b5fd478802f75a777e89b299 100644 (file)
 #include "c.h"
 #include "closestream.h"
 
+const char *idtype[] = {
+       [PRIO_PROCESS]  = N_("process ID"),
+       [PRIO_PGRP]     = N_("process group ID"),
+       [PRIO_USER]     = N_("user ID"),
+};
+
 static void __attribute__((__noreturn__)) usage(FILE *out)
 {
        fputs(USAGE_HEADER, out);
@@ -67,36 +73,31 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
        exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
 }
 
-static int getprio(const int which, const int who, const char *idtype, int *prio)
+static int getprio(const int which, const int who, int *prio)
 {
        errno = 0;
        *prio = getpriority(which, who);
        if (*prio == -1 && errno) {
-               warn(_("failed to get priority for %d (%s)"), who, idtype);
+               warn(_("failed to get priority for %d (%s)"), who, idtype[which]);
                return -errno;
        }
        return 0;
 }
 
-static int donice(int which, int who, int prio)
+static int donice(const int which, const int who, const int prio)
 {
        int oldprio, newprio;
-       const char *idtype = _("process ID");
 
-       if (which == PRIO_USER)
-               idtype = _("user ID");
-       else if (which == PRIO_PGRP)
-               idtype = _("process group ID");
-       if (getprio(which, who, idtype, &oldprio) != 0)
+       if (getprio(which, who, &oldprio) != 0)
                return 1;
        if (setpriority(which, who, prio) < 0) {
-               warn(_("failed to set priority for %d (%s)"), who, idtype);
+               warn(_("failed to set priority for %d (%s)"), who, idtype[which]);
                return 1;
        }
-       if (getprio(which, who, idtype, &newprio) != 0)
+       if (getprio(which, who, &newprio) != 0)
                return 1;
        printf(_("%d (%s) old priority %d, new priority %d\n"),
-              who, idtype, oldprio, newprio);
+              who, idtype[which], oldprio, newprio);
        return 0;
 }
 
@@ -174,7 +175,7 @@ int main(int argc, char **argv)
                } else {
                        who = strtol(*argv, &endptr, 10);
                        if (who < 0 || *endptr) {
-                               warnx(_("bad value %s"), *argv);
+                               warnx(_("bad %s value: %s"), idtype[which], *argv);
                                errs = 1;
                                continue;
                        }