Override elf_nacl.xr linker script so that libc_pic.os links correctly
[glibc/nacl-glibc.git] / sysdeps / mach / hurd / getpriority.c
blob8f7c3c6d976de53957be0fbdf34b454d1fa0eff3
1 /* Copyright (C) 1994,95,96,97,2000,02 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17 02111-1307 USA. */
19 #include <limits.h>
20 #include <hurd.h>
21 #include <hurd/resource.h>
23 /* Return the highest priority of any process specified by WHICH and WHO
24 (see <sys/resource.h>); if WHO is zero, the current process, process group,
25 or user (as specified by WHO) is used. A lower priority number means higher
26 priority. Priorities range from PRIO_MIN to PRIO_MAX. */
27 int
28 getpriority (enum __priority_which which, id_t who)
30 error_t err, onerr;
31 int maxpri = INT_MIN;
32 struct procinfo *pip; /* Just for sizeof. */
33 int pibuf[sizeof *pip + 2 * sizeof (pip->threadinfos[0])], *pi = pibuf;
34 size_t pisize = sizeof pibuf / sizeof pibuf[0];
36 error_t getonepriority (pid_t pid, struct procinfo *pip)
38 if (pip)
39 onerr = 0;
40 else
42 int *oldpi = pi;
43 size_t oldpisize = pisize;
44 char *tw = 0;
45 size_t twsz = 0;
46 int flags = PI_FETCH_TASKINFO;
47 onerr = __USEPORT (PROC, __proc_getprocinfo (port, pid, &flags,
48 &pi, &pisize,
49 &tw, &twsz));
50 if (twsz)
51 __vm_deallocate (__mach_task_self (), (vm_address_t) tw, twsz);
52 if (pi != oldpi && oldpi != pibuf)
53 /* Old buffer from last call was not reused; free it. */
54 __vm_deallocate (__mach_task_self (),
55 (vm_address_t) oldpi, oldpisize * sizeof pi[0]);
56 pip = (struct procinfo *) pi;
58 #ifdef TASK_SCHED_TIMESHARE_INFO
59 if (!onerr && pip->timeshare_base_info.base_priority > maxpri)
60 maxpri = pip->timeshare_base_info.base_priority;
61 #else
62 if (!onerr && pip->taskinfo.base_priority > maxpri)
63 maxpri = pip->taskinfo.base_priority;
64 #endif
65 return 0;
68 onerr = 0;
69 err = _hurd_priority_which_map (which, who,
70 getonepriority, PI_FETCH_TASKINFO);
72 if (pi != pibuf)
73 __vm_deallocate (__mach_task_self (),
74 (vm_address_t) pi, pisize * sizeof pi[0]);
76 if (!err && maxpri == INT_MIN)
77 /* No error, but no pids found. */
78 err = onerr ?: ESRCH;
80 if (err)
81 return __hurd_fail (err);
83 return MACH_PRIORITY_TO_NICE (maxpri);
85 libc_hidden_def (getpriority)