View | Details | Raw Unified | Return to bug 1470 | Differences between
and this patch

Collapse All | Expand All

(-)configure.ac (+1 lines)
Lines 589-594 Link Here
589
		if it doesn't return EOPNOTSUPP.])
589
		if it doesn't return EOPNOTSUPP.])
590
	AC_DEFINE(_PATH_BTMP, "/var/log/btmp", [log for bad login attempts])
590
	AC_DEFINE(_PATH_BTMP, "/var/log/btmp", [log for bad login attempts])
591
	AC_DEFINE(USE_BTMP)
591
	AC_DEFINE(USE_BTMP)
592
	AC_DEFINE(OOM_ADJUST, 1, [Adjust Linux out-of-memory killer])
592
	inet6_default_4in6=yes
593
	inet6_default_4in6=yes
593
	case `uname -r` in
594
	case `uname -r` in
594
	1.*|2.0.*)
595
	1.*|2.0.*)
(-)sshd.c (+14 lines)
Lines 1253-1258 Link Here
1253
	Key *key;
1253
	Key *key;
1254
	Authctxt *authctxt;
1254
	Authctxt *authctxt;
1255
1255
1256
#ifdef OOM_ADJUST
1257
	/* Linux out-of-memory killer adjustment */
1258
	static int oom_adj_save;
1259
#endif
1260
1256
#ifdef HAVE_SECUREWARE
1261
#ifdef HAVE_SECUREWARE
1257
	(void)set_auth_parameters(ac, av);
1262
	(void)set_auth_parameters(ac, av);
1258
#endif
1263
#endif
Lines 1658-1663 Link Here
1658
	/* ignore SIGPIPE */
1663
	/* ignore SIGPIPE */
1659
	signal(SIGPIPE, SIG_IGN);
1664
	signal(SIGPIPE, SIG_IGN);
1660
1665
1666
#ifdef OOM_ADJUST
1667
	/* Adjust out-of-memory killer */
1668
	oom_adj_save = oom_adjust_setup();
1669
#endif
1670
1661
	/* Get a connection, either from inetd or a listening TCP socket */
1671
	/* Get a connection, either from inetd or a listening TCP socket */
1662
	if (inetd_flag) {
1672
	if (inetd_flag) {
1663
		server_accept_inetd(&sock_in, &sock_out);
1673
		server_accept_inetd(&sock_in, &sock_out);
Lines 1695-1700 Link Here
1695
1705
1696
	/* This is the child processing a new connection. */
1706
	/* This is the child processing a new connection. */
1697
	setproctitle("%s", "[accepted]");
1707
	setproctitle("%s", "[accepted]");
1708
1709
#ifdef OOM_ADJUST
1710
	oom_adjust_restore(oom_adj_save);
1711
#endif
1698
1712
1699
	/*
1713
	/*
1700
	 * Create a new session and process group since the 4.4BSD
1714
	 * Create a new session and process group since the 4.4BSD
(-)openbsd-compat/port-linux.c (-1 / +61 lines)
Lines 27-34 Link Here
27
#include <stdarg.h>
27
#include <stdarg.h>
28
#include <string.h>
28
#include <string.h>
29
29
30
#ifdef WITH_SELINUX
30
#if defined(OOM_ADJUST) || defined(WITH_SELINUX)
31
#include "log.h"
31
#include "log.h"
32
#endif
33
34
#ifdef OOM_ADJUST
35
#include <stdio.h>
36
#endif
37
38
#ifdef WITH_SELINUX
32
#include "xmalloc.h"
39
#include "xmalloc.h"
33
#include "port-linux.h"
40
#include "port-linux.h"
34
41
Lines 204-206 Link Here
204
	xfree(newctx);
211
	xfree(newctx);
205
}
212
}
206
#endif /* WITH_SELINUX */
213
#endif /* WITH_SELINUX */
214
215
#ifdef OOM_ADJUST
216
#define OOM_ADJ_PATH	"/proc/self/oom_adj"
217
#define OOM_ADJ_VALUE	-17
218
219
/*
220
 * Tell the kernel's out-of-memory killer to avoid sshd.
221
 * Returns the previous oom_adj value or zero.
222
 */
223
int
224
oom_adjust_setup(void)
225
{
226
	int oom_adj_save = 0;
227
	FILE *fp;
228
229
	if ((fp = fopen(OOM_ADJ_PATH, "r+")) != NULL)
230
	{
231
		if (fscanf(fp, "%d", &oom_adj_save) != 1)
232
			logit("error reading %s: %s", OOM_ADJ_PATH, strerror(errno));
233
		else 
234
		{
235
			rewind(fp);
236
			if (fprintf(fp, "%d\n", OOM_ADJ_VALUE) <= 0)
237
				logit("error writing %s: %s", 
238
					OOM_ADJ_PATH, strerror(errno));
239
			else
240
				verbose("Set %s to %d", 
241
					OOM_ADJ_PATH, oom_adj_save);
242
		}
243
244
		fclose(fp);
245
	}
246
	return oom_adj_save;
247
}
248
249
/* Restore the saved OOM adjustment */
250
void
251
oom_adjust_restore(int oom_adj)
252
{
253
	FILE *fp;
254
255
	if ((fp = fopen(OOM_ADJ_PATH, "w")) == NULL)
256
		return;
257
258
	if (fprintf(fp, "%d\n", oom_adj) <= 0)
259
		logit("error writing %s: %s", OOM_ADJ_PATH, strerror(errno));
260
	else
261
		verbose("Set %s to %d", OOM_ADJ_PATH, oom_adj);
262
263
	fclose(fp);
264
	return;
265
}
266
#endif
(-)openbsd-compat/port-linux.h (+5 lines)
Lines 26-29 Link Here
26
void ssh_selinux_change_context(const char *);
26
void ssh_selinux_change_context(const char *);
27
#endif
27
#endif
28
28
29
#ifdef OOM_ADJUST
30
void oom_adjust_restore(int oom_adj);
31
int oom_adjust_setup(void);
32
#endif
33
29
#endif /* ! _PORT_LINUX_H */
34
#endif /* ! _PORT_LINUX_H */

Return to bug 1470