Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Side by Side Diff: sandbox/linux/suid/process_util_linux.c

Issue 467058: Linux: Adjust /proc/pid/oom_adj to sacrifice plugin and renderer processes to... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sandbox/linux/suid/process_util.h ('k') | sandbox/linux/suid/sandbox.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // The following is the C version of code from base/process_utils_linux.cc.
6 // We shouldn't link against C++ code in a setuid binary.
7
8 #include "process_util.h"
9
10 #include <fcntl.h>
11 #include <limits.h>
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <string.h>
15 #include <sys/stat.h>
16 #include <sys/types.h>
17 #include <unistd.h>
18
19 bool AdjustOOMScore(pid_t process, int score) {
20 if (score < 0 || score > 15)
21 return false;
22
23 char oom_adj[PATH_MAX];
agl 2009/12/09 21:19:14 Rather than use PATH_MAX here, it would be clearer
24 snprintf(oom_adj, sizeof(oom_adj), "/proc/%lu", process);
25
26 struct stat statbuf;
27 if (stat(oom_adj, &statbuf) < 0)
28 return false;
29 if (getuid() != statbuf.st_uid)
agl 2009/12/09 21:19:14 If one was being really careful one would open the
30 return false;
31
32 strcat(oom_adj, "/oom_adj");
33 int fd = open(oom_adj, O_WRONLY);
34 if (fd < 0)
35 return false;
36
37 char buf[3];
38 snprintf(buf, sizeof(buf), "%d", score);
39 size_t len = strlen(buf);
40
41 ssize_t bytes_written = write(fd, buf, len);
42 close(fd);
43 return (bytes_written == len);
44 }
OLDNEW
« no previous file with comments | « sandbox/linux/suid/process_util.h ('k') | sandbox/linux/suid/sandbox.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698