]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
swapoff: avoid being killed by OOM
authorKarel Zak <kzak@redhat.com>
Thu, 20 Jun 2024 10:07:12 +0000 (12:07 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 20 Jun 2024 10:07:12 +0000 (12:07 +0200)
Based on patch from dparalen <vetrisko@gmail.com>.

Fixes: https://github.com/util-linux/util-linux/issues/3095
Signed-off-by: Karel Zak <kzak@redhat.com>
include/pathnames.h
sys-utils/swapoff.c

index 81fa405f63c7fdd19dc25134bdef71dfaffb27cf..36d8acaea2c75f8bd7d46c65e5aeaa57d124d6a2 100644 (file)
 #define _PATH_PROC_FDDIR       "/proc/self/fd"
 #define _PATH_PROC_TIMENS_OFF   "/proc/self/timens_offsets"
 
+#define _PATH_PROC_OOM_ADJ     "/proc/self/oom_score_adj"
+
 #define _PATH_PROC_ATTR_CURRENT        "/proc/self/attr/current"
 #define _PATH_PROC_ATTR_EXEC   "/proc/self/attr/exec"
 #define _PATH_PROC_CAPLASTCAP  "/proc/sys/kernel/cap_last_cap"
index 62f1374d09695e81da79c999b0717efb2f48a57b..5677d87a1521d09f277426389d0ee242a6891177 100644 (file)
@@ -23,6 +23,8 @@
 #include "c.h"
 #include "xalloc.h"
 #include "closestream.h"
+#include "pathnames.h"
+#include "path.h"
 
 #include "swapprober.h"
 #include "swapon-common.h"
@@ -272,6 +274,9 @@ int main(int argc, char *argv[])
                errtryhelp(SWAPOFF_EX_USAGE);
        }
 
+       /* prevent the OOM killer from killing myself */
+       ul_path_write_string(NULL, "-1000", _PATH_PROC_OOM_ADJ);
+
        mnt_init_debug(0);
        mntcache = mnt_new_cache();