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

Collapse All | Expand All

(-)openbsd-compat/port-linux.c (-18 / +35 lines)
Lines 208-221 ssh_selinux_change_context(const char *n Link Here
208
#endif /* WITH_SELINUX */
208
#endif /* WITH_SELINUX */
209
209
210
#ifdef LINUX_OOM_ADJUST
210
#ifdef LINUX_OOM_ADJUST
211
#define OOM_ADJ_PATH	"/proc/self/oom_adj"
212
/*
211
/*
213
 * The magic "don't kill me", as documented in eg:
212
 * The magic "don't kill me" values, old and new, as documented in eg:
214
 * http://lxr.linux.no/#linux+v2.6.32/Documentation/filesystems/proc.txt
213
 * http://lxr.linux.no/#linux+v2.6.32/Documentation/filesystems/proc.txt
214
 * http://lxr.linux.no/#linux+v2.6.36/Documentation/filesystems/proc.txt
215
 */
215
 */
216
#define OOM_ADJ_NOKILL	-17
217
216
218
static int oom_adj_save = INT_MIN;
217
static int oom_adj_save = INT_MIN;
218
static char *oom_adj_path = NULL;
219
struct {
220
	char *path;
221
	int value;
222
} oom_adjust[] = {
223
	{"/proc/self/oom_score_adj", -1000},	/* kernels >= 2.6.36 */
224
	{"/proc/self/oom_adj", -17},		/* kernels <= 2.6.35 */
225
	{NULL, 0},
226
};
219
227
220
/*
228
/*
221
 * Tell the kernel's out-of-memory killer to avoid sshd.
229
 * Tell the kernel's out-of-memory killer to avoid sshd.
Lines 224-246 static int oom_adj_save = INT_MIN; Link Here
224
void
232
void
225
oom_adjust_setup(void)
233
oom_adjust_setup(void)
226
{
234
{
235
	int i, value;
227
	FILE *fp;
236
	FILE *fp;
228
237
229
	debug3("%s", __func__);
238
	debug3("%s", __func__);
230
	if ((fp = fopen(OOM_ADJ_PATH, "r+")) != NULL) {
239
	 for (i = 0; oom_adjust[i].path != NULL; i++) {
231
		if (fscanf(fp, "%d", &oom_adj_save) != 1)
240
		oom_adj_path = oom_adjust[i].path;
232
			verbose("error reading %s: %s", OOM_ADJ_PATH, strerror(errno));
241
		value = oom_adjust[i].value;
233
		else {
242
		if ((fp = fopen(oom_adj_path, "r+")) != NULL) {
234
			rewind(fp);
243
			if (fscanf(fp, "%d", &oom_adj_save) != 1)
235
			if (fprintf(fp, "%d\n", OOM_ADJ_NOKILL) <= 0)
244
				verbose("error reading %s: %s", oom_adj_path,
236
				verbose("error writing %s: %s",
245
				    strerror(errno));
237
				    OOM_ADJ_PATH, strerror(errno));
246
			else {
238
			else
247
				rewind(fp);
239
				verbose("Set %s from %d to %d",
248
				if (fprintf(fp, "%d\n", value) <= 0)
240
				    OOM_ADJ_PATH, oom_adj_save, OOM_ADJ_NOKILL);
249
					verbose("error writing %s: %s",
250
					   oom_adj_path, strerror(errno));
251
				else
252
					verbose("Set %s from %d to %d",
253
					   oom_adj_path, oom_adj_save, value);
254
			}
255
			fclose(fp);
256
			return;
241
		}
257
		}
242
		fclose(fp);
243
	}
258
	}
259
	oom_adj_path = NULL;
244
}
260
}
245
261
246
/* Restore the saved OOM adjustment */
262
/* Restore the saved OOM adjustment */
Lines 250-262 oom_adjust_restore(void) Link Here
250
	FILE *fp;
266
	FILE *fp;
251
267
252
	debug3("%s", __func__);
268
	debug3("%s", __func__);
253
	if (oom_adj_save == INT_MIN || (fp = fopen(OOM_ADJ_PATH, "w")) == NULL)
269
	if (oom_adj_save == INT_MIN || oom_adj_save == NULL ||
270
	    (fp = fopen(oom_adj_path, "w")) == NULL)
254
		return;
271
		return;
255
272
256
	if (fprintf(fp, "%d\n", oom_adj_save) <= 0)
273
	if (fprintf(fp, "%d\n", oom_adj_save) <= 0)
257
		verbose("error writing %s: %s", OOM_ADJ_PATH, strerror(errno));
274
		verbose("error writing %s: %s", oom_adj_path, strerror(errno));
258
	else
275
	else
259
		verbose("Set %s to %d", OOM_ADJ_PATH, oom_adj_save);
276
		verbose("Set %s to %d", oom_adj_path, oom_adj_save);
260
277
261
	fclose(fp);
278
	fclose(fp);
262
	return;
279
	return;

Return to bug 1838