]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
process-util: more gracefully handle oom adjust parsing/setting 35072/head
authorLennart Poettering <lennart@poettering.net>
Thu, 7 Nov 2024 13:54:21 +0000 (14:54 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 12 Nov 2024 22:03:40 +0000 (23:03 +0100)
Who knows what kind of mount shenanigans people employ, let's gracefully
handle parse failures of proc files, like we alway do otherwsie.

src/basic/process-util.c

index ee0edfaf94ef617704d8ddb295cd0fac6aff394a..9c159b46055b317b9b8fb62206f3001e45d61738 100644 (file)
@@ -1815,6 +1815,9 @@ int namespace_fork(
 int set_oom_score_adjust(int value) {
         char t[DECIMAL_STR_MAX(int)];
 
+        if (!oom_score_adjust_is_valid(value))
+                return -EINVAL;
+
         xsprintf(t, "%i", value);
 
         return write_string_file("/proc/self/oom_score_adj", t,
@@ -1831,11 +1834,16 @@ int get_oom_score_adjust(int *ret) {
 
         delete_trailing_chars(t, WHITESPACE);
 
-        assert_se(safe_atoi(t, &a) >= 0);
-        assert_se(oom_score_adjust_is_valid(a));
+        r = safe_atoi(t, &a);
+        if (r < 0)
+                return r;
+
+        if (!oom_score_adjust_is_valid(a))
+                return -ENODATA;
 
         if (ret)
                 *ret = a;
+
         return 0;
 }