Bugzilla – Attachment 1740 Details for
Bug 1470
adjust Linux out-of-memory killer to stop sshd being killed
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
openssh-linux-oom_kill.patch
openssh-linux-oom_kill.patch (text/plain), 4.62 KB, created by
Darren Tucker
on 2009-12-07 12:04:46 AEDT
(
hide
)
Description:
openssh-linux-oom_kill.patch
Filename:
MIME Type:
Creator:
Darren Tucker
Created:
2009-12-07 12:04:46 AEDT
Size:
4.62 KB
patch
obsolete
>? build >Index: configure.ac >=================================================================== >RCS file: /var/cvs/openssh/configure.ac,v >retrieving revision 1.431 >diff -u -p -r1.431 configure.ac >--- configure.ac 7 Dec 2009 00:15:43 -0000 1.431 >+++ configure.ac 7 Dec 2009 01:01:43 -0000 >@@ -589,6 +589,7 @@ main() { if (NSVersionOfRunTimeLibrary(" > if it doesn't return EOPNOTSUPP.]) > AC_DEFINE(_PATH_BTMP, "/var/log/btmp", [log for bad login attempts]) > AC_DEFINE(USE_BTMP) >+ AC_DEFINE(LINUX_OOM_ADJUST, 1, [Adjust Linux out-of-memory killer]) > inet6_default_4in6=yes > case `uname -r` in > 1.*|2.0.*) >Index: platform.c >=================================================================== >RCS file: /var/cvs/openssh/platform.c,v >retrieving revision 1.1 >diff -u -p -r1.1 platform.c >--- platform.c 30 Aug 2006 17:24:41 -0000 1.1 >+++ platform.c 7 Dec 2009 01:01:43 -0000 >@@ -22,6 +22,15 @@ > #include "openbsd-compat/openbsd-compat.h" > > void >+platform_init(void) >+{ >+#ifdef LINUX_OOM_ADJUST >+ /* Adjust out-of-memory killer so listening process is not killed */ >+ oom_adjust_setup(); >+#endif >+} >+ >+void > platform_pre_fork(void) > { > #ifdef USE_SOLARIS_PROCESS_CONTRACTS >@@ -42,5 +51,8 @@ platform_post_fork_child(void) > { > #ifdef USE_SOLARIS_PROCESS_CONTRACTS > solaris_contract_post_fork_child(); >+#endif >+#ifdef LINUX_OOM_ADJUST >+ oom_adjust_restore(); > #endif > } >Index: platform.h >=================================================================== >RCS file: /var/cvs/openssh/platform.h,v >retrieving revision 1.1 >diff -u -p -r1.1 platform.h >--- platform.h 30 Aug 2006 17:24:41 -0000 1.1 >+++ platform.h 7 Dec 2009 01:01:43 -0000 >@@ -18,6 +18,7 @@ > > #include <sys/types.h> > >+void platform_init(void); > void platform_pre_fork(void); > void platform_post_fork_parent(pid_t child_pid); > void platform_post_fork_child(void); >Index: sshd.c >=================================================================== >RCS file: /var/cvs/openssh/sshd.c,v >retrieving revision 1.387 >diff -u -p -r1.387 sshd.c >--- sshd.c 18 Nov 2009 06:48:30 -0000 1.387 >+++ sshd.c 7 Dec 2009 01:01:43 -0000 >@@ -1652,6 +1652,8 @@ main(int ac, char **av) > /* ignore SIGPIPE */ > signal(SIGPIPE, SIG_IGN); > >+ platform_init(); >+ > /* Get a connection, either from inetd or a listening TCP socket */ > if (inetd_flag) { > server_accept_inetd(&sock_in, &sock_out); >Index: openbsd-compat/port-linux.c >=================================================================== >RCS file: /var/cvs/openssh/openbsd-compat/port-linux.c,v >retrieving revision 1.6 >diff -u -p -r1.6 port-linux.c >--- openbsd-compat/port-linux.c 24 Oct 2009 04:04:13 -0000 1.6 >+++ openbsd-compat/port-linux.c 7 Dec 2009 01:01:43 -0000 >@@ -27,8 +27,15 @@ > #include <stdarg.h> > #include <string.h> > >-#ifdef WITH_SELINUX >+#if defined(LINUX_OOM_ADJUST) || defined(WITH_SELINUX) > #include "log.h" >+#endif >+ >+#ifdef LINUX_OOM_ADJUST >+#include <stdio.h> >+#endif >+ >+#ifdef WITH_SELINUX > #include "xmalloc.h" > #include "port-linux.h" > >@@ -204,3 +211,53 @@ ssh_selinux_change_context(const char *n > xfree(newctx); > } > #endif /* WITH_SELINUX */ >+ >+#ifdef LINUX_OOM_ADJUST >+#define OOM_ADJ_PATH "/proc/self/oom_adj" >+#define OOM_ADJ_NOKILL -17 /* disables OOM */ >+ >+static int oom_adj_save; >+ >+/* >+ * Tell the kernel's out-of-memory killer to avoid sshd. >+ * Returns the previous oom_adj value or zero. >+ */ >+void >+oom_adjust_setup(void) >+{ >+ FILE *fp; >+ >+ if ((fp = fopen(OOM_ADJ_PATH, "r+")) != NULL) { >+ if (fscanf(fp, "%d", &oom_adj_save) != 1) >+ logit("error reading %s: %s", OOM_ADJ_PATH, strerror(errno)); >+ else { >+ rewind(fp); >+ if (fprintf(fp, "%d\n", OOM_ADJ_NOKILL) <= 0) >+ logit("error writing %s: %s", >+ OOM_ADJ_PATH, strerror(errno)); >+ else >+ verbose("Set %s to %d", >+ OOM_ADJ_PATH, oom_adj_save); >+ } >+ fclose(fp); >+ } >+} >+ >+/* Restore the saved OOM adjustment */ >+void >+oom_adjust_restore(void) >+{ >+ FILE *fp; >+ >+ if ((fp = fopen(OOM_ADJ_PATH, "w")) == NULL) >+ return; >+ >+ if (fprintf(fp, "%d\n", oom_adj_save) <= 0) >+ logit("error writing %s: %s", OOM_ADJ_PATH, strerror(errno)); >+ else >+ verbose("Set %s to %d", OOM_ADJ_PATH, oom_adj_save); >+ >+ fclose(fp); >+ return; >+} >+#endif >Index: openbsd-compat/port-linux.h >=================================================================== >RCS file: /var/cvs/openssh/openbsd-compat/port-linux.h,v >retrieving revision 1.3 >diff -u -p -r1.3 port-linux.h >--- openbsd-compat/port-linux.h 24 Oct 2009 04:04:13 -0000 1.3 >+++ openbsd-compat/port-linux.h 7 Dec 2009 01:01:43 -0000 >@@ -26,4 +26,9 @@ void ssh_selinux_setup_exec_context(char > void ssh_selinux_change_context(const char *); > #endif > >+#ifdef LINUX_OOM_ADJUST >+void oom_adjust_restore(void); >+void oom_adjust_setup(void); >+#endif >+ > #endif /* ! _PORT_LINUX_H */
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 1470
:
1507
|
1712
|
1740
|
1741
|
1742