summaryrefslogtreecommitdiffstats
path: root/sys-utils/renice.c
diff options
context:
space:
mode:
authorSami Kerola2014-09-06 00:06:28 +0200
committerSami Kerola2014-09-19 20:31:12 +0200
commit5ebcab664ef970a99b1a2f767bdb5c7983e934d1 (patch)
treeb88d65132849193436cec432f09f384aebb1ffaf /sys-utils/renice.c
parentMerge branch 'master' of https://github.com/stevenhoneyman/util-linux (diff)
downloadkernel-qcow2-util-linux-5ebcab664ef970a99b1a2f767bdb5c7983e934d1.tar.gz
kernel-qcow2-util-linux-5ebcab664ef970a99b1a2f767bdb5c7983e934d1.tar.xz
kernel-qcow2-util-linux-5ebcab664ef970a99b1a2f767bdb5c7983e934d1.zip
renice: reorder functions to avoid need of function prototype
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'sys-utils/renice.c')
-rw-r--r--sys-utils/renice.c65
1 files changed, 32 insertions, 33 deletions
diff --git a/sys-utils/renice.c b/sys-utils/renice.c
index c0378e1a5..5d643fb88 100644
--- a/sys-utils/renice.c
+++ b/sys-utils/renice.c
@@ -48,8 +48,6 @@
#include "c.h"
#include "closestream.h"
-static int donice(int,int,int);
-
static void __attribute__((__noreturn__)) usage(FILE *out)
{
fputs(_("\nUsage:\n"), out);
@@ -72,6 +70,38 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
}
+static int
+donice(int which, int who, 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");
+
+ errno = 0;
+ oldprio = getpriority(which, who);
+ if (oldprio == -1 && errno) {
+ warn(_("failed to get priority for %d (%s)"), who, idtype);
+ return 1;
+ }
+ if (setpriority(which, who, prio) < 0) {
+ warn(_("failed to set priority for %d (%s)"), who, idtype);
+ return 1;
+ }
+ errno = 0;
+ newprio = getpriority(which, who);
+ if (newprio == -1 && errno) {
+ warn(_("failed to get priority for %d (%s)"), who, idtype);
+ return 1;
+ }
+
+ printf(_("%d (%s) old priority %d, new priority %d\n"),
+ who, idtype, oldprio, newprio);
+ return 0;
+}
+
/*
* Change the priority (the nice value) of processes
* or groups of processes which are already running.
@@ -155,34 +185,3 @@ main(int argc, char **argv)
return errs != 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}
-static int
-donice(int which, int who, 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");
-
- errno = 0;
- oldprio = getpriority(which, who);
- if (oldprio == -1 && errno) {
- warn(_("failed to get priority for %d (%s)"), who, idtype);
- return 1;
- }
- if (setpriority(which, who, prio) < 0) {
- warn(_("failed to set priority for %d (%s)"), who, idtype);
- return 1;
- }
- errno = 0;
- newprio = getpriority(which, who);
- if (newprio == -1 && errno) {
- warn(_("failed to get priority for %d (%s)"), who, idtype);
- return 1;
- }
-
- printf(_("%d (%s) old priority %d, new priority %d\n"),
- who, idtype, oldprio, newprio);
- return 0;
-}