From: Karel Zak Date: Thu, 14 Aug 2008 09:40:08 +0000 (+0200) Subject: ionice: cleanup error messages, add NLS support X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5bd11d0d11ffad2d343040ac5c3eba433f4620dd;p=util-linux ionice: cleanup error messages, add NLS support Signed-off-by: Karel Zak --- diff --git a/schedutils/ionice.c b/schedutils/ionice.c index f5c02db5..395509bd 100644 --- a/schedutils/ionice.c +++ b/schedutils/ionice.c @@ -14,6 +14,9 @@ #include #include #include +#include + +#include "nls.h" static inline int ioprio_set(int which, int who, int ioprio) { @@ -42,17 +45,19 @@ enum { const char *to_prio[] = { "none", "realtime", "best-effort", "idle", }; -static void usage(void) +static void usage(int rc) { - printf("Usage: ionice [OPTIONS] [COMMAND [ARG]...]\n"); - printf("Sets or gets process io scheduling class and priority.\n"); - printf("\n\t-n\tClass data (typically 0-7, lower being higher prio)\n"); - printf("\t-c\tScheduling class\n"); - printf("\t\t\t1: realtime, 2: best-effort, 3: idle\n"); - printf("\t-p\tProcess pid\n"); - printf("\t-t\tIgnore failures to set priority, run command unconditionally\n"); - printf("\t-h\tThis help page\n"); - printf("\nJens Axboe (C) 2005\n"); + fprintf(stdout, _( + "\nionice - sets or gets process io scheduling class and priority.\n\n" + "Usage: ionice [OPTIONS] [COMMAND [ARG]...]\n\n" + " -n class data (0-7, lower being higher prio)\n" + " -c scheduling class\n" + " 1: realtime, 2: best-effort, 3: idle\n" + " -p process pid\n" + " -t ignore failures, run command unconditionally\n" + " -h this help\n\n")); + + exit(rc); } int main(int argc, char *argv[]) @@ -60,6 +65,10 @@ int main(int argc, char *argv[]) int ioprio = 4, set = 0, tolerant = 0, ioprio_class = IOPRIO_CLASS_BE; int c, pid = 0; + setlocale(LC_ALL, ""); + bindtextdomain(PACKAGE, LOCALEDIR); + textdomain(PACKAGE); + while ((c = getopt(argc, argv, "+n:c:p:th")) != EOF) { switch (c) { case 'n': @@ -77,9 +86,9 @@ int main(int argc, char *argv[]) tolerant = 1; break; case 'h': + usage(EXIT_SUCCESS); default: - usage(); - exit(EXIT_SUCCESS); + usage(EXIT_FAILURE); } } @@ -92,12 +101,11 @@ int main(int argc, char *argv[]) break; case IOPRIO_CLASS_IDLE: if (set & 1) - printf("Ignoring given class data for idle class\n"); + warnx(_("ignoring given class data for idle class")); ioprio = 7; break; default: - printf("bad prio class %d\n", ioprio_class); - exit(EXIT_FAILURE); + errx(EXIT_FAILURE, _("bad prio class %d"), ioprio_class); } if (!set) { @@ -106,10 +114,9 @@ int main(int argc, char *argv[]) ioprio = ioprio_get(IOPRIO_WHO_PROCESS, pid); - if (ioprio == -1) { - perror("ioprio_get"); - exit(EXIT_FAILURE); - } else { + if (ioprio == -1) + err(EXIT_FAILURE, _("ioprio_get failed")); + else { ioprio_class = ioprio >> IOPRIO_CLASS_SHIFT; if (ioprio_class != IOPRIO_CLASS_IDLE) { ioprio = ioprio & 0xff; @@ -119,17 +126,14 @@ int main(int argc, char *argv[]) } } else { if (ioprio_set(IOPRIO_WHO_PROCESS, pid, ioprio | ioprio_class << IOPRIO_CLASS_SHIFT) == -1) { - if (!tolerant) { - perror("ioprio_set"); - exit(EXIT_FAILURE); - } + if (!tolerant) + err(EXIT_FAILURE, _("ioprio_set failed")); } if (argv[optind]) { execvp(argv[optind], &argv[optind]); /* execvp should never return */ - perror("execvp"); - exit(EXIT_FAILURE); + err(EXIT_FAILURE, _("execvp failed")); } }