summaryrefslogtreecommitdiff
path: root/openbsd-compat
diff options
context:
space:
mode:
authorColin Watson <cjwatson@debian.org>2009-01-14 11:35:56 +0000
committerColin Watson <cjwatson@debian.org>2009-01-14 11:35:56 +0000
commit6399215a54a22845b1310610011c9229e248e1be (patch)
tree056b6568f685ce75a9f8a08af946fc34cd48ad75 /openbsd-compat
parent7461980ced1a1e6ca438279b437c283ae3495833 (diff)
Open /proc/self/oom_adj with O_RDONLY or O_WRONLY as necessary, rather
than O_RDWR.
Diffstat (limited to 'openbsd-compat')
-rw-r--r--openbsd-compat/port-linux.c10
-rw-r--r--openbsd-compat/port-linux.h1
2 files changed, 5 insertions, 6 deletions
diff --git a/openbsd-compat/port-linux.c b/openbsd-compat/port-linux.c
index bc4924727..b7142ba90 100644
--- a/openbsd-compat/port-linux.c
+++ b/openbsd-compat/port-linux.c
@@ -197,10 +197,10 @@ ssh_selinux_setup_pty(char *pwname, const char *tty)
197 197
198#ifdef OOM_ADJUST 198#ifdef OOM_ADJUST
199/* Get the out-of-memory adjustment file for the current process */ 199/* Get the out-of-memory adjustment file for the current process */
200int 200static int
201oom_adj_open(void) 201oom_adj_open(int oflag)
202{ 202{
203 int fd = open("/proc/self/oom_adj", O_RDWR); 203 int fd = open("/proc/self/oom_adj", oflag);
204 if (fd < 0) 204 if (fd < 0)
205 logit("error opening /proc/self/oom_adj: %s", strerror(errno)); 205 logit("error opening /proc/self/oom_adj: %s", strerror(errno));
206 return fd; 206 return fd;
@@ -211,7 +211,7 @@ int
211oom_adj_get(char *buf, size_t maxlen) 211oom_adj_get(char *buf, size_t maxlen)
212{ 212{
213 ssize_t n; 213 ssize_t n;
214 int fd = oom_adj_open(); 214 int fd = oom_adj_open(O_RDONLY);
215 if (fd < 0) 215 if (fd < 0)
216 return -1; 216 return -1;
217 n = read(fd, buf, maxlen); 217 n = read(fd, buf, maxlen);
@@ -228,7 +228,7 @@ int
228oom_adj_set(const char *buf) 228oom_adj_set(const char *buf)
229{ 229{
230 ssize_t n; 230 ssize_t n;
231 int fd = oom_adj_open(); 231 int fd = oom_adj_open(O_WRONLY);
232 if (fd < 0) 232 if (fd < 0)
233 return -1; 233 return -1;
234 n = write(fd, buf, strlen(buf)); 234 n = write(fd, buf, strlen(buf));
diff --git a/openbsd-compat/port-linux.h b/openbsd-compat/port-linux.h
index 2a3271a93..6e6a8acfd 100644
--- a/openbsd-compat/port-linux.h
+++ b/openbsd-compat/port-linux.h
@@ -26,7 +26,6 @@ void ssh_selinux_setup_exec_context(char *);
26#endif 26#endif
27 27
28#ifdef OOM_ADJUST 28#ifdef OOM_ADJUST
29int oom_adj_open(void);
30int oom_adj_get(char *buf, size_t maxlen); 29int oom_adj_get(char *buf, size_t maxlen);
31int oom_adj_set(const char *buf); 30int oom_adj_set(const char *buf);
32#endif 31#endif