chiark / gitweb /
process-util: add new helper call for adjusting the OOM score
authorLennart Poettering <lennart@poettering.net>
Mon, 7 May 2018 18:44:41 +0000 (20:44 +0200)
committerSven Eden <yamakuzure@gmx.net>
Fri, 24 Aug 2018 14:47:08 +0000 (16:47 +0200)
And let's make use of it in execute.c

src/basic/process-util.c
src/basic/process-util.h

index 27a593981168ef8e259f33de74132d7a181c33dc..43bad9009f7f5c0293399308e48b9b4f3b1d9a1e 100644 (file)
@@ -1457,6 +1457,15 @@ int fork_agent(const char *name, const int except[], size_t n_except, pid_t *ret
         _exit(EXIT_FAILURE);
 }
 
+int set_oom_score_adjust(int value) {
+        char t[DECIMAL_STR_MAX(int)];
+
+        sprintf(t, "%i", value);
+
+        return write_string_file("/proc/self/oom_score_adj", t,
+                                 WRITE_STRING_FILE_VERIFY_ON_FAILURE|WRITE_STRING_FILE_DISABLE_BUFFER);
+}
+
 #if 0 /// UNNEEDED by elogind
 static const char *const ioprio_class_table[] = {
         [IOPRIO_CLASS_NONE] = "none",
index e44f136e5fe7d09ed378abaa5a544af599cba402..a5f749b4ecfae77f31c8c09153f28335d1b22ad8 100644 (file)
@@ -191,6 +191,8 @@ static inline int safe_fork(const char *name, ForkFlags flags, pid_t *ret_pid) {
 
 int fork_agent(const char *name, const int except[], size_t n_except, pid_t *pid, const char *path, ...);
 
+int set_oom_score_adjust(int value);
+
 #if SIZEOF_PID_T == 4
 /* The highest possibly (theoretic) pid_t value on this architecture. */
 #define PID_T_MAX ((pid_t) INT32_MAX)