Add xdr_sizeof prototype.
[glibc/history.git] / hurd / hurdprio.c
blobd3da694ef10f837f18dc556f4053ec38ddc91431
1 /* Support code for dealing with priorities in the Hurd.
2 Copyright (C) 1994, 1995, 1996, 1997 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. */
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 *),
26 int pi_flags)
28 mach_msg_type_number_t npids = 64, i;
29 pid_t pidbuf[npids], *pids;
30 error_t err;
31 struct procinfo *pip;
32 int pibuf[sizeof *pip + 5 * sizeof (pip->threadinfos[0])], *pi = pibuf;
33 mach_msg_type_number_t pisize = sizeof (pibuf) / sizeof (int);
35 switch (which)
37 case PRIO_PROCESS:
38 npids = 1;
39 pids[0] = who;
40 err = 0;
41 break;
43 case PRIO_PGRP:
44 err = __USEPORT (PROC, __proc_getpgrppids (port, who, &pids, &npids));
45 break;
47 case PRIO_USER:
48 err = __USEPORT (PROC, __proc_getallpids (port, &pids, &npids));
49 break;
51 default:
52 return EINVAL;
55 for (i = 0; !err && i < npids; ++i)
57 if (which == PRIO_USER)
59 /* Get procinfo to check the owner. */
60 int *oldpi = pi;
61 mach_msg_type_number_t oldpisize = pisize;
62 char *tw = 0;
63 size_t twsz = 0;
64 if (err = __USEPORT (PROC, __proc_getprocinfo (port, pids[i],
65 &pi_flags,
66 &pi, &pisize,
67 &tw, &twsz)))
68 continue;
69 if (twsz)
70 /* Gratuitous. */
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)
79 continue;
81 else
82 pip = NULL;
84 err = (*function) (pids[i], pip);
87 if (pids != pidbuf)
88 __vm_deallocate (__mach_task_self (),
89 (vm_address_t) pids, npids * sizeof pids[0]);
90 if (pi != pibuf)
91 __vm_deallocate (__mach_task_self (),
92 (vm_address_t) pi, pisize * sizeof pi[0]);
94 return err;