(PAD): use return value of _IO_padn. (buffered_vfprintf): remove line buffer when...
[glibc.git] / hurd / hurdprio.c
blobd7beb3c97a02e6b4b31f6852d667299d352041f6
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.
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>
21 #include <hurd.h>
23 error_t
24 _hurd_priority_which_map (enum __priority_which which, int who,
25 error_t (*function) (pid_t, struct procinfo *))
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);
34 switch (which)
36 case PRIO_PROCESS:
37 npids = 1;
38 pids[0] = who;
39 err = 0;
40 break;
42 case PRIO_PGRP:
43 err = __USEPORT (PROC, __proc_getpgrppids (port, who, &pids, &npids));
44 break;
46 case PRIO_USER:
47 err = __USEPORT (PROC, __proc_getallpids (port, &pids, &npids));
48 break;
50 default:
51 return EINVAL;
54 for (i = 0; !err && i < npids; ++i)
56 if (which == PRIO_USER)
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]);
69 pip = (struct procinfo *) pi;
70 if (pip->owner != who)
71 continue;
73 else
74 pip = NULL;
76 err = (*function) (pids[i], pip);
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]);
86 return err;