[hackers] [sbase] Use getpriority()/setpriority() instead of deprecated nice() || sin
commit 203b52c38a447e6e1cadcab4cd366cd5bd86be94
Author: sin <sin_AT_2f30.org>
Date: Tue Jan 28 17:10:09 2014 +0000
Use getpriority()/setpriority() instead of deprecated nice()
This is now similar to how renice(1) is implemented.
diff --git a/nice.c b/nice.c
index 7755b90..0ef6256 100644
--- a/nice.c
+++ b/nice.c
_AT_@ -3,6 +3,8 @@
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
+#include <sys/resource.h>
+#include <sys/time.h>
#include <unistd.h>
#include "util.h"
_AT_@ -12,6 +14,7 @@ int
main(int argc, char **argv)
{
long val = 10;
+ int savederrno;
ARGBEGIN {
case 'n':
_AT_@ -26,15 +29,18 @@ main(int argc, char **argv)
usage();
errno = 0;
- nice((int)MAX(INT_MIN, MIN(val, INT_MAX)));
- if(errno != 0)
- perror("can't adjust niceness");
+ val += getpriority(PRIO_PROCESS, 0);
+ if (errno != 0)
+ weprintf("getpriority:");
+ val = MAX(PRIO_MIN, MIN(val, PRIO_MAX));
+ if (setpriority(PRIO_PROCESS, 0, val) != 0)
+ weprintf("setpriority:");
/* POSIX specifies the nice failure still invokes the command */
execvp(argv[0], argv);
- /* reached only on failure */
- perror(argv[0]);
- return (errno == ENOENT)? 127 : 126;
+ savederrno = errno;
+ weprintf("execvp %s:", argv[0]);
+ return (savederrno == ENOENT)? 127 : 126;
}
static void
Received on Tue Jan 28 2014 - 18:20:44 CET
This archive was generated by hypermail 2.3.0
: Tue Jan 28 2014 - 18:24:09 CET