]> sourceware.org Git - glibc.git/blob - hurd/hurdprio.c
initial import
[glibc.git] / hurd / hurdprio.c
1 /* Support code for dealing with priorities in the Hurd.
2 Copyright (C) 1994 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
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.
9
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.
14
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. */
19
20 #include <hurd/resource.h>
21 #include <hurd.h>
22
23 error_t
24 _hurd_priority_which_map (enum __priority_which which, int who,
25 error_t (*function) (pid_t, struct procinfo *))
26 {
27 mach_msg_type_number_t npids = 64, i;
28 pid_t pidbuf[npids], *pids;
29 error_t err;
30 struct procinfo *pip;
31 int pibuf[sizeof *pip + 5 * sizeof (pip->threadinfos[0])], *pi = pibuf;
32 mach_msg_type_number_t pisize = sizeof (pibuf) / sizeof (int);
33
34 switch (which)
35 {
36 case PRIO_PROCESS:
37 npids = 1;
38 pids[0] = who;
39 err = 0;
40 break;
41
42 case PRIO_PGRP:
43 err = __USEPORT (PROC, __proc_getpgrppids (port, who, &pids, &npids));
44 break;
45
46 case PRIO_USER:
47 err = __USEPORT (PROC, __proc_getallpids (port, &pids, &npids));
48 break;
49
50 default:
51 return EINVAL;
52 }
53
54 for (i = 0; !err && i < npids; ++i)
55 {
56 if (which == PRIO_USER)
57 {
58 /* Get procinfo to check the owner. */
59 int *oldpi = pi;
60 mach_msg_type_number_t oldpisize = pisize;
61 if (err = __USEPORT (PROC, __proc_getprocinfo (port, pids[i],
62 &pi, &pisize)))
63 continue;
64 if (pi != oldpi && oldpi != pibuf)
65 /* Old buffer from last call was not reused; free it. */
66 __vm_deallocate (__mach_task_self (),
67 (vm_address_t) oldpi, oldpisize * sizeof pi[0]);
68
69 pip = (struct procinfo *) pi;
70 if (pip->owner != who)
71 continue;
72 }
73 else
74 pip = NULL;
75
76 err = (*function) (pids[i], pip);
77 }
78
79 if (pids != pidbuf)
80 __vm_deallocate (__mach_task_self (),
81 (vm_address_t) pids, npids * sizeof pids[0]);
82 if (pi != pibuf)
83 __vm_deallocate (__mach_task_self (),
84 (vm_address_t) pi, pisize * sizeof pi[0]);
85
86 return err;
87 }
This page took 0.042035 seconds and 5 git commands to generate.