Mercurial > hg > toybox
annotate toys/posix/renice.c @ 1775:57f2a26fa92c draft toast
To ensure that toybox can be installed alongside busybox without
confusing update-alternatives, the paths of the links installed by toybox should
match those installed by busybox. This is accomplished by changing the flags
of a few tools within toybox.
author | Paul Barker <paul@paulbarker.me.uk> |
---|---|
date | Sat, 04 Apr 2015 11:58:06 -0500 |
parents | 53a9bcb938f0 |
children |
rev | line source |
---|---|
977 | 1 /* renice.c - renice process |
2 * | |
3 * Copyright 2013 CE Strake <strake888 at gmail.com> | |
4 * | |
979
53a9bcb938f0
Move renice from pending to posix, default y, fix link to standard.
Rob Landley <rob@landley.net>
parents:
978
diff
changeset
|
5 * See http://pubs.opengroup.org/onlinepubs/9699919799/utilities/renice.html |
977 | 6 |
1775
57f2a26fa92c
To ensure that toybox can be installed alongside busybox without
Paul Barker <paul@paulbarker.me.uk>
parents:
979
diff
changeset
|
7 USE_RENICE(NEWTOY(renice, "<1gpun#|", TOYFLAG_USR|TOYFLAG_BIN)) |
977 | 8 |
9 config RENICE | |
10 bool "renice" | |
979
53a9bcb938f0
Move renice from pending to posix, default y, fix link to standard.
Rob Landley <rob@landley.net>
parents:
978
diff
changeset
|
11 default y |
977 | 12 help |
13 usage: renice [-gpu] -n increment ID ... | |
14 */ | |
15 | |
16 #define FOR_renice | |
17 #include "toys.h" | |
18 | |
19 GLOBALS( | |
20 long nArgu; | |
21 ) | |
22 | |
978
6d3c39cb8a9d
Cleanup renice and implement '|' (required option) in argument parsing.
Rob Landley <rob@landley.net>
parents:
977
diff
changeset
|
23 void renice_main(void) { |
6d3c39cb8a9d
Cleanup renice and implement '|' (required option) in argument parsing.
Rob Landley <rob@landley.net>
parents:
977
diff
changeset
|
24 int which = (toys.optflags & FLAG_g) ? PRIO_PGRP : |
6d3c39cb8a9d
Cleanup renice and implement '|' (required option) in argument parsing.
Rob Landley <rob@landley.net>
parents:
977
diff
changeset
|
25 ((toys.optflags & FLAG_u) ? PRIO_USER : PRIO_PROCESS); |
6d3c39cb8a9d
Cleanup renice and implement '|' (required option) in argument parsing.
Rob Landley <rob@landley.net>
parents:
977
diff
changeset
|
26 char **arg; |
977 | 27 |
978
6d3c39cb8a9d
Cleanup renice and implement '|' (required option) in argument parsing.
Rob Landley <rob@landley.net>
parents:
977
diff
changeset
|
28 for (arg = toys.optargs; *arg; arg++) { |
6d3c39cb8a9d
Cleanup renice and implement '|' (required option) in argument parsing.
Rob Landley <rob@landley.net>
parents:
977
diff
changeset
|
29 char *s = *arg; |
6d3c39cb8a9d
Cleanup renice and implement '|' (required option) in argument parsing.
Rob Landley <rob@landley.net>
parents:
977
diff
changeset
|
30 int id = -1; |
977 | 31 |
978
6d3c39cb8a9d
Cleanup renice and implement '|' (required option) in argument parsing.
Rob Landley <rob@landley.net>
parents:
977
diff
changeset
|
32 if (toys.optflags & FLAG_u) { |
6d3c39cb8a9d
Cleanup renice and implement '|' (required option) in argument parsing.
Rob Landley <rob@landley.net>
parents:
977
diff
changeset
|
33 struct passwd *p = getpwnam(s); |
6d3c39cb8a9d
Cleanup renice and implement '|' (required option) in argument parsing.
Rob Landley <rob@landley.net>
parents:
977
diff
changeset
|
34 if (p) id = p->pw_uid; |
6d3c39cb8a9d
Cleanup renice and implement '|' (required option) in argument parsing.
Rob Landley <rob@landley.net>
parents:
977
diff
changeset
|
35 } else { |
6d3c39cb8a9d
Cleanup renice and implement '|' (required option) in argument parsing.
Rob Landley <rob@landley.net>
parents:
977
diff
changeset
|
36 id = strtol(s, &s, 10); |
6d3c39cb8a9d
Cleanup renice and implement '|' (required option) in argument parsing.
Rob Landley <rob@landley.net>
parents:
977
diff
changeset
|
37 if (*s) id = -1; |
6d3c39cb8a9d
Cleanup renice and implement '|' (required option) in argument parsing.
Rob Landley <rob@landley.net>
parents:
977
diff
changeset
|
38 } |
977 | 39 |
978
6d3c39cb8a9d
Cleanup renice and implement '|' (required option) in argument parsing.
Rob Landley <rob@landley.net>
parents:
977
diff
changeset
|
40 if (id < 0) { |
6d3c39cb8a9d
Cleanup renice and implement '|' (required option) in argument parsing.
Rob Landley <rob@landley.net>
parents:
977
diff
changeset
|
41 error_msg("bad '%s'", *arg); |
977 | 42 continue; |
43 } | |
44 | |
978
6d3c39cb8a9d
Cleanup renice and implement '|' (required option) in argument parsing.
Rob Landley <rob@landley.net>
parents:
977
diff
changeset
|
45 if (setpriority(which, id, getpriority(which, id)+TT.nArgu) < 0) |
6d3c39cb8a9d
Cleanup renice and implement '|' (required option) in argument parsing.
Rob Landley <rob@landley.net>
parents:
977
diff
changeset
|
46 perror_msg("setpriority %d", id); |
977 | 47 } |
48 } |