Bump to version 1.22.1
[platform/upstream/busybox.git] / procps / renice.c
index 08e0dc2..77f400a 100644 (file)
@@ -4,7 +4,7 @@
  *
  * Copyright (C) 2005  Manuel Novoa III  <mjn3@codepoet.org>
  *
- * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
+ * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  */
 
 /* Notes:
  *   following IDs (if any).  Multiple switches are allowed.
  */
 
-#include "busybox.h"
+//usage:#define renice_trivial_usage
+//usage:       "{{-n INCREMENT} | PRIORITY} [[-p | -g | -u] ID...]"
+//usage:#define renice_full_usage "\n\n"
+//usage:       "Change scheduling priority for a running process\n"
+//usage:     "\n       -n      Adjust current nice value (smaller is faster)"
+//usage:     "\n       -p      Process id(s) (default)"
+//usage:     "\n       -g      Process group id(s)"
+//usage:     "\n       -u      Process user name(s) and/or id(s)"
+
+#include "libbb.h"
 #include <sys/resource.h>
 
 void BUG_bad_PRIO_PROCESS(void);
 void BUG_bad_PRIO_PGRP(void);
 void BUG_bad_PRIO_USER(void);
 
-int renice_main(int argc, char **argv)
+int renice_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
+int renice_main(int argc UNUSED_PARAM, char **argv)
 {
-       static const char Xetpriority_msg[] = "%cetpriority";
+       static const char Xetpriority_msg[] ALIGN1 = "%cetpriority";
 
        int retval = EXIT_SUCCESS;
-       int which = PRIO_PROCESS;       /* Default 'which' value. */
+       int which = PRIO_PROCESS;  /* Default 'which' value. */
        int use_relative = 0;
        int adjustment, new_priority;
        unsigned who;
@@ -56,7 +66,7 @@ int renice_main(int argc, char **argv)
                        arg += 2;
        }
 
-       if (!arg) {                             /* No args?  Then show usage. */
+       if (!arg) {  /* No args?  Then show usage. */
                bb_show_usage();
        }
 
@@ -66,8 +76,9 @@ int renice_main(int argc, char **argv)
        while ((arg = *++argv) != NULL) {
                /* Check for a mode switch. */
                if (arg[0] == '-' && arg[1]) {
-                       static const char opts[]
-                               = { 'p', 'g', 'u', 0, PRIO_PROCESS, PRIO_PGRP, PRIO_USER };
+                       static const char opts[] ALIGN1 = {
+                               'p', 'g', 'u', 0, PRIO_PROCESS, PRIO_PGRP, PRIO_USER
+                       };
                        const char *p = strchr(opts, arg[1]);
                        if (p) {
                                which = p[4];
@@ -82,14 +93,14 @@ int renice_main(int argc, char **argv)
                        struct passwd *p;
                        p = getpwnam(arg);
                        if (!p) {
-                               bb_error_msg("unknown user: %s", arg);
+                               bb_error_msg("unknown user %s", arg);
                                goto HAD_ERROR;
                        }
                        who = p->pw_uid;
                } else {
                        who = bb_strtou(arg, NULL, 10);
                        if (errno) {
-                               bb_error_msg("bad value: %s", arg);
+                               bb_error_msg("invalid number '%s'", arg);
                                goto HAD_ERROR;
                        }
                }
@@ -98,7 +109,7 @@ int renice_main(int argc, char **argv)
                if (use_relative) {
                        int old_priority;
 
-                       errno = 0;       /* Needed for getpriority error detection. */
+                       errno = 0;  /* Needed for getpriority error detection. */
                        old_priority = getpriority(which, who);
                        if (errno) {
                                bb_perror_msg(Xetpriority_msg, 'g');