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 |
| 9 // (and it can be included earlier than the explicit #include below |
| 10 // in some versions of glibc). |
| 11 #define _GNU_SOURCE |
| 12 |
8 #include "sandbox/linux/suid/process_util.h" | 13 #include "sandbox/linux/suid/process_util.h" |
9 | 14 |
10 #define _GNU_SOURCE // needed for O_DIRECTORY | |
11 | |
12 #include <fcntl.h> | 15 #include <fcntl.h> |
13 #include <inttypes.h> | 16 #include <inttypes.h> |
14 #include <limits.h> | 17 #include <limits.h> |
15 #include <stdio.h> | 18 #include <stdio.h> |
16 #include <stdlib.h> | 19 #include <stdlib.h> |
17 #include <string.h> | 20 #include <string.h> |
18 #include <sys/stat.h> | 21 #include <sys/stat.h> |
19 #include <sys/types.h> | 22 #include <sys/types.h> |
20 #include <unistd.h> | 23 #include <unistd.h> |
21 | 24 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 close(dirfd); | 69 close(dirfd); |
67 | 70 |
68 char buf[11]; // 0 <= |score| <= kMaxOomScore; using log_10(2**32) + 1 size | 71 char buf[11]; // 0 <= |score| <= kMaxOomScore; using log_10(2**32) + 1 size |
69 snprintf(buf, sizeof(buf), "%d", score); | 72 snprintf(buf, sizeof(buf), "%d", score); |
70 size_t len = strlen(buf); | 73 size_t len = strlen(buf); |
71 | 74 |
72 ssize_t bytes_written = write(fd, buf, len); | 75 ssize_t bytes_written = write(fd, buf, len); |
73 close(fd); | 76 close(fd); |
74 return (bytes_written == len); | 77 return (bytes_written == len); |
75 } | 78 } |
OLD | NEW |