1 /* Support code for dealing with priorities in the Hurd.
2 Copyright (C) 1994-2013 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 Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the 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 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
20 #include <hurd/resource.h>
25 _hurd_priority_which_map (enum __priority_which which
, int who
,
26 error_t (*function
) (pid_t
, struct procinfo
*),
29 mach_msg_type_number_t npids
= 64, i
;
30 pid_t pidbuf
[npids
], *pids
= pidbuf
;
33 int pibuf
[sizeof *pip
+ 5 * sizeof (pip
->threadinfos
[0])], *pi
= pibuf
;
34 mach_msg_type_number_t pisize
= sizeof (pibuf
) / sizeof (int);
42 err
= (*function
) (who
?: getpid (), 0); /* XXX special-case self? */
46 err
= __USEPORT (PROC
, __proc_getpgrppids (port
, who
, &pids
, &npids
));
47 for (i
= 0; !err
&& i
< npids
; ++i
)
48 err
= (*function
) (pids
[i
], 0);
54 err
= __USEPORT (PROC
, __proc_getallpids (port
, &pids
, &npids
));
55 for (i
= 0; !err
&& i
< npids
; ++i
)
57 /* Get procinfo to check the owner. */
59 mach_msg_type_number_t oldpisize
= pisize
;
62 err
= __USEPORT (PROC
, __proc_getprocinfo (port
, pids
[i
],
68 if (twsz
) /* Gratuitous. */
70 if (pi
!= oldpi
&& oldpi
!= pibuf
)
71 /* Old buffer from last call was not reused; free it. */
72 __munmap (oldpi
, oldpisize
* sizeof pi
[0]);
74 pip
= (struct procinfo
*) pi
;
75 if (pip
->owner
== (uid_t
) who
)
76 err
= (*function
) (pids
[i
], pip
);
83 __munmap (pids
, npids
* sizeof pids
[0]);
85 __munmap (pi
, pisize
* sizeof pi
[0]);