From e15d24dc9eb7004227c895e09a2e60945a708147 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 20 Jun 2024 12:07:12 +0200 Subject: [PATCH] swapoff: avoid being killed by OOM Based on patch from dparalen . Fixes: https://github.com/util-linux/util-linux/issues/3095 Signed-off-by: Karel Zak --- include/pathnames.h | 2 ++ sys-utils/swapoff.c | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/include/pathnames.h b/include/pathnames.h index 81fa405f63..36d8acaea2 100644 --- a/include/pathnames.h +++ b/include/pathnames.h @@ -110,6 +110,8 @@ #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" diff --git a/sys-utils/swapoff.c b/sys-utils/swapoff.c index 62f1374d09..5677d87a15 100644 --- a/sys-utils/swapoff.c +++ b/sys-utils/swapoff.c @@ -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(); -- 2.47.2