1 /* Copyright (C) 1994-2015 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
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.
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
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
20 #include <hurd/resource.h>
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. */
27 __getpriority (enum __priority_which which
, id_t who
)
31 struct procinfo
*pip
; /* Just for sizeof. */
32 int pibuf
[sizeof *pip
+ 2 * sizeof (pip
->threadinfos
[0])], *pi
= pibuf
;
33 size_t pisize
= sizeof pibuf
/ sizeof pibuf
[0];
35 error_t
getonepriority (pid_t pid
, struct procinfo
*pip
)
42 size_t oldpisize
= pisize
;
45 int flags
= PI_FETCH_TASKINFO
;
46 onerr
= __USEPORT (PROC
, __proc_getprocinfo (port
, pid
, &flags
,
50 __vm_deallocate (__mach_task_self (), (vm_address_t
) tw
, twsz
);
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
;
57 #ifdef TASK_SCHED_TIMESHARE_INFO
58 if (!onerr
&& pip
->timeshare_base_info
.base_priority
> maxpri
)
59 maxpri
= pip
->timeshare_base_info
.base_priority
;
61 if (!onerr
&& pip
->taskinfo
.base_priority
> maxpri
)
62 maxpri
= pip
->taskinfo
.base_priority
;
68 err
= _hurd_priority_which_map (which
, who
,
69 getonepriority
, PI_FETCH_TASKINFO
);
72 __vm_deallocate (__mach_task_self (),
73 (vm_address_t
) pi
, pisize
* sizeof pi
[0]);
75 if (!err
&& maxpri
== INT_MIN
)
76 /* No error, but no pids found. */
80 return __hurd_fail (err
);
82 return MACH_PRIORITY_TO_NICE (maxpri
);
84 libc_hidden_def (__getpriority
)
85 weak_alias (__getpriority
, getpriority
)