1 /* Support code for dealing with priorities in the Hurd.
2 Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If
17 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
18 Cambridge, MA 02139, USA. */
20 #include <hurd/resource.h>
24 _hurd_priority_which_map (enum __priority_which which
, int who
,
25 error_t (*function
) (pid_t
, struct procinfo
*),
28 mach_msg_type_number_t npids
= 64, i
;
29 pid_t pidbuf
[npids
], *pids
;
32 int pibuf
[sizeof *pip
+ 5 * sizeof (pip
->threadinfos
[0])], *pi
= pibuf
;
33 mach_msg_type_number_t pisize
= sizeof (pibuf
) / sizeof (int);
44 err
= __USEPORT (PROC
, __proc_getpgrppids (port
, who
, &pids
, &npids
));
48 err
= __USEPORT (PROC
, __proc_getallpids (port
, &pids
, &npids
));
55 for (i
= 0; !err
&& i
< npids
; ++i
)
57 if (which
== PRIO_USER
)
59 /* Get procinfo to check the owner. */
61 mach_msg_type_number_t oldpisize
= pisize
;
64 if (err
= __USEPORT (PROC
, __proc_getprocinfo (port
, pids
[i
],
71 __vm_deallocate (__mach_task_self (), (vm_address_t
) tw
, twsz
);
72 if (pi
!= oldpi
&& oldpi
!= pibuf
)
73 /* Old buffer from last call was not reused; free it. */
74 __vm_deallocate (__mach_task_self (),
75 (vm_address_t
) oldpi
, oldpisize
* sizeof pi
[0]);
77 pip
= (struct procinfo
*) pi
;
78 if (pip
->owner
!= (uid_t
) who
)
84 err
= (*function
) (pids
[i
], pip
);
88 __vm_deallocate (__mach_task_self (),
89 (vm_address_t
) pids
, npids
* sizeof pids
[0]);
91 __vm_deallocate (__mach_task_self (),
92 (vm_address_t
) pi
, pisize
* sizeof pi
[0]);