Bugzilla – Attachment 1712 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]
[patch]
Revised patch for Linux OOM killer
linux-oom.diff (text/plain), 3.80 KB, created by
Iain Morgan
on 2009-10-28 11:28:14 AEDT
(
hide
)
Description:
Revised patch for Linux OOM killer
Filename:
MIME Type:
Creator:
Iain Morgan
Created:
2009-10-28 11:28:14 AEDT
Size:
3.80 KB
patch
obsolete
>Index: configure.ac >=================================================================== >RCS file: /cvs/openssh/configure.ac,v >retrieving revision 1.430 >diff -u -b -r1.430 configure.ac >--- configure.ac 11 Oct 2009 10:50:20 -0000 1.430 >+++ configure.ac 28 Oct 2009 00:03:19 -0000 >@@ -589,6 +589,7 @@ > if it doesn't return EOPNOTSUPP.]) > AC_DEFINE(_PATH_BTMP, "/var/log/btmp", [log for bad login attempts]) > AC_DEFINE(USE_BTMP) >+ AC_DEFINE(OOM_ADJUST, 1, [Adjust Linux out-of-memory killer]) > inet6_default_4in6=yes > case `uname -r` in > 1.*|2.0.*) >Index: sshd.c >=================================================================== >RCS file: /cvs/openssh/sshd.c,v >retrieving revision 1.386 >diff -u -b -r1.386 sshd.c >--- sshd.c 21 Jun 2009 10:26:17 -0000 1.386 >+++ sshd.c 28 Oct 2009 00:03:19 -0000 >@@ -1253,6 +1253,11 @@ > Key *key; > Authctxt *authctxt; > >+#ifdef OOM_ADJUST >+ /* Linux out-of-memory killer adjustment */ >+ static int oom_adj_save; >+#endif >+ > #ifdef HAVE_SECUREWARE > (void)set_auth_parameters(ac, av); > #endif >@@ -1658,6 +1663,11 @@ > /* ignore SIGPIPE */ > signal(SIGPIPE, SIG_IGN); > >+#ifdef OOM_ADJUST >+ /* Adjust out-of-memory killer */ >+ oom_adj_save = oom_adjust_setup(); >+#endif >+ > /* Get a connection, either from inetd or a listening TCP socket */ > if (inetd_flag) { > server_accept_inetd(&sock_in, &sock_out); >@@ -1695,6 +1705,10 @@ > > /* This is the child processing a new connection. */ > setproctitle("%s", "[accepted]"); >+ >+#ifdef OOM_ADJUST >+ oom_adjust_restore(oom_adj_save); >+#endif > > /* > * Create a new session and process group since the 4.4BSD >Index: openbsd-compat/port-linux.c >=================================================================== >RCS file: /cvs/openssh/openbsd-compat/port-linux.c,v >retrieving revision 1.6 >diff -u -b -r1.6 port-linux.c >--- openbsd-compat/port-linux.c 24 Oct 2009 04:04:13 -0000 1.6 >+++ openbsd-compat/port-linux.c 28 Oct 2009 00:03:19 -0000 >@@ -27,8 +27,15 @@ > #include <stdarg.h> > #include <string.h> > >-#ifdef WITH_SELINUX >+#if defined(OOM_ADJUST) || defined(WITH_SELINUX) > #include "log.h" >+#endif >+ >+#ifdef OOM_ADJUST >+#include <stdio.h> >+#endif >+ >+#ifdef WITH_SELINUX > #include "xmalloc.h" > #include "port-linux.h" > >@@ -204,3 +211,56 @@ > xfree(newctx); > } > #endif /* WITH_SELINUX */ >+ >+#ifdef OOM_ADJUST >+#define OOM_ADJ_PATH "/proc/self/oom_adj" >+#define OOM_ADJ_VALUE -17 >+ >+/* >+ * Tell the kernel's out-of-memory killer to avoid sshd. >+ * Returns the previous oom_adj value or zero. >+ */ >+int >+oom_adjust_setup(void) >+{ >+ int oom_adj_save = 0; >+ 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_VALUE) <= 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 oom_adj_save; >+} >+ >+/* Restore the saved OOM adjustment */ >+void >+oom_adjust_restore(int oom_adj) >+{ >+ FILE *fp; >+ >+ if ((fp = fopen(OOM_ADJ_PATH, "w")) == NULL) >+ return; >+ >+ if (fprintf(fp, "%d\n", oom_adj) <= 0) >+ logit("error writing %s: %s", OOM_ADJ_PATH, strerror(errno)); >+ else >+ verbose("Set %s to %d", OOM_ADJ_PATH, oom_adj); >+ >+ fclose(fp); >+ return; >+} >+#endif >Index: openbsd-compat/port-linux.h >=================================================================== >RCS file: /cvs/openssh/openbsd-compat/port-linux.h,v >retrieving revision 1.3 >diff -u -b -r1.3 port-linux.h >--- openbsd-compat/port-linux.h 24 Oct 2009 04:04:13 -0000 1.3 >+++ openbsd-compat/port-linux.h 28 Oct 2009 00:03:19 -0000 >@@ -26,4 +26,9 @@ > void ssh_selinux_change_context(const char *); > #endif > >+#ifdef OOM_ADJUST >+void oom_adjust_restore(int oom_adj); >+int 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 Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 1470
:
1507
| 1712 |
1740
|
1741
|
1742