Better handling of nice(); add setpriority() getpriority()
sched_setscheduler() sched_yield()

diff --git a/SYSCALLS b/SYSCALLS
index 48e2811..ba30a3e 100644
--- a/SYSCALLS
+++ b/SYSCALLS
@@ -23,7 +23,9 @@
 pid_t getsid(pid_t)
 pid_t wait4(pid_t, int *, int, struct rusage *)
 int execve(const char *, char * const *, char * const *)
-<!x86_64,ia64,alpha> int nice(int)
+int setpriority(int, int, int);
+int sched_setscheduler(pid_t, int, const struct sched_param *)
+int sched_yield()
 
 #
 # User and group IDs
diff --git a/getpriority.c b/getpriority.c
new file mode 100644
index 0000000..d6db2cc
--- /dev/null
+++ b/getpriority.c
@@ -0,0 +1,25 @@
+/*
+ * getpriority.c
+ *
+ * Needs to do some post-syscall mangling to distinguish error returns...
+ * but only on some platforms.  Sigh.
+ */
+
+#include <unistd.h>
+#include <sys/time.h>
+#include <sys/resource.h>
+#include <sys/syscall.h>
+
+#define __NR__getpriority __NR_getpriority
+
+static inline _syscall2(int,_getpriority,int,which,int,who);
+
+int getpriority(int which, int who)
+{
+#if defined(__alpha__) || defined(__ia64__)
+  return _getpriority(which, who);
+#else
+  int rv = _getpriority(which, who);
+  return ( rv < 0 ) ? rv : 20-rv;
+#endif
+}
diff --git a/include/sched.h b/include/sched.h
new file mode 100644
index 0000000..5e61039
--- /dev/null
+++ b/include/sched.h
@@ -0,0 +1,23 @@
+/*
+ * sched.h
+ */
+
+#ifndef _SCHED_H
+#define _SCHED_H
+
+#include <klibc/extern.h>
+
+/* linux/sched.h is unusable; put the declarations we need here... */
+
+#define SCHED_NORMAL            0
+#define SCHED_FIFO              1
+#define SCHED_RR                2
+
+struct sched_param {
+  int sched_priority;
+};
+
+__extern int sched_setschedule(pid_t, int, const struct sched_param *);
+__extern int sched_yield(void);
+
+#endif /* _SCHED_H */
diff --git a/include/sys/resource.h b/include/sys/resource.h
index 93c4439..7cb11f2 100644
--- a/include/sys/resource.h
+++ b/include/sys/resource.h
@@ -8,4 +8,7 @@
 #include <sys/types.h>		/* MUST be included first! */
 #include <linux/resource.h>
 
+__extern int getpriority(int, int);
+__extern int setpriority(int, int, int);
+
 #endif /* _SYS_RESOURCE_H */
diff --git a/klibc/Makefile b/klibc/Makefile
index f4ebe3f..27d0fbc 100644
--- a/klibc/Makefile
+++ b/klibc/Makefile
@@ -34,7 +34,7 @@
 	  strncmp.o strncpy.o strrchr.o strspn.o strsep.o strtok.o \
 	  gethostname.o getdomainname.o getcwd.o seteuid.o setegid.o \
 	  getenv.o setenv.o unsetenv.o getopt.o readdir.o \
-	  time.o fdatasync.o llseek.o select.o
+	  time.o fdatasync.o llseek.o select.o nice.o getpriority.o
 LIB     = libc.a
 
 SOFLAGS = -fPIC
diff --git a/klibc/SYSCALLS b/klibc/SYSCALLS
index 48e2811..ba30a3e 100644
--- a/klibc/SYSCALLS
+++ b/klibc/SYSCALLS
@@ -23,7 +23,9 @@
 pid_t getsid(pid_t)
 pid_t wait4(pid_t, int *, int, struct rusage *)
 int execve(const char *, char * const *, char * const *)
-<!x86_64,ia64,alpha> int nice(int)
+int setpriority(int, int, int);
+int sched_setscheduler(pid_t, int, const struct sched_param *)
+int sched_yield()
 
 #
 # User and group IDs
diff --git a/klibc/getpriority.c b/klibc/getpriority.c
new file mode 100644
index 0000000..d6db2cc
--- /dev/null
+++ b/klibc/getpriority.c
@@ -0,0 +1,25 @@
+/*
+ * getpriority.c
+ *
+ * Needs to do some post-syscall mangling to distinguish error returns...
+ * but only on some platforms.  Sigh.
+ */
+
+#include <unistd.h>
+#include <sys/time.h>
+#include <sys/resource.h>
+#include <sys/syscall.h>
+
+#define __NR__getpriority __NR_getpriority
+
+static inline _syscall2(int,_getpriority,int,which,int,who);
+
+int getpriority(int which, int who)
+{
+#if defined(__alpha__) || defined(__ia64__)
+  return _getpriority(which, who);
+#else
+  int rv = _getpriority(which, who);
+  return ( rv < 0 ) ? rv : 20-rv;
+#endif
+}
diff --git a/klibc/include/sched.h b/klibc/include/sched.h
new file mode 100644
index 0000000..5e61039
--- /dev/null
+++ b/klibc/include/sched.h
@@ -0,0 +1,23 @@
+/*
+ * sched.h
+ */
+
+#ifndef _SCHED_H
+#define _SCHED_H
+
+#include <klibc/extern.h>
+
+/* linux/sched.h is unusable; put the declarations we need here... */
+
+#define SCHED_NORMAL            0
+#define SCHED_FIFO              1
+#define SCHED_RR                2
+
+struct sched_param {
+  int sched_priority;
+};
+
+__extern int sched_setschedule(pid_t, int, const struct sched_param *);
+__extern int sched_yield(void);
+
+#endif /* _SCHED_H */
diff --git a/klibc/include/sys/resource.h b/klibc/include/sys/resource.h
index 93c4439..7cb11f2 100644
--- a/klibc/include/sys/resource.h
+++ b/klibc/include/sys/resource.h
@@ -8,4 +8,7 @@
 #include <sys/types.h>		/* MUST be included first! */
 #include <linux/resource.h>
 
+__extern int getpriority(int, int);
+__extern int setpriority(int, int, int);
+
 #endif /* _SYS_RESOURCE_H */
diff --git a/klibc/nice.c b/klibc/nice.c
new file mode 100644
index 0000000..c3d9da6
--- /dev/null
+++ b/klibc/nice.c
@@ -0,0 +1,21 @@
+/*
+ * nice.c
+ */
+
+#include <unistd.h>
+#include <sched.h>
+#include <sys/syscall.h>
+
+#ifdef __NR_nice
+
+_syscall1(int,nice,int,inc);
+
+#else
+
+int nice(int inc)
+{
+  pid_t me = getpid();
+  return setpriority(me, PRIO_PROCESS, getpriority(me, PRIO_PROCESS));
+}
+
+#endif
diff --git a/klibc/syscommon.h b/klibc/syscommon.h
index cdd225f..46777db 100644
--- a/klibc/syscommon.h
+++ b/klibc/syscommon.h
@@ -11,6 +11,7 @@
 #include <sys/syscall.h>
 
 #include <poll.h>
+#include <sched.h>
 #include <sys/dirent.h>
 #include <sys/mman.h>
 #include <sys/module.h>
diff --git a/nice.c b/nice.c
new file mode 100644
index 0000000..c3d9da6
--- /dev/null
+++ b/nice.c
@@ -0,0 +1,21 @@
+/*
+ * nice.c
+ */
+
+#include <unistd.h>
+#include <sched.h>
+#include <sys/syscall.h>
+
+#ifdef __NR_nice
+
+_syscall1(int,nice,int,inc);
+
+#else
+
+int nice(int inc)
+{
+  pid_t me = getpid();
+  return setpriority(me, PRIO_PROCESS, getpriority(me, PRIO_PROCESS));
+}
+
+#endif
diff --git a/syscommon.h b/syscommon.h
index cdd225f..46777db 100644
--- a/syscommon.h
+++ b/syscommon.h
@@ -11,6 +11,7 @@
 #include <sys/syscall.h>
 
 #include <poll.h>
+#include <sched.h>
 #include <sys/dirent.h>
 #include <sys/mman.h>
 #include <sys/module.h>