process-util: add helper for querying oom score adjustment value
This commit is contained in:
@@ -1502,6 +1502,24 @@ int set_oom_score_adjust(int value) {
|
||||
WRITE_STRING_FILE_VERIFY_ON_FAILURE|WRITE_STRING_FILE_DISABLE_BUFFER);
|
||||
}
|
||||
|
||||
int get_oom_score_adjust(int *ret) {
|
||||
_cleanup_free_ char *t;
|
||||
int r, a;
|
||||
|
||||
r = read_virtual_file("/proc/self/oom_score_adj", SIZE_MAX, &t, NULL);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
delete_trailing_chars(t, WHITESPACE);
|
||||
|
||||
assert_se(safe_atoi(t, &a) >= 0);
|
||||
assert_se(oom_score_adjust_is_valid(a));
|
||||
|
||||
if (ret)
|
||||
*ret = a;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pidfd_get_pid(int fd, pid_t *ret) {
|
||||
char path[STRLEN("/proc/self/fdinfo/") + DECIMAL_STR_MAX(int)];
|
||||
_cleanup_free_ char *fdinfo = NULL;
|
||||
|
||||
Reference in New Issue
Block a user