]>
Commit | Line | Data |
---|---|---|
f7a9f785 | 1 | /* Copyright (C) 1994-2016 Free Software Foundation, Inc. |
478b92f0 | 2 | This file is part of the GNU C Library. |
28f540f4 | 3 | |
478b92f0 | 4 | The GNU C Library is free software; you can redistribute it and/or |
41bdb6e2 AJ |
5 | modify it under the terms of the GNU Lesser General Public |
6 | License as published by the Free Software Foundation; either | |
7 | version 2.1 of the License, or (at your option) any later version. | |
28f540f4 | 8 | |
478b92f0 UD |
9 | The GNU C Library is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
41bdb6e2 | 12 | Lesser General Public License for more details. |
28f540f4 | 13 | |
41bdb6e2 | 14 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 PE |
15 | License along with the GNU C Library; if not, see |
16 | <http://www.gnu.org/licenses/>. */ | |
28f540f4 RM |
17 | |
18 | #include <limits.h> | |
19 | #include <hurd.h> | |
20 | #include <hurd/resource.h> | |
21 | ||
22 | /* Return the highest priority of any process specified by WHICH and WHO | |
23 | (see <sys/resource.h>); if WHO is zero, the current process, process group, | |
24 | or user (as specified by WHO) is used. A lower priority number means higher | |
25 | priority. Priorities range from PRIO_MIN to PRIO_MAX. */ | |
26 | int | |
c3621351 | 27 | __getpriority (enum __priority_which which, id_t who) |
28f540f4 RM |
28 | { |
29 | error_t err, onerr; | |
30 | int maxpri = INT_MIN; | |
31 | struct procinfo *pip; /* Just for sizeof. */ | |
32 | int pibuf[sizeof *pip + 2 * sizeof (pip->threadinfos[0])], *pi = pibuf; | |
b62b62ac | 33 | size_t pisize = sizeof pibuf / sizeof pibuf[0]; |
28f540f4 RM |
34 | |
35 | error_t getonepriority (pid_t pid, struct procinfo *pip) | |
36 | { | |
37 | if (pip) | |
38 | onerr = 0; | |
39 | else | |
40 | { | |
41 | int *oldpi = pi; | |
b62b62ac | 42 | size_t oldpisize = pisize; |
853f0eea RM |
43 | char *tw = 0; |
44 | size_t twsz = 0; | |
061c6526 MB |
45 | int flags = PI_FETCH_TASKINFO; |
46 | onerr = __USEPORT (PROC, __proc_getprocinfo (port, pid, &flags, | |
853f0eea RM |
47 | &pi, &pisize, |
48 | &tw, &twsz)); | |
49 | if (twsz) | |
e380bf62 | 50 | __vm_deallocate (__mach_task_self (), (vm_address_t) tw, twsz); |
28f540f4 RM |
51 | if (pi != oldpi && oldpi != pibuf) |
52 | /* Old buffer from last call was not reused; free it. */ | |
53 | __vm_deallocate (__mach_task_self (), | |
54 | (vm_address_t) oldpi, oldpisize * sizeof pi[0]); | |
55 | pip = (struct procinfo *) pi; | |
56 | } | |
9ce8b3c8 RM |
57 | #ifdef TASK_SCHED_TIMESHARE_INFO |
58 | if (!onerr && pip->timeshare_base_info.base_priority > maxpri) | |
59 | maxpri = pip->timeshare_base_info.base_priority; | |
60 | #else | |
28f540f4 RM |
61 | if (!onerr && pip->taskinfo.base_priority > maxpri) |
62 | maxpri = pip->taskinfo.base_priority; | |
9ce8b3c8 | 63 | #endif |
28f540f4 RM |
64 | return 0; |
65 | } | |
66 | ||
67 | onerr = 0; | |
80b55d32 RM |
68 | err = _hurd_priority_which_map (which, who, |
69 | getonepriority, PI_FETCH_TASKINFO); | |
28f540f4 RM |
70 | |
71 | if (pi != pibuf) | |
72 | __vm_deallocate (__mach_task_self (), | |
73 | (vm_address_t) pi, pisize * sizeof pi[0]); | |
74 | ||
75 | if (!err && maxpri == INT_MIN) | |
76 | /* No error, but no pids found. */ | |
77 | err = onerr ?: ESRCH; | |
78 | ||
79 | if (err) | |
80 | return __hurd_fail (err); | |
81 | ||
82 | return MACH_PRIORITY_TO_NICE (maxpri); | |
83 | } | |
c3621351 JM |
84 | libc_hidden_def (__getpriority) |
85 | weak_alias (__getpriority, getpriority) |