summaryrefslogtreecommitdiffstats
path: root/sys-utils/renice.c
diff options
context:
space:
mode:
authorSami Kerola2014-09-06 01:16:05 +0200
committerSami Kerola2014-09-19 20:31:13 +0200
commitce4030e4841a6eeba33bf65e1d9b4639fa3c6774 (patch)
treef1fd00d811e4772ae6377d83bbe37d9915f80dd5 /sys-utils/renice.c
parentrenice: fix numeric uid argument parsing (diff)
downloadkernel-qcow2-util-linux-ce4030e4841a6eeba33bf65e1d9b4639fa3c6774.tar.gz
kernel-qcow2-util-linux-ce4030e4841a6eeba33bf65e1d9b4639fa3c6774.tar.xz
kernel-qcow2-util-linux-ce4030e4841a6eeba33bf65e1d9b4639fa3c6774.zip
rename: add getpriority() message lookup table
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'sys-utils/renice.c')
-rw-r--r--sys-utils/renice.c27
1 files changed, 14 insertions, 13 deletions
diff --git a/sys-utils/renice.c b/sys-utils/renice.c
index a123ed15f..994c9ded4 100644
--- a/sys-utils/renice.c
+++ b/sys-utils/renice.c
@@ -48,6 +48,12 @@
#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;
}