From 50e3bab2421e41cbce9093c5047298ed7ad730cb Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Fri, 10 Sep 2010 10:30:25 +1000 Subject: - (dtucker) [openbsd-compat/port-linux.c] Check is_selinux_enabled for exact return code since it can apparently return -1 under some conditions. From openssh bugs werbittewas de, ok djm@ --- openbsd-compat/port-linux.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'openbsd-compat/port-linux.c') diff --git a/openbsd-compat/port-linux.c b/openbsd-compat/port-linux.c index 89b9a7340..86d16dc6e 100644 --- a/openbsd-compat/port-linux.c +++ b/openbsd-compat/port-linux.c @@ -1,4 +1,4 @@ -/* $Id: port-linux.c,v 1.8 2010/03/01 04:52:50 dtucker Exp $ */ +/* $Id: port-linux.c,v 1.9 2010/09/10 00:30:25 dtucker Exp $ */ /* * Copyright (c) 2005 Daniel Walsh @@ -45,7 +45,7 @@ ssh_selinux_enabled(void) static int enabled = -1; if (enabled == -1) { - enabled = is_selinux_enabled(); + enabled = (is_selinux_enabled() == 1); debug("SELinux support %s", enabled ? "enabled" : "disabled"); } -- cgit v1.2.3 From 0c93adc7c1814b113d25c5e214973a3aa630b0af Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Mon, 17 Jan 2011 11:55:59 +1100 Subject: - (dtucker) [openbsd-compat/port-linux.c] Bug #1838: Add support for the new Linux OOM-killer magic values that changed in 2.6.36 kernels, with fallback to the old values. Feedback from vapier at gentoo org and djm, ok djm. --- ChangeLog | 3 +++ openbsd-compat/port-linux.c | 55 +++++++++++++++++++++++++++++---------------- 2 files changed, 39 insertions(+), 19 deletions(-) (limited to 'openbsd-compat/port-linux.c') diff --git a/ChangeLog b/ChangeLog index 7dda03e0e..e64a550f1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,9 @@ its unique snowflake of a gdb error to the ones we look for. - (djm) [regress/agent-getpeereid.sh] leave stdout attached when running ssh-add to avoid $SUDO failures on Linux + - (dtucker) [openbsd-compat/port-linux.c] Bug #1838: Add support for the new + Linux OOM-killer magic values that changed in 2.6.36 kernels, with fallback + to the old values. Feedback from vapier at gentoo org and djm, ok djm. 20110116 - (dtucker) [Makefile.in configure.ac regress/kextype.sh] Skip sha256-based diff --git a/openbsd-compat/port-linux.c b/openbsd-compat/port-linux.c index 86d16dc6e..d89101d18 100644 --- a/openbsd-compat/port-linux.c +++ b/openbsd-compat/port-linux.c @@ -1,4 +1,4 @@ -/* $Id: port-linux.c,v 1.9 2010/09/10 00:30:25 dtucker Exp $ */ +/* $Id: port-linux.c,v 1.10 2011/01/17 00:56:00 dtucker Exp $ */ /* * Copyright (c) 2005 Daniel Walsh @@ -208,14 +208,22 @@ ssh_selinux_change_context(const char *newname) #endif /* WITH_SELINUX */ #ifdef LINUX_OOM_ADJUST -#define OOM_ADJ_PATH "/proc/self/oom_adj" /* - * The magic "don't kill me", as documented in eg: + * The magic "don't kill me" values, old and new, as documented in eg: * http://lxr.linux.no/#linux+v2.6.32/Documentation/filesystems/proc.txt + * http://lxr.linux.no/#linux+v2.6.36/Documentation/filesystems/proc.txt */ -#define OOM_ADJ_NOKILL -17 static int oom_adj_save = INT_MIN; +static char *oom_adj_path = NULL; +struct { + char *path; + int value; +} oom_adjust[] = { + {"/proc/self/oom_score_adj", -1000}, /* kernels >= 2.6.36 */ + {"/proc/self/oom_adj", -17}, /* kernels <= 2.6.35 */ + {NULL, 0}, +}; /* * Tell the kernel's out-of-memory killer to avoid sshd. @@ -224,23 +232,31 @@ static int oom_adj_save = INT_MIN; void oom_adjust_setup(void) { + int i, value; FILE *fp; debug3("%s", __func__); - if ((fp = fopen(OOM_ADJ_PATH, "r+")) != NULL) { - if (fscanf(fp, "%d", &oom_adj_save) != 1) - verbose("error reading %s: %s", OOM_ADJ_PATH, strerror(errno)); - else { - rewind(fp); - if (fprintf(fp, "%d\n", OOM_ADJ_NOKILL) <= 0) - verbose("error writing %s: %s", - OOM_ADJ_PATH, strerror(errno)); - else - verbose("Set %s from %d to %d", - OOM_ADJ_PATH, oom_adj_save, OOM_ADJ_NOKILL); + for (i = 0; oom_adjust[i].path != NULL; i++) { + oom_adj_path = oom_adjust[i].path; + value = oom_adjust[i].value; + if ((fp = fopen(oom_adj_path, "r+")) != NULL) { + if (fscanf(fp, "%d", &oom_adj_save) != 1) + verbose("error reading %s: %s", oom_adj_path, + strerror(errno)); + else { + rewind(fp); + if (fprintf(fp, "%d\n", value) <= 0) + verbose("error writing %s: %s", + oom_adj_path, strerror(errno)); + else + verbose("Set %s from %d to %d", + oom_adj_path, oom_adj_save, value); + } + fclose(fp); + return; } - fclose(fp); } + oom_adj_path = NULL; } /* Restore the saved OOM adjustment */ @@ -250,13 +266,14 @@ oom_adjust_restore(void) FILE *fp; debug3("%s", __func__); - if (oom_adj_save == INT_MIN || (fp = fopen(OOM_ADJ_PATH, "w")) == NULL) + if (oom_adj_save == INT_MIN || oom_adj_save == NULL || + (fp = fopen(oom_adj_path, "w")) == NULL) return; if (fprintf(fp, "%d\n", oom_adj_save) <= 0) - verbose("error writing %s: %s", OOM_ADJ_PATH, strerror(errno)); + verbose("error writing %s: %s", oom_adj_path, strerror(errno)); else - verbose("Set %s to %d", OOM_ADJ_PATH, oom_adj_save); + verbose("Set %s to %d", oom_adj_path, oom_adj_save); fclose(fp); return; -- cgit v1.2.3 From 263d43d2a58f0fc4cf211808410560c8c3e451d2 Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Mon, 17 Jan 2011 18:50:22 +1100 Subject: - (dtucker) [openbsd-compat/port-linux.c] Fix minor bug caught by -Werror on the tinderbox. --- ChangeLog | 2 ++ openbsd-compat/port-linux.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'openbsd-compat/port-linux.c') diff --git a/ChangeLog b/ChangeLog index b8c334ab0..6230fdc26 100644 --- a/ChangeLog +++ b/ChangeLog @@ -20,6 +20,8 @@ of tests for quotes backslashes in sftp-glob.sh. based on discussion with vinschen AT redhat.com and dtucker@; ok dtucker@ - (tim) [regress/agent-getpeereid.sh] shell portability fix. + - (dtucker) [openbsd-compat/port-linux.c] Fix minor bug caught by -Werror on + the tinderbox. 20110116 - (dtucker) [Makefile.in configure.ac regress/kextype.sh] Skip sha256-based diff --git a/openbsd-compat/port-linux.c b/openbsd-compat/port-linux.c index d89101d18..5b1cf402c 100644 --- a/openbsd-compat/port-linux.c +++ b/openbsd-compat/port-linux.c @@ -1,4 +1,4 @@ -/* $Id: port-linux.c,v 1.10 2011/01/17 00:56:00 dtucker Exp $ */ +/* $Id: port-linux.c,v 1.11 2011/01/17 07:50:24 dtucker Exp $ */ /* * Copyright (c) 2005 Daniel Walsh @@ -266,7 +266,7 @@ oom_adjust_restore(void) FILE *fp; debug3("%s", __func__); - if (oom_adj_save == INT_MIN || oom_adj_save == NULL || + if (oom_adj_save == INT_MIN || oom_adj_path == NULL || (fp = fopen(oom_adj_path, "w")) == NULL) return; -- cgit v1.2.3