Chromium Code Reviews| Index: sandbox/linux/suid/process_util_linux.c |
| diff --git a/sandbox/linux/suid/process_util_linux.c b/sandbox/linux/suid/process_util_linux.c |
| index 17453def621006ca2d824c45c21cb922d6849d60..31886e285cf4dac44398418703deddafcb96e470 100644 |
| --- a/sandbox/linux/suid/process_util_linux.c |
| +++ b/sandbox/linux/suid/process_util_linux.c |
| @@ -1,4 +1,4 @@ |
| -// Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| @@ -20,7 +20,7 @@ |
| #include <unistd.h> |
| bool AdjustOOMScore(pid_t process, int score) { |
| - if (score < 0 || score > 15) |
| + if (score < 0 || score > 1000) |
|
stevenjb
2011/08/18 00:20:07
And in the darkness bind them?
Greg Spencer (Chromium)
2011/08/18 23:10:50
Also moved into a constant.
|
| return false; |
| char oom_adj[27]; // "/proc/" + log_10(2**64) + "\0" |
| @@ -41,13 +41,24 @@ bool AdjustOOMScore(pid_t process, int score) { |
| return false; |
| } |
| - const int fd = openat(dirfd, "oom_adj", O_WRONLY); |
| + int fd = openat(dirfd, "oom_score_adj", O_WRONLY); |
| + if (fd < 0) { |
| + // We failed to open oom_score_adj, so let's try for the older |
| + // oom_adj file instead. |
| + fd = openat(dirfd, "oom_adj", O_WRONLY); |
| + if (fd < 0) { |
| + // Nope, that doesn't work either. |
| + return false; |
| + } else { |
| + // If we're using the old oom_adj file, the allowed range is now |
| + // [0, 15], so we scale the score. This may result in some |
| + // aliasing of values, of course. |
| + score = score * 15 / 1000; |
| + } |
| + } |
| close(dirfd); |
| - if (fd < 0) |
| - return false; |
| - |
| - char buf[3]; // 0 <= |score| <= 15; |
| + char buf[5]; // 0 <= |score| <= 1000; |
|
stevenjb
2011/08/18 00:20:07
Maybe size this for any 32 bit range?
Greg Spencer (Chromium)
2011/08/18 23:10:50
Done.
|
| snprintf(buf, sizeof(buf), "%d", score); |
| size_t len = strlen(buf); |