From: Karel Zak Date: Thu, 20 Jun 2024 10:07:12 +0000 (+0200) Subject: swapoff: avoid being killed by OOM X-Git-Tag: v2.42-start~291^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e15d24dc9eb7004227c895e09a2e60945a708147;p=thirdparty%2Futil-linux.git 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 --- diff --git a/include/pathnames.h b/include/pathnames.h index 81fa405f6..36d8acaea 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 62f1374d0..5677d87a1 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();