1*433d6423SLionel Sambuc /*
2*433d6423SLionel Sambuc priority.c
3*433d6423SLionel Sambuc */
4*433d6423SLionel Sambuc
5*433d6423SLionel Sambuc #include <sys/cdefs.h>
6*433d6423SLionel Sambuc #include "namespace.h"
7*433d6423SLionel Sambuc #include <errno.h>
8*433d6423SLionel Sambuc #include <sys/types.h>
9*433d6423SLionel Sambuc #include <sys/resource.h>
10*433d6423SLionel Sambuc #include <lib.h>
11*433d6423SLionel Sambuc #include <unistd.h>
12*433d6423SLionel Sambuc #include <string.h>
13*433d6423SLionel Sambuc #include <stddef.h>
14*433d6423SLionel Sambuc
15*433d6423SLionel Sambuc
getpriority(int which,id_t who)16*433d6423SLionel Sambuc int getpriority(int which, id_t who)
17*433d6423SLionel Sambuc {
18*433d6423SLionel Sambuc int v;
19*433d6423SLionel Sambuc message m;
20*433d6423SLionel Sambuc
21*433d6423SLionel Sambuc memset(&m, 0, sizeof(m));
22*433d6423SLionel Sambuc m.m_lc_pm_priority.which = which;
23*433d6423SLionel Sambuc m.m_lc_pm_priority.who = who;
24*433d6423SLionel Sambuc
25*433d6423SLionel Sambuc /* GETPRIORITY returns negative for error.
26*433d6423SLionel Sambuc * Otherwise, it returns the priority plus the minimum
27*433d6423SLionel Sambuc * priority, to distiginuish from error. We have to
28*433d6423SLionel Sambuc * correct for this. (The user program has to check errno
29*433d6423SLionel Sambuc * to see if something really went wrong.)
30*433d6423SLionel Sambuc */
31*433d6423SLionel Sambuc
32*433d6423SLionel Sambuc if((v = _syscall(PM_PROC_NR, PM_GETPRIORITY, &m)) < 0) {
33*433d6423SLionel Sambuc return v;
34*433d6423SLionel Sambuc }
35*433d6423SLionel Sambuc
36*433d6423SLionel Sambuc return v + PRIO_MIN;
37*433d6423SLionel Sambuc }
38*433d6423SLionel Sambuc
setpriority(int which,id_t who,int prio)39*433d6423SLionel Sambuc int setpriority(int which, id_t who, int prio)
40*433d6423SLionel Sambuc {
41*433d6423SLionel Sambuc message m;
42*433d6423SLionel Sambuc
43*433d6423SLionel Sambuc memset(&m, 0, sizeof(m));
44*433d6423SLionel Sambuc m.m_lc_pm_priority.which = which;
45*433d6423SLionel Sambuc m.m_lc_pm_priority.who = who;
46*433d6423SLionel Sambuc m.m_lc_pm_priority.prio = prio;
47*433d6423SLionel Sambuc
48*433d6423SLionel Sambuc return _syscall(PM_PROC_NR, PM_SETPRIORITY, &m);
49*433d6423SLionel Sambuc }
50*433d6423SLionel Sambuc
51