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

Collapse All | Expand All

(-)configure.ac (+1 lines)
Lines 589-594 main() { if (NSVersionOfRunTimeLibrary(" 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(LINUX_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.*)
(-)platform.c (+12 lines)
Lines 22-27 Link Here
22
#include "openbsd-compat/openbsd-compat.h"
22
#include "openbsd-compat/openbsd-compat.h"
23
23
24
void
24
void
25
platform_pre_listen(void)
26
{
27
#ifdef LINUX_OOM_ADJUST
28
	/* Adjust out-of-memory killer so listening process is not killed */
29
	oom_adjust_setup();
30
#endif
31
}
32
33
void
25
platform_pre_fork(void)
34
platform_pre_fork(void)
26
{
35
{
27
#ifdef USE_SOLARIS_PROCESS_CONTRACTS
36
#ifdef USE_SOLARIS_PROCESS_CONTRACTS
Lines 42-46 platform_post_fork_child(void) Link Here
42
{
51
{
43
#ifdef USE_SOLARIS_PROCESS_CONTRACTS
52
#ifdef USE_SOLARIS_PROCESS_CONTRACTS
44
	solaris_contract_post_fork_child();
53
	solaris_contract_post_fork_child();
54
#endif
55
#ifdef LINUX_OOM_ADJUST
56
	oom_adjust_restore();
45
#endif
57
#endif
46
}
58
}
(-)platform.h (+1 lines)
Lines 18-23 Link Here
18
18
19
#include <sys/types.h>
19
#include <sys/types.h>
20
20
21
void platform_pre_listen(void);
21
void platform_pre_fork(void);
22
void platform_pre_fork(void);
22
void platform_post_fork_parent(pid_t child_pid);
23
void platform_post_fork_parent(pid_t child_pid);
23
void platform_post_fork_child(void);
24
void platform_post_fork_child(void);
(-)sshd.c (+2 lines)
Lines 1652-1661 main(int ac, char **av) Link Here
1652
	/* ignore SIGPIPE */
1652
	/* ignore SIGPIPE */
1653
	signal(SIGPIPE, SIG_IGN);
1653
	signal(SIGPIPE, SIG_IGN);
1654
1654
1655
1655
	/* Get a connection, either from inetd or a listening TCP socket */
1656
	/* Get a connection, either from inetd or a listening TCP socket */
1656
	if (inetd_flag) {
1657
	if (inetd_flag) {
1657
		server_accept_inetd(&sock_in, &sock_out);
1658
		server_accept_inetd(&sock_in, &sock_out);
1658
	} else {
1659
	} else {
1660
		platform_pre_listen();
1659
		server_listen();
1661
		server_listen();
1660
1662
1661
		if (options.protocol & SSH_PROTO_1)
1663
		if (options.protocol & SSH_PROTO_1)
(-)openbsd-compat/port-linux.c (-1 / +60 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(LINUX_OOM_ADJUST) || defined(WITH_SELINUX)
31
#include "log.h"
31
#include "log.h"
32
#endif
33
34
#ifdef LINUX_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 ssh_selinux_change_context(const char *n Link Here
204
	xfree(newctx);
211
	xfree(newctx);
205
}
212
}
206
#endif /* WITH_SELINUX */
213
#endif /* WITH_SELINUX */
214
215
#ifdef LINUX_OOM_ADJUST
216
#define OOM_ADJ_PATH	"/proc/self/oom_adj"
217
#define OOM_ADJ_NOKILL	-17  /* disables OOM */
218
219
static int oom_adj_save;
220
221
/*
222
 * Tell the kernel's out-of-memory killer to avoid sshd.
223
 * Returns the previous oom_adj value or zero.
224
 */
225
void
226
oom_adjust_setup(void)
227
{
228
	FILE *fp;
229
230
	debug3("%s", __func__);
231
	if ((fp = fopen(OOM_ADJ_PATH, "r+")) != NULL) {
232
		if (fscanf(fp, "%d", &oom_adj_save) != 1)
233
			logit("error reading %s: %s", OOM_ADJ_PATH, strerror(errno));
234
		else {
235
			rewind(fp);
236
			if (fprintf(fp, "%d\n", OOM_ADJ_NOKILL) <= 0)
237
				logit("error writing %s: %s",
238
				    OOM_ADJ_PATH, strerror(errno));
239
			else
240
				verbose("Set %s from %d to %d",
241
				    OOM_ADJ_PATH, oom_adj_save, OOM_ADJ_NOKILL);
242
		}
243
		fclose(fp);
244
	}
245
}
246
247
/* Restore the saved OOM adjustment */
248
void
249
oom_adjust_restore(void)
250
{
251
	FILE *fp;
252
253
	debug3("%s", __func__);
254
	if ((fp = fopen(OOM_ADJ_PATH, "w")) == NULL)
255
		return;
256
257
	if (fprintf(fp, "%d\n", oom_adj_save) <= 0)
258
		logit("error writing %s: %s", OOM_ADJ_PATH, strerror(errno));
259
	else
260
		verbose("Set %s to %d", OOM_ADJ_PATH, oom_adj_save);
261
262
	fclose(fp);
263
	return;
264
}
265
#endif
(-)openbsd-compat/port-linux.h (+5 lines)
Lines 26-29 void ssh_selinux_setup_exec_context(char 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 LINUX_OOM_ADJUST
30
void oom_adjust_restore(void);
31
void oom_adjust_setup(void);
32
#endif
33
29
#endif /* ! _PORT_LINUX_H */
34
#endif /* ! _PORT_LINUX_H */

Return to bug 1470