OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "sandbox/linux/services/proc_util.h" | 5 #include "sandbox/linux/services/proc_util.h" |
6 | 6 |
7 #include <dirent.h> | 7 #include <dirent.h> |
8 #include <errno.h> | 8 #include <errno.h> |
9 #include <fcntl.h> | 9 #include <fcntl.h> |
10 #include <string.h> | 10 #include <string.h> |
11 #include <sys/stat.h> | 11 #include <sys/stat.h> |
12 #include <sys/types.h> | 12 #include <sys/types.h> |
13 | 13 |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/posix/eintr_wrapper.h" |
16 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
17 | 18 |
18 namespace sandbox { | 19 namespace sandbox { |
19 namespace { | 20 namespace { |
20 | 21 |
21 struct DIRCloser { | 22 struct DIRCloser { |
22 void operator()(DIR* d) const { | 23 void operator()(DIR* d) const { |
23 DCHECK(d); | 24 DCHECK(d); |
24 PCHECK(0 == closedir(d)); | 25 PCHECK(0 == closedir(d)); |
25 } | 26 } |
26 }; | 27 }; |
27 | 28 |
28 typedef scoped_ptr<DIR, DIRCloser> ScopedDIR; | 29 typedef scoped_ptr<DIR, DIRCloser> ScopedDIR; |
29 | 30 |
30 } // namespace | 31 } // namespace |
31 | 32 |
32 int ProcUtil::CountOpenFds(int proc_fd) { | 33 int ProcUtil::CountOpenFds(int proc_fd) { |
33 DCHECK_LE(0, proc_fd); | 34 DCHECK_LE(0, proc_fd); |
34 int proc_self_fd = openat(proc_fd, "self/fd", O_DIRECTORY | O_RDONLY); | 35 int proc_self_fd = HANDLE_EINTR( |
| 36 openat(proc_fd, "self/fd", O_DIRECTORY | O_RDONLY | O_CLOEXEC)); |
35 PCHECK(0 <= proc_self_fd); | 37 PCHECK(0 <= proc_self_fd); |
36 | 38 |
37 // Ownership of proc_self_fd is transferred here, it must not be closed | 39 // Ownership of proc_self_fd is transferred here, it must not be closed |
38 // or modified afterwards except via dir. | 40 // or modified afterwards except via dir. |
39 ScopedDIR dir(fdopendir(proc_self_fd)); | 41 ScopedDIR dir(fdopendir(proc_self_fd)); |
40 CHECK(dir); | 42 CHECK(dir); |
41 | 43 |
42 int count = 0; | 44 int count = 0; |
43 struct dirent e; | 45 struct dirent e; |
44 struct dirent* de; | 46 struct dirent* de; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 CHECK(fstatat(proc_self_fd, e.d_name, &s, 0) == 0); | 104 CHECK(fstatat(proc_self_fd, e.d_name, &s, 0) == 0); |
103 if (S_ISDIR(s.st_mode)) { | 105 if (S_ISDIR(s.st_mode)) { |
104 return true; | 106 return true; |
105 } | 107 } |
106 } | 108 } |
107 | 109 |
108 // No open unmanaged directories found. | 110 // No open unmanaged directories found. |
109 return false; | 111 return false; |
110 } | 112 } |
111 | 113 |
| 114 //static |
| 115 base::ScopedFD ProcUtil::OpenProcSelfTask() { |
| 116 base::ScopedFD proc_self_task( |
| 117 HANDLE_EINTR( |
| 118 open("/proc/self/task/", O_RDONLY | O_DIRECTORY | O_CLOEXEC))); |
| 119 PCHECK(proc_self_task.is_valid()); |
| 120 return proc_self_task.Pass(); |
| 121 } |
| 122 |
112 } // namespace sandbox | 123 } // namespace sandbox |
OLD | NEW |