summaryrefslogtreecommitdiff
path: root/src/basic
diff options
context:
space:
mode:
authorRonny Chevalier <chevalier.ronny@gmail.com>2016-08-05 13:35:52 +0200
committerGitHub <noreply@github.com>2016-08-05 13:35:52 +0200
commit96533edceb5bb626a674acda2843de72838811cf (patch)
tree58d255848f99af24009cea575d4d58ec53d6874d /src/basic
parent1ed1f50f8277df07918e13cba3331a114eaa6fe3 (diff)
parent41bf0590cc89438f1d319465190b1c00809c78fe (diff)
Merge pull request #3902 from poettering/parse-nice
util-lib: unify parsing of nice level values
Diffstat (limited to 'src/basic')
-rw-r--r--src/basic/parse-util.c18
-rw-r--r--src/basic/parse-util.h2
-rw-r--r--src/basic/process-util.h5
3 files changed, 24 insertions, 1 deletions
diff --git a/src/basic/parse-util.c b/src/basic/parse-util.c
index 11849ade0b..c98815b9bc 100644
--- a/src/basic/parse-util.c
+++ b/src/basic/parse-util.c
@@ -29,6 +29,7 @@
#include "extract-word.h"
#include "macro.h"
#include "parse-util.h"
+#include "process-util.h"
#include "string-util.h"
int parse_boolean(const char *v) {
@@ -551,10 +552,25 @@ int parse_percent_unbounded(const char *p) {
}
int parse_percent(const char *p) {
- int v = parse_percent_unbounded(p);
+ int v;
+ v = parse_percent_unbounded(p);
if (v > 100)
return -ERANGE;
return v;
}
+
+int parse_nice(const char *p, int *ret) {
+ int n, r;
+
+ r = safe_atoi(p, &n);
+ if (r < 0)
+ return r;
+
+ if (!nice_is_valid(n))
+ return -ERANGE;
+
+ *ret = n;
+ return 0;
+}
diff --git a/src/basic/parse-util.h b/src/basic/parse-util.h
index f0fa5f9752..461e1cd4d8 100644
--- a/src/basic/parse-util.h
+++ b/src/basic/parse-util.h
@@ -108,3 +108,5 @@ int parse_fractional_part_u(const char **s, size_t digits, unsigned *res);
int parse_percent_unbounded(const char *p);
int parse_percent(const char *p);
+
+int parse_nice(const char *p, int *ret);
diff --git a/src/basic/process-util.h b/src/basic/process-util.h
index 9f75088796..2568e3834f 100644
--- a/src/basic/process-util.h
+++ b/src/basic/process-util.h
@@ -26,6 +26,7 @@
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
+#include <sys/resource.h>
#include "formats-util.h"
#include "macro.h"
@@ -103,3 +104,7 @@ int sched_policy_from_string(const char *s);
void valgrind_summary_hack(void);
int pid_compare_func(const void *a, const void *b);
+
+static inline bool nice_is_valid(int n) {
+ return n >= PRIO_MIN && n < PRIO_MAX;
+}