1 /* Copyright (C) 1994-2017 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/>. */
19 #include <hurd/resource.h>
21 /* Set the priority of all processes specified by WHICH and WHO
22 to PRIO. Returns 0 on success, -1 on errors. */
24 __setpriority (enum __priority_which which
, id_t who
, int prio
)
27 error_t pidloser
, priloser
;
28 unsigned int npids
, ntasks
, nwin
, nperm
, nacces
;
30 error_t
setonepriority (pid_t pid
, struct procinfo
*pi
)
33 error_t piderr
= __USEPORT (PROC
, __proc_pid2task (port
, pid
, &task
));
39 if (piderr
&& piderr
!= EPERM
)
46 #ifdef POLICY_TIMESHARE_BASE_COUNT
48 /* XXX This assumes timeshare policy. */
49 struct policy_timeshare_base base
50 = { NICE_TO_MACH_PRIORITY (prio
) };
51 prierr
= __task_policy (task
, POLICY_TIMESHARE
,
52 (policy_base_t
) &base
,
53 POLICY_TIMESHARE_BASE_COUNT
,
57 prierr
= __task_priority (task
, NICE_TO_MACH_PRIORITY (prio
), 1);
59 __mach_port_deallocate (__mach_task_self (), task
);
68 case KERN_INVALID_ARGUMENT
: /* Task died. */
79 npids
= ntasks
= nwin
= nperm
= nacces
= 0;
80 pidloser
= priloser
= 0;
81 err
= _hurd_priority_which_map (which
, who
, setonepriority
, 0);
83 if (!err
&& npids
== 0)
84 /* No error, but no pids found. */
86 else if (nperm
== npids
)
87 /* Got EPERM from proc_task2pid for every process. */
89 else if (nacces
== ntasks
)
90 /* Got KERN_FAILURE from task_priority for every task. */
93 err
= pidloser
?: priloser
;
95 return err
? __hurd_fail (err
) : 0;
97 libc_hidden_def (__setpriority
)
98 weak_alias (__setpriority
, setpriority
)