diff options
author | gspencer@chromium.org <gspencer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-03 20:30:43 +0000 |
---|---|---|
committer | gspencer@chromium.org <gspencer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-03 20:30:43 +0000 |
commit | 232ed4691df490e376c74ecf04f2f6092f03427f (patch) | |
tree | 3dd09707acccf9eb175e592b4f0fbade06a5015b /sandbox/linux/suid/sandbox.c | |
parent | 9a4fd693db2ee9e383f7a826d50bc63bc5bf7db0 (diff) | |
download | chromium_src-232ed4691df490e376c74ecf04f2f6092f03427f.zip chromium_src-232ed4691df490e376c74ecf04f2f6092f03427f.tar.gz chromium_src-232ed4691df490e376c74ecf04f2f6092f03427f.tar.bz2 |
This creates a field trial to determine the best level for low memory
notification.
It creates a field trial with 7 groups: default (kernel default
value), turning notification off (relying on OOM killer only), 0MB, 25MB, 50MB
margin, 100MB margin, and 200MB margin.
Also, in order to set parameters for the trial, this CL creates
an API for setting the low memory margin.
BUG=chromium-os:20080
TEST=Ran on device several times, checked that the memory margin was
set correctly when the session started, and that different trial groups
were selected.
Review URL: http://codereview.chromium.org/10206029
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@135205 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sandbox/linux/suid/sandbox.c')
-rw-r--r-- | sandbox/linux/suid/sandbox.c | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/sandbox/linux/suid/sandbox.c b/sandbox/linux/suid/sandbox.c index a83291e..41a68c7 100644 --- a/sandbox/linux/suid/sandbox.c +++ b/sandbox/linux/suid/sandbox.c @@ -4,6 +4,8 @@ // http://code.google.com/p/chromium/wiki/LinuxSUIDSandbox +#include "sandbox.h" + #define _GNU_SOURCE #include <asm/unistd.h> #include <errno.h> @@ -38,7 +40,6 @@ #define CLONE_NEWNET 0x40000000 #endif -static const char kAdjustOOMScoreSwitch[] = "--adjust-oom-score"; static const char kSandboxDescriptorEnvironmentVarName[] = "SBX_D"; static const char kSandboxHelperPidEnvironmentVarName[] = "SBX_HELPER_PID"; @@ -405,9 +406,10 @@ int main(int argc, char **argv) { // when you call it with --find-inode INODE_NUMBER. if (argc == 3 && (0 == strcmp(argv[1], kFindInodeSwitch))) { pid_t pid; - char* endptr; + char* endptr = NULL; + errno = 0; ino_t inode = strtoull(argv[2], &endptr, 10); - if (inode == ULLONG_MAX || *endptr) + if (inode == ULLONG_MAX || !endptr || *endptr || errno != 0) return 1; if (!FindProcessHoldingSocket(&pid, inode)) return 1; @@ -417,17 +419,31 @@ int main(int argc, char **argv) { // Likewise, we cannot adjust /proc/pid/oom_adj for sandboxed renderers // because those files are owned by root. So we need another helper here. if (argc == 4 && (0 == strcmp(argv[1], kAdjustOOMScoreSwitch))) { - char* endptr; + char* endptr = NULL; long score; + errno = 0; unsigned long pid_ul = strtoul(argv[2], &endptr, 10); - if (pid_ul == ULONG_MAX || *endptr) + if (pid_ul == ULONG_MAX || !endptr || *endptr || errno != 0) return 1; pid_t pid = pid_ul; + endptr = NULL; + errno = 0; score = strtol(argv[3], &endptr, 10); - if (score == LONG_MAX || score == LONG_MIN || *endptr) + if (score == LONG_MAX || score == LONG_MIN || + !endptr || *endptr || errno != 0) return 1; return AdjustOOMScore(pid, score); } +#if defined(OS_CHROMEOS) + if (argc == 3 && (0 == strcmp(argv[1], kAdjustLowMemMarginSwitch))) { + char* endptr = NULL; + errno = 0; + unsigned long margin_mb = strtoul(argv[2], &endptr, 10); + if (!endptr || *endptr || errno != 0) + return 1; + return AdjustLowMemoryMargin(margin_mb); + } +#endif if (!MoveToNewNamespaces()) return 1; |