]> git.ipfire.org Git - thirdparty/util-linux.git/blobdiff - sys-utils/renice.c
libdisk: write sample output to stdout
[thirdparty/util-linux.git] / sys-utils / renice.c
index 100f6a5349a696cc61f230be90640b68c0b5e954..fbce39a1f8f7755853bc4f570aa4575e3a64b942 100644 (file)
 #include "c.h"
 #include "closestream.h"
 
-const char *idtype[] = {
+static 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)
+static void __attribute__((__noreturn__)) usage(void)
 {
+       FILE *out = stdout;
        fputs(USAGE_HEADER, out);
        fprintf(out,
              _(" %1$s [-n] <priority> [-p|--pid] <pid>...\n"
                " %1$s [-n] <priority>  -g|--pgrp <pgid>...\n"
                " %1$s [-n] <priority>  -u|--user <user>...\n"),
                program_invocation_short_name);
+
+       fputs(USAGE_SEPARATOR, out);
+       fputs(_("Alter the priority of running processes.\n"), out);
+
        fputs(USAGE_OPTIONS, out);
        fputs(_(" -n, --priority <num>   specify the nice increment value\n"), out);
        fputs(_(" -p, --pid <id>         interpret argument as process ID (default)\n"), out);
        fputs(_(" -g, --pgrp <id>        interpret argument as process group ID\n"), out);
-       fputs(_(" -u, --user <name|id>   interpret argument as username or user ID\n"), out);
+       fputs(_(" -u, --user <name>|<id> interpret argument as username or user ID\n"), out);
        fputs(USAGE_SEPARATOR, out);
-       fputs(USAGE_HELP, out);
-       fputs(USAGE_VERSION, out);
-       fprintf(out, USAGE_MAN_TAIL("renice(1)"));
-       exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+       printf(USAGE_HELP_OPTIONS(24));
+       printf(USAGE_MAN_TAIL("renice(1)"));
+       exit(EXIT_SUCCESS);
 }
 
 static int getprio(const int which, const int who, int *prio)
@@ -115,7 +119,7 @@ int main(int argc, char **argv)
        setlocale(LC_ALL, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
-       atexit(close_stdout);
+       close_stdout_atexit();
 
        argc--;
        argv++;
@@ -123,14 +127,12 @@ int main(int argc, char **argv)
        if (argc == 1) {
                if (strcmp(*argv, "-h") == 0 ||
                    strcmp(*argv, "--help") == 0)
-                       usage(stdout);
+                       usage();
 
                if (strcmp(*argv, "-v") == 0 ||
                    strcmp(*argv, "-V") == 0 ||
-                   strcmp(*argv, "--version") == 0) {
-                       printf(UTIL_LINUX_VERSION);
-                       return EXIT_SUCCESS;
-               }
+                   strcmp(*argv, "--version") == 0)
+                       print_version(EXIT_SUCCESS);
        }
 
        if (*argv && (strcmp(*argv, "-n") == 0 || strcmp(*argv, "--priority") == 0)) {
@@ -138,13 +140,16 @@ int main(int argc, char **argv)
                argv++;
        }
 
-       if (argc < 2)
-               usage(stderr);
+       if (argc < 2 || !*argv) {
+               warnx(_("not enough arguments"));
+               errtryhelp(EXIT_FAILURE);
+       }
 
        prio = strtol(*argv, &endptr, 10);
-       if (*endptr)
-               usage(stderr);
-
+       if (*endptr) {
+               warnx(_("invalid priority '%s'"), *argv);
+               errtryhelp(EXIT_FAILURE);
+       }
        argc--;
        argv++;
 
@@ -176,6 +181,8 @@ int main(int argc, char **argv)
                } else {
                        who = strtol(*argv, &endptr, 10);
                        if (who < 0 || *endptr) {
+                               /* TRANSLATORS: The first %s is one of the above
+                                * three ID names. Read: "bad value for %s: %s" */
                                warnx(_("bad %s value: %s"), idtype[which], *argv);
                                errs = 1;
                                continue;