summaryrefslogtreecommitdiff
path: root/openbsd-compat
diff options
context:
space:
mode:
Diffstat (limited to 'openbsd-compat')
-rw-r--r--openbsd-compat/port-linux.c56
-rw-r--r--openbsd-compat/port-linux.h6
2 files changed, 60 insertions, 2 deletions
diff --git a/openbsd-compat/port-linux.c b/openbsd-compat/port-linux.c
index 485929133..a9aa773ef 100644
--- a/openbsd-compat/port-linux.c
+++ b/openbsd-compat/port-linux.c
@@ -18,7 +18,7 @@
18 */ 18 */
19 19
20/* 20/*
21 * Linux-specific portability code - just SELinux support at present 21 * Linux-specific portability code
22 */ 22 */
23 23
24#include "includes.h" 24#include "includes.h"
@@ -27,11 +27,19 @@
27#include <stdarg.h> 27#include <stdarg.h>
28#include <string.h> 28#include <string.h>
29 29
30#ifdef OOM_ADJUST
31#include <sys/types.h>
32#include <sys/stat.h>
33#include <fcntl.h>
34#include <unistd.h>
35#endif
36
37#include "log.h"
38
30#ifdef WITH_SELINUX 39#ifdef WITH_SELINUX
31#include "key.h" 40#include "key.h"
32#include "hostfile.h" 41#include "hostfile.h"
33#include "auth.h" 42#include "auth.h"
34#include "log.h"
35#ifdef HAVE_GETSEUSERBYNAME 43#ifdef HAVE_GETSEUSERBYNAME
36#include "xmalloc.h" 44#include "xmalloc.h"
37#endif 45#endif
@@ -186,3 +194,47 @@ ssh_selinux_setup_pty(char *pwname, const char *tty)
186 debug3("%s: done", __func__); 194 debug3("%s: done", __func__);
187} 195}
188#endif /* WITH_SELINUX */ 196#endif /* WITH_SELINUX */
197
198#ifdef OOM_ADJUST
199/* Get the out-of-memory adjustment file for the current process */
200int
201oom_adj_open(void)
202{
203 int fd = open("/proc/self/oom_adj", O_RDWR);
204 if (fd < 0)
205 logit("error opening /proc/self/oom_adj: %s", strerror(errno));
206 return fd;
207}
208
209/* Get the current OOM adjustment */
210int
211oom_adj_get(char *buf, size_t maxlen)
212{
213 ssize_t n;
214 int fd = oom_adj_open();
215 if (fd < 0)
216 return -1;
217 n = read(fd, buf, maxlen);
218 if (n < 0)
219 logit("error reading /proc/self/oom_adj: %s", strerror(errno));
220 else
221 buf[n] = '\0';
222 close(fd);
223 return n < 0 ? -1 : 0;
224}
225
226/* Set the current OOM adjustment */
227int
228oom_adj_set(const char *buf)
229{
230 ssize_t n;
231 int fd = oom_adj_open();
232 if (fd < 0)
233 return -1;
234 n = write(fd, buf, strlen(buf));
235 if (n < 0)
236 logit("error writing /proc/self/oom_adj: %s", strerror(errno));
237 close(fd);
238 return n < 0 ? -1 : 0;
239}
240#endif
diff --git a/openbsd-compat/port-linux.h b/openbsd-compat/port-linux.h
index 05e520e1c..cb8a253c4 100644
--- a/openbsd-compat/port-linux.h
+++ b/openbsd-compat/port-linux.h
@@ -24,4 +24,10 @@ void ssh_selinux_setup_pty(char *, const char *);
24void ssh_selinux_setup_exec_context(char *); 24void ssh_selinux_setup_exec_context(char *);
25#endif 25#endif
26 26
27#ifdef OOM_ADJUST
28int oom_adj_open(void);
29int oom_adj_get(char *buf, size_t maxlen);
30int oom_adj_set(const char *buf);
31#endif
32
27#endif /* ! _PORT_LINUX_H */ 33#endif /* ! _PORT_LINUX_H */