1 /* Copyright (C) 1994, 1995, 1997 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 Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 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 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
20 #include <hurd/resource.h>
22 /* Set the priority of all processes specified by WHICH and WHO
23 to PRIO. Returns 0 on success, -1 on errors. */
25 setpriority (enum __priority_which which
, int who
, int prio
)
28 error_t pidloser
, priloser
;
29 unsigned int npids
, ntasks
, nwin
, nperm
, nacces
;
31 error_t
setonepriority (pid_t pid
, struct procinfo
*pi
)
34 error_t piderr
= __USEPORT (PROC
, __proc_pid2task (port
, pid
, &task
));
40 if (piderr
&& piderr
!= EPERM
)
47 prierr
= __task_priority (task
, NICE_TO_MACH_PRIORITY (prio
), 1);
48 __mach_port_deallocate (__mach_task_self (), task
);
57 case KERN_INVALID_ARGUMENT
: /* Task died. */
68 npids
= ntasks
= nwin
= nperm
= nacces
= 0;
69 pidloser
= priloser
= 0;
70 err
= _hurd_priority_which_map (which
, who
, setonepriority
, 0);
72 if (!err
&& npids
== 0)
73 /* No error, but no pids found. */
75 else if (nperm
== npids
)
76 /* Got EPERM from proc_task2pid for every process. */
78 else if (nacces
== ntasks
)
79 /* Got KERN_FAILURE from task_priority for every task. */
82 err
= pidloser
?: priloser
;
84 return err
? __hurd_fail (err
) : 0;