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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sandbox/linux/suid/process_util.h ('k') | sandbox/linux/suid/sandbox.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sandbox/linux/suid/process_util_linux.c
===================================================================
--- sandbox/linux/suid/process_util_linux.c (revision 0)
+++ sandbox/linux/suid/process_util_linux.c (revision 0)
@@ -0,0 +1,44 @@
+// Copyright (c) 2009 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.
+
+// The following is the C version of code from base/process_utils_linux.cc.
+// We shouldn't link against C++ code in a setuid binary.
+
+#include "process_util.h"
+
+#include <fcntl.h>
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+bool AdjustOOMScore(pid_t process, int score) {
+ if (score < 0 || score > 15)
+ return false;
+
+ char oom_adj[PATH_MAX];
agl 2009/12/09 21:19:14 Rather than use PATH_MAX here, it would be clearer
+ snprintf(oom_adj, sizeof(oom_adj), "/proc/%lu", process);
+
+ struct stat statbuf;
+ if (stat(oom_adj, &statbuf) < 0)
+ return false;
+ if (getuid() != statbuf.st_uid)
agl 2009/12/09 21:19:14 If one was being really careful one would open the
+ return false;
+
+ strcat(oom_adj, "/oom_adj");
+ int fd = open(oom_adj, O_WRONLY);
+ if (fd < 0)
+ return false;
+
+ char buf[3];
+ snprintf(buf, sizeof(buf), "%d", score);
+ size_t len = strlen(buf);
+
+ ssize_t bytes_written = write(fd, buf, len);
+ close(fd);
+ return (bytes_written == len);
+}
Property changes on: sandbox/linux/suid/process_util_linux.c
___________________________________________________________________
Added: svn:eol-style
+ LF
« 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