|
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 |