1995-02-18 02:27:10 +01:00
|
|
|
/* Support code for dealing with priorities in the Hurd.
|
2018-01-01 01:32:25 +01:00
|
|
|
Copyright (C) 1994-2018 Free Software Foundation, Inc.
|
1997-02-15 05:31:36 +01:00
|
|
|
This file is part of the GNU C Library.
|
|
|
|
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
2001-07-06 06:58:11 +02:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
1997-02-15 05:31:36 +01:00
|
|
|
|
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2001-07-06 06:58:11 +02:00
|
|
|
Lesser General Public License for more details.
|
1997-02-15 05:31:36 +01:00
|
|
|
|
2001-07-06 06:58:11 +02:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2012-02-10 00:18:22 +01:00
|
|
|
License along with the GNU C Library; if not, see
|
|
|
|
<http://www.gnu.org/licenses/>. */
|
1995-02-18 02:27:10 +01:00
|
|
|
|
|
|
|
#include <hurd.h>
|
1999-09-19 07:42:05 +02:00
|
|
|
#include <hurd/resource.h>
|
|
|
|
#include <sys/mman.h>
|
1999-09-05 10:51:02 +02:00
|
|
|
#include <unistd.h>
|
1995-02-18 02:27:10 +01:00
|
|
|
|
|
|
|
error_t
|
|
|
|
_hurd_priority_which_map (enum __priority_which which, int who,
|
1995-11-01 11:00:20 +01:00
|
|
|
error_t (*function) (pid_t, struct procinfo *),
|
|
|
|
int pi_flags)
|
1995-02-18 02:27:10 +01:00
|
|
|
{
|
|
|
|
mach_msg_type_number_t npids = 64, i;
|
1999-07-27 01:28:24 +02:00
|
|
|
pid_t pidbuf[npids], *pids = pidbuf;
|
1995-02-18 02:27:10 +01:00
|
|
|
error_t err;
|
|
|
|
struct procinfo *pip;
|
|
|
|
int pibuf[sizeof *pip + 5 * sizeof (pip->threadinfos[0])], *pi = pibuf;
|
|
|
|
mach_msg_type_number_t pisize = sizeof (pibuf) / sizeof (int);
|
|
|
|
|
|
|
|
switch (which)
|
|
|
|
{
|
1999-09-19 07:42:05 +02:00
|
|
|
default:
|
|
|
|
return EINVAL;
|
|
|
|
|
1995-02-18 02:27:10 +01:00
|
|
|
case PRIO_PROCESS:
|
1999-09-19 07:42:05 +02:00
|
|
|
err = (*function) (who ?: getpid (), 0); /* XXX special-case self? */
|
1995-02-18 02:27:10 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PRIO_PGRP:
|
|
|
|
err = __USEPORT (PROC, __proc_getpgrppids (port, who, &pids, &npids));
|
1999-09-19 07:42:05 +02:00
|
|
|
for (i = 0; !err && i < npids; ++i)
|
|
|
|
err = (*function) (pids[i], 0);
|
1995-02-18 02:27:10 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PRIO_USER:
|
1999-09-05 10:44:50 +02:00
|
|
|
if (who == 0)
|
2018-04-02 21:07:52 +02:00
|
|
|
who = __geteuid ();
|
1995-02-18 02:27:10 +01:00
|
|
|
err = __USEPORT (PROC, __proc_getallpids (port, &pids, &npids));
|
1999-09-19 07:42:05 +02:00
|
|
|
for (i = 0; !err && i < npids; ++i)
|
1995-02-18 02:27:10 +01:00
|
|
|
{
|
|
|
|
/* Get procinfo to check the owner. */
|
|
|
|
int *oldpi = pi;
|
|
|
|
mach_msg_type_number_t oldpisize = pisize;
|
1995-11-03 23:42:06 +01:00
|
|
|
char *tw = 0;
|
|
|
|
size_t twsz = 0;
|
1999-09-19 07:42:05 +02:00
|
|
|
err = __USEPORT (PROC, __proc_getprocinfo (port, pids[i],
|
|
|
|
&pi_flags,
|
|
|
|
&pi, &pisize,
|
|
|
|
&tw, &twsz));
|
|
|
|
if (!err)
|
|
|
|
{
|
|
|
|
if (twsz) /* Gratuitous. */
|
|
|
|
__munmap (tw, twsz);
|
|
|
|
if (pi != oldpi && oldpi != pibuf)
|
|
|
|
/* Old buffer from last call was not reused; free it. */
|
|
|
|
__munmap (oldpi, oldpisize * sizeof pi[0]);
|
1995-02-18 02:27:10 +01:00
|
|
|
|
1999-09-19 07:42:05 +02:00
|
|
|
pip = (struct procinfo *) pi;
|
|
|
|
if (pip->owner == (uid_t) who)
|
|
|
|
err = (*function) (pids[i], pip);
|
|
|
|
}
|
1995-02-18 02:27:10 +01:00
|
|
|
}
|
1999-09-19 07:42:05 +02:00
|
|
|
break;
|
1995-02-18 02:27:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pids != pidbuf)
|
1999-09-19 07:42:05 +02:00
|
|
|
__munmap (pids, npids * sizeof pids[0]);
|
1995-02-18 02:27:10 +01:00
|
|
|
if (pi != pibuf)
|
1999-09-19 07:42:05 +02:00
|
|
|
__munmap (pi, pisize * sizeof pi[0]);
|
1995-02-18 02:27:10 +01:00
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|