OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // The following is the C version of code from base/process_utils_linux.cc. | 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. | 6 // We shouldn't link against C++ code in a setuid binary. |
7 | 7 |
8 // Needed for O_DIRECTORY, must be defined before fcntl.h is included | 8 // Needed for O_DIRECTORY, must be defined before fcntl.h is included |
9 // (and it can be included earlier than the explicit #include below | 9 // (and it can be included earlier than the explicit #include below |
10 // in some versions of glibc). | 10 // in some versions of glibc). |
11 #define _GNU_SOURCE | 11 #define _GNU_SOURCE |
12 | 12 |
13 #include "sandbox/linux/suid/process_util.h" | 13 #include "sandbox/linux/suid/process_util.h" |
14 | 14 |
15 #include <fcntl.h> | 15 #include <fcntl.h> |
16 #include <inttypes.h> | 16 #include <inttypes.h> |
17 #include <limits.h> | 17 #include <limits.h> |
| 18 #include <stddef.h> |
18 #include <stdio.h> | 19 #include <stdio.h> |
19 #include <stdlib.h> | 20 #include <stdlib.h> |
20 #include <string.h> | 21 #include <string.h> |
21 #include <sys/stat.h> | 22 #include <sys/stat.h> |
22 #include <sys/types.h> | 23 #include <sys/types.h> |
23 #include <unistd.h> | 24 #include <unistd.h> |
24 | 25 |
25 // Ranges for the current (oom_score_adj) and previous (oom_adj) | 26 // Ranges for the current (oom_score_adj) and previous (oom_adj) |
26 // flavors of OOM score. | 27 // flavors of OOM score. |
27 static const int kMaxOomScore = 1000; | 28 static const int kMaxOomScore = 1000; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 close(dirfd); | 70 close(dirfd); |
70 | 71 |
71 char buf[11]; // 0 <= |score| <= kMaxOomScore; using log_10(2**32) + 1 size | 72 char buf[11]; // 0 <= |score| <= kMaxOomScore; using log_10(2**32) + 1 size |
72 snprintf(buf, sizeof(buf), "%d", score); | 73 snprintf(buf, sizeof(buf), "%d", score); |
73 size_t len = strlen(buf); | 74 size_t len = strlen(buf); |
74 | 75 |
75 ssize_t bytes_written = write(fd, buf, len); | 76 ssize_t bytes_written = write(fd, buf, len); |
76 close(fd); | 77 close(fd); |
77 return (bytes_written == (ssize_t)len); | 78 return (bytes_written == (ssize_t)len); |
78 } | 79 } |
OLD | NEW |