1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16#define FOR_renice
17#include "toys.h"
18
19GLOBALS(
20 long n;
21)
22
23void renice_main(void) {
24 int which = (toys.optflags & FLAG_g) ? PRIO_PGRP :
25 ((toys.optflags & FLAG_u) ? PRIO_USER : PRIO_PROCESS);
26 char **arg;
27
28 for (arg = toys.optargs; *arg; arg++) {
29 char *s = *arg;
30 int id = -1;
31
32 if (toys.optflags & FLAG_u) {
33 struct passwd *p = getpwnam(s);
34 if (p) id = p->pw_uid;
35 } else {
36 id = strtol(s, &s, 10);
37 if (*s) id = -1;
38 }
39
40 if (id < 0) {
41 error_msg("bad '%s'", *arg);
42 continue;
43 }
44
45 if (setpriority(which, id, getpriority(which, id)+TT.n) < 0)
46 perror_msg("setpriority %d", id);
47 }
48}
49