|
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}, /* new values, 2.6.36 and up */ |
| 224 |
{"/proc/self/oom_adj", -17}, /* old values, 2.6.35 and down */ |
| 225 |
}; |
| 219 |
|
226 |
|
| 220 |
/* |
227 |
/* |
| 221 |
* Tell the kernel's out-of-memory killer to avoid sshd. |
228 |
* 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 |
231 |
void |
| 225 |
oom_adjust_setup(void) |
232 |
oom_adjust_setup(void) |
| 226 |
{ |
233 |
{ |
|
|
234 |
int i, value; |
| 227 |
FILE *fp; |
235 |
FILE *fp; |
| 228 |
|
236 |
|
| 229 |
debug3("%s", __func__); |
237 |
debug3("%s", __func__); |
| 230 |
if ((fp = fopen(OOM_ADJ_PATH, "r+")) != NULL) { |
238 |
for (i = 0; i < 2; i++) { |
| 231 |
if (fscanf(fp, "%d", &oom_adj_save) != 1) |
239 |
oom_adj_path = oom_adjust[i].path; |
| 232 |
verbose("error reading %s: %s", OOM_ADJ_PATH, strerror(errno)); |
240 |
value = oom_adjust[i].value; |
| 233 |
else { |
241 |
if ((fp = fopen(oom_adj_path, "r+")) != NULL) { |
| 234 |
rewind(fp); |
242 |
if (fscanf(fp, "%d", &oom_adj_save) != 1) |
| 235 |
if (fprintf(fp, "%d\n", OOM_ADJ_NOKILL) <= 0) |
243 |
verbose("error reading %s: %s", oom_adj_path, |
| 236 |
verbose("error writing %s: %s", |
244 |
strerror(errno)); |
| 237 |
OOM_ADJ_PATH, strerror(errno)); |
245 |
else { |
| 238 |
else |
246 |
rewind(fp); |
| 239 |
verbose("Set %s from %d to %d", |
247 |
if (fprintf(fp, "%d\n", value) <= 0) |
| 240 |
OOM_ADJ_PATH, oom_adj_save, OOM_ADJ_NOKILL); |
248 |
verbose("error writing %s: %s", |
|
|
249 |
oom_adj_path, strerror(errno)); |
| 250 |
else |
| 251 |
verbose("Set %s from %d to %d", |
| 252 |
oom_adj_path, oom_adj_save, value); |
| 253 |
} |
| 254 |
fclose(fp); |
| 255 |
return; |
| 241 |
} |
256 |
} |
| 242 |
fclose(fp); |
|
|
| 243 |
} |
257 |
} |
|
|
258 |
oom_adj_path = NULL; |
| 244 |
} |
259 |
} |
| 245 |
|
260 |
|
| 246 |
/* Restore the saved OOM adjustment */ |
261 |
/* Restore the saved OOM adjustment */ |
|
Lines 250-262
oom_adjust_restore(void)
Link Here
|
| 250 |
FILE *fp; |
265 |
FILE *fp; |
| 251 |
|
266 |
|
| 252 |
debug3("%s", __func__); |
267 |
debug3("%s", __func__); |
| 253 |
if (oom_adj_save == INT_MIN || (fp = fopen(OOM_ADJ_PATH, "w")) == NULL) |
268 |
if (oom_adj_save == INT_MIN || oom_adj_save == NULL || |
|
|
269 |
(fp = fopen(oom_adj_path, "w")) == NULL) |
| 254 |
return; |
270 |
return; |
| 255 |
|
271 |
|
| 256 |
if (fprintf(fp, "%d\n", oom_adj_save) <= 0) |
272 |
if (fprintf(fp, "%d\n", oom_adj_save) <= 0) |
| 257 |
verbose("error writing %s: %s", OOM_ADJ_PATH, strerror(errno)); |
273 |
verbose("error writing %s: %s", oom_adj_path, strerror(errno)); |
| 258 |
else |
274 |
else |
| 259 |
verbose("Set %s to %d", OOM_ADJ_PATH, oom_adj_save); |
275 |
verbose("Set %s to %d", oom_adj_path, oom_adj_save); |
| 260 |
|
276 |
|
| 261 |
fclose(fp); |
277 |
fclose(fp); |
| 262 |
return; |
278 |
return; |