1 /* Support code for dealing with priorities in the Hurd.
2 Copyright (C) 1994,95,96,97,99 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 not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
21 #include <hurd/resource.h>
26 _hurd_priority_which_map (enum __priority_which which
, int who
,
27 error_t (*function
) (pid_t
, struct procinfo
*),
30 mach_msg_type_number_t npids
= 64, i
;
31 pid_t pidbuf
[npids
], *pids
= pidbuf
;
34 int pibuf
[sizeof *pip
+ 5 * sizeof (pip
->threadinfos
[0])], *pi
= pibuf
;
35 mach_msg_type_number_t pisize
= sizeof (pibuf
) / sizeof (int);
43 err
= (*function
) (who
?: getpid (), 0); /* XXX special-case self? */
47 err
= __USEPORT (PROC
, __proc_getpgrppids (port
, who
, &pids
, &npids
));
48 for (i
= 0; !err
&& i
< npids
; ++i
)
49 err
= (*function
) (pids
[i
], 0);
55 err
= __USEPORT (PROC
, __proc_getallpids (port
, &pids
, &npids
));
56 for (i
= 0; !err
&& i
< npids
; ++i
)
58 /* Get procinfo to check the owner. */
60 mach_msg_type_number_t oldpisize
= pisize
;
63 err
= __USEPORT (PROC
, __proc_getprocinfo (port
, pids
[i
],
69 if (twsz
) /* Gratuitous. */
71 if (pi
!= oldpi
&& oldpi
!= pibuf
)
72 /* Old buffer from last call was not reused; free it. */
73 __munmap (oldpi
, oldpisize
* sizeof pi
[0]);
75 pip
= (struct procinfo
*) pi
;
76 if (pip
->owner
== (uid_t
) who
)
77 err
= (*function
) (pids
[i
], pip
);
84 __munmap (pids
, npids
* sizeof pids
[0]);
86 __munmap (pi
, pisize
* sizeof pi
[0]);