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/thread_helpers.h" | 5 #include "sandbox/linux/services/thread_helpers.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <signal.h> | 9 #include <signal.h> |
10 #include <sys/types.h> | 10 #include <sys/types.h> |
(...skipping 25 matching lines...) Expand all Loading... |
36 // determining if the current proces is monothreaded it works: if at any | 36 // determining if the current proces is monothreaded it works: if at any |
37 // time it becomes monothreaded, it'll stay so. | 37 // time it becomes monothreaded, it'll stay so. |
38 return task_stat.st_nlink == 3; | 38 return task_stat.st_nlink == 3; |
39 } | 39 } |
40 | 40 |
41 } // namespace | 41 } // namespace |
42 | 42 |
43 bool ThreadHelpers::IsSingleThreaded(int proc_self_task) { | 43 bool ThreadHelpers::IsSingleThreaded(int proc_self_task) { |
44 DCHECK_LE(-1, proc_self_task); | 44 DCHECK_LE(-1, proc_self_task); |
45 if (-1 == proc_self_task) { | 45 if (-1 == proc_self_task) { |
46 const int task_fd = open("/proc/self/task/", O_RDONLY | O_DIRECTORY); | 46 const int task_fd = |
| 47 open("/proc/self/task/", O_RDONLY | O_DIRECTORY | O_CLOEXEC); |
47 PCHECK(0 <= task_fd); | 48 PCHECK(0 <= task_fd); |
48 const bool result = IsSingleThreadedImpl(task_fd); | 49 const bool result = IsSingleThreadedImpl(task_fd); |
49 PCHECK(0 == IGNORE_EINTR(close(task_fd))); | 50 PCHECK(0 == IGNORE_EINTR(close(task_fd))); |
50 return result; | 51 return result; |
51 } else { | 52 } else { |
52 return IsSingleThreadedImpl(proc_self_task); | 53 return IsSingleThreadedImpl(proc_self_task); |
53 } | 54 } |
54 } | 55 } |
55 | 56 |
56 bool ThreadHelpers::StopThreadAndWatchProcFS(int proc_self_task, | 57 bool ThreadHelpers::StopThreadAndWatchProcFS(int proc_self_task, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 // In practice, this never goes through more than a couple iterations. In | 94 // In practice, this never goes through more than a couple iterations. In |
94 // debug mode, crash after 64ms (+ eventually 25 times the granularity of | 95 // debug mode, crash after 64ms (+ eventually 25 times the granularity of |
95 // the clock) in nanosleep(2). | 96 // the clock) in nanosleep(2). |
96 DCHECK_GT(25U, iterations); | 97 DCHECK_GT(25U, iterations); |
97 } | 98 } |
98 | 99 |
99 return true; | 100 return true; |
100 } | 101 } |
101 | 102 |
102 } // namespace sandbox | 103 } // namespace sandbox |
OLD | NEW |