We do not typically document the historic usage. However, in this
case we might make an exception since the old and new syntax are
semantically different (absolute vs. increment). I've adapted your
diff as follows.
- todd
Index: renice.c
===================================================================
RCS file: /cvs/src/usr.bin/renice/renice.c,v
retrieving revision 1.16
diff -u -r1.16 renice.c
--- renice.c 15 Nov 2013 22:20:04 -0000 1.16
+++ renice.c 20 Mar 2015 16:29:05 -0000
@@ -37,7 +37,7 @@
};
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,10 +46,9 @@
struct renice_param *params, *p;
struct passwd *pw;
int ch, type = PRIO_PROCESS;
- int nflag = 0, pri = 0;
+ int absolute = 0, nflag = 0, pri = 0;
char *ep, *idstr;
const char *errstr;
- long l;
if (argc < 3)
usage();
@@ -61,10 +60,15 @@
/* Backwards compatibility: first arg may be priority. */
if (isdigit((unsigned char)argv[1][0]) ||
- (argv[1][0] == '-' && isdigit((unsigned char)argv[1][1]))) {
- argv[0] = "-n";
- argc++;
- argv--;
+ ((argv[1][0] == '+' || argv[1][0] == '-') &&
+ isdigit((unsigned char)argv[1][1]))) {
+ pri = (int)strtol(argv[1], &ep, 10);
+ if (*ep != '\0' || ep == argv[1]) {
+ warnx("invalid priority %s", argv[1]);
+ usage();
+ }
+ absolute = 1;
+ optind = 2;
}
/*
@@ -79,13 +83,15 @@
idstr = optarg;
break;
case 'n':
- l = strtol(optarg, &ep, 10);
+ if (absolute) {
+ warnx("-n not allowed with historic
priority setting");
+ usage();
+ }
+ pri = (int)strtol(optarg, &ep, 10);
if (*ep != '\0' || ep == optarg) {
warnx("invalid increment %s", optarg);
usage();
}
- pri = l > PRIO_MAX ? PRIO_MAX :
- l < PRIO_MIN ? PRIO_MIN : (int)l;
/* Set priority for previous entries? */
if (!nflag) {
@@ -135,15 +141,15 @@
}
p++;
}
- if (!nflag)
+ if (!nflag && !absolute)
usage();
- exit(renice(params, p));
+ exit(renice(params, p, absolute));
}
static int
-renice(struct renice_param *p, struct renice_param *end)
+renice(struct renice_param *p, struct renice_param *end, int absolute)
{
- int old, errors = 0;
+ int new, old, errors = 0;
for (; p < end; p++) {
errno = 0;
@@ -153,13 +159,17 @@
errors++;
continue;
}
- if (setpriority(p->type, p->id, p->pri) == -1) {
+ if (!absolute)
+ p->pri += old;
+ new = p->pri > PRIO_MAX ? PRIO_MAX :
+ p->pri < PRIO_MIN ? PRIO_MIN : p->pri;
+ if (setpriority(p->type, p->id, new) == -1) {
warn("setpriority: %d", p->id);
errors++;
continue;
}
printf("%d: old priority %d, new priority %d\n",
- p->id, old, p->pri);
+ p->id, old, new);
}
return (errors);
}