]> sourceware.org Git - glibc.git/blame - hurd/hurdprio.c
* hurd/hurdinit.c (_hurd_ports_use): Return error _hurd_ports is null.
[glibc.git] / hurd / hurdprio.c
CommitLineData
28f540f4 1/* Support code for dealing with priorities in the Hurd.
70aabf75 2 Copyright (C) 1994,95,96,97,99 Free Software Foundation, Inc.
c84142e8
UD
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
41bdb6e2
AJ
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.
c84142e8
UD
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
41bdb6e2 13 Lesser General Public License for more details.
c84142e8 14
41bdb6e2
AJ
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
28f540f4 19
28f540f4 20#include <hurd.h>
aefc5849
RM
21#include <hurd/resource.h>
22#include <sys/mman.h>
f7db9ce5 23#include <unistd.h>
28f540f4
RM
24
25error_t
26_hurd_priority_which_map (enum __priority_which which, int who,
80b55d32
RM
27 error_t (*function) (pid_t, struct procinfo *),
28 int pi_flags)
28f540f4
RM
29{
30 mach_msg_type_number_t npids = 64, i;
70aabf75 31 pid_t pidbuf[npids], *pids = pidbuf;
28f540f4
RM
32 error_t err;
33 struct procinfo *pip;
34 int pibuf[sizeof *pip + 5 * sizeof (pip->threadinfos[0])], *pi = pibuf;
35 mach_msg_type_number_t pisize = sizeof (pibuf) / sizeof (int);
36
37 switch (which)
38 {
aefc5849
RM
39 default:
40 return EINVAL;
41
28f540f4 42 case PRIO_PROCESS:
aefc5849 43 err = (*function) (who ?: getpid (), 0); /* XXX special-case self? */
28f540f4
RM
44 break;
45
46 case PRIO_PGRP:
47 err = __USEPORT (PROC, __proc_getpgrppids (port, who, &pids, &npids));
aefc5849
RM
48 for (i = 0; !err && i < npids; ++i)
49 err = (*function) (pids[i], 0);
28f540f4
RM
50 break;
51
52 case PRIO_USER:
1a658b79
RM
53 if (who == 0)
54 who = geteuid ();
28f540f4 55 err = __USEPORT (PROC, __proc_getallpids (port, &pids, &npids));
aefc5849 56 for (i = 0; !err && i < npids; ++i)
28f540f4
RM
57 {
58 /* Get procinfo to check the owner. */
59 int *oldpi = pi;
60 mach_msg_type_number_t oldpisize = pisize;
853f0eea
RM
61 char *tw = 0;
62 size_t twsz = 0;
aefc5849
RM
63 err = __USEPORT (PROC, __proc_getprocinfo (port, pids[i],
64 &pi_flags,
65 &pi, &pisize,
66 &tw, &twsz));
67 if (!err)
68 {
69 if (twsz) /* Gratuitous. */
70 __munmap (tw, twsz);
71 if (pi != oldpi && oldpi != pibuf)
72 /* Old buffer from last call was not reused; free it. */
73 __munmap (oldpi, oldpisize * sizeof pi[0]);
28f540f4 74
aefc5849
RM
75 pip = (struct procinfo *) pi;
76 if (pip->owner == (uid_t) who)
77 err = (*function) (pids[i], pip);
78 }
28f540f4 79 }
aefc5849 80 break;
28f540f4
RM
81 }
82
83 if (pids != pidbuf)
aefc5849 84 __munmap (pids, npids * sizeof pids[0]);
28f540f4 85 if (pi != pibuf)
aefc5849 86 __munmap (pi, pisize * sizeof pi[0]);
28f540f4
RM
87
88 return err;
89}
This page took 0.161742 seconds and 5 git commands to generate.