Hello tech@,
this bugs me for a while now, so I'm sendig this diff in for consideration.
Brings renice(8) manpage and code and POSIX definition more in sync by:
- makeing the code increment the priority instead of setting it when -n is used.
- documenting the backwards compatible "set priority" option
- makeing "set priority" and -n mutually exclusive
- makeing "set priority" accept "+10" as a valid priority
Also this brings OpenBSD's renice more in sync with other BSDs.
Index: renice.8
===================================================================
RCS file: /cvs/src/usr.bin/renice/renice.8,v
retrieving revision 1.23
diff -u -p -r1.23 renice.8
--- renice.8 23 May 2014 06:40:57 -0000 1.23
+++ renice.8 20 Mar 2015 12:31:43 -0000
@@ -37,6 +37,20 @@
.Nd alter priority of running processes
.Sh SYNOPSIS
.Nm renice
+.Ar priority
+.Oo
+.Op Fl g
+.Ar pgrp ...
+.Oc
+.Oo
+.Op Fl p
+.Ar pid ...
+.Oc
+.Oo
+.Op Fl u
+.Ar user ...
+.Oc
+.Nm renice
.Fl n Ar increment
.Oo
.Op Fl g
@@ -131,7 +145,7 @@ utility is compliant with the
specification,
except the way in which processes are specified differs.
.Pp
-The historical behavior of passing the increment as the first
+The historical behavior of passing the priority as the first
argument is supported for backwards compatibility.
.Sh HISTORY
The
Index: renice.c
===================================================================
RCS file: /cvs/src/usr.bin/renice/renice.c,v
retrieving revision 1.16
diff -u -p -r1.16 renice.c
--- renice.c 15 Nov 2013 22:20:04 -0000 1.16
+++ renice.c 20 Mar 2015 12:39:55 -0000
@@ -37,7 +37,7 @@ struct renice_param {
};
int main(int, char **);
-static int renice(struct renice_param *, struct renice_param *);
+static int renice(struct renice_param *, struct renice_param *, int);
__dead void usage(void);
int
@@ -46,7 +46,7 @@ main(int argc, char **argv)
struct renice_param *params, *p;
struct passwd *pw;
int ch, type = PRIO_PROCESS;
- int nflag = 0, pri = 0;
+ int nflag = 0, pri = 0, set_pri_flag = 0;
char *ep, *idstr;
const char *errstr;
long l;
@@ -61,7 +61,9 @@ main(int argc, char **argv)
/* Backwards compatibility: first arg may be priority. */
if (isdigit((unsigned char)argv[1][0]) ||
- (argv[1][0] == '-' && isdigit((unsigned char)argv[1][1]))) {
+ (argv[1][0] == '-' && isdigit((unsigned char)argv[1][1])) ||
+ (argv[1][0] == '+' && isdigit((unsigned char)argv[1][1]))) {
+ set_pri_flag = 1;
argv[0] = "-n";
argc++;
argv--;
@@ -79,6 +81,10 @@ main(int argc, char **argv)
idstr = optarg;
break;
case 'n':
+ if (set_pri_flag && nflag) {
+ warnx("-n not allowed when setting
priority");
+ usage();
+ }
l = strtol(optarg, &ep, 10);
if (*ep != '\0' || ep == optarg) {
warnx("invalid increment %s", optarg);
@@ -137,11 +143,11 @@ main(int argc, char **argv)
}
if (!nflag)
usage();
- exit(renice(params, p));
+ exit(renice(params, p, set_pri_flag));
}
static int
-renice(struct renice_param *p, struct renice_param *end)
+renice(struct renice_param *p, struct renice_param *end, int set_priority_flag)
{
int old, errors = 0;
@@ -153,6 +159,12 @@ renice(struct renice_param *p, struct re
errors++;
continue;
}
+ if (!set_priority_flag) {
+ /* increment instead of set priority */
+ p->pri = old + p->pri;
+ p->pri = p->pri > PRIO_MAX ? PRIO_MAX :
+ p->pri < PRIO_MIN ? PRIO_MIN : p->pri;
+ }
if (setpriority(p->type, p->id, p->pri) == -1) {
warn("setpriority: %d", p->id);
errors++;
@@ -167,7 +179,9 @@ renice(struct renice_param *p, struct re
__dead void
usage(void)
{
- fprintf(stderr, "usage: renice -n increment [[-g] pgrp ...] "
+ fprintf(stderr, "usage: renice priority [[-g] pgrp ...] "
+ "[[-p] pid ...] [[-u] user ...]\n");
+ fprintf(stderr, " renice -n increment [[-g] pgrp ...] "
"[[-p] pid ...] [[-u] user ...]\n");
exit(1);
}