OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/process.h" | 5 #include "base/process.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <sys/resource.h> | 8 #include <sys/resource.h> |
9 | 9 |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 if (!CanBackgroundProcesses()) | 100 if (!CanBackgroundProcesses()) |
101 return false; | 101 return false; |
102 | 102 |
103 int priority = background ? kBackgroundPriority : kForegroundPriority; | 103 int priority = background ? kBackgroundPriority : kForegroundPriority; |
104 int result = setpriority(PRIO_PROCESS, process_, priority); | 104 int result = setpriority(PRIO_PROCESS, process_, priority); |
105 DPCHECK(result == 0); | 105 DPCHECK(result == 0); |
106 return result == 0; | 106 return result == 0; |
107 } | 107 } |
108 | 108 |
109 struct CheckForNicePermission { | 109 struct CheckForNicePermission { |
110 bool can_reraise_priority; | 110 CheckForNicePermission() : can_reraise_priority(false) { |
111 | |
112 CheckForNicePermission() { | |
113 // We won't be able to raise the priority if we don't have the right rlimit. | 111 // We won't be able to raise the priority if we don't have the right rlimit. |
114 // The limit may be adjusted in /etc/security/limits.conf for PAM systems. | 112 // The limit may be adjusted in /etc/security/limits.conf for PAM systems. |
115 struct rlimit rlim; | 113 struct rlimit rlim; |
116 if ((getrlimit(RLIMIT_NICE, &rlim) == 0) && | 114 if ((getrlimit(RLIMIT_NICE, &rlim) == 0) && |
117 (20 - kForegroundPriority) <= static_cast<int>(rlim.rlim_cur)) { | 115 (20 - kForegroundPriority) <= static_cast<int>(rlim.rlim_cur)) { |
118 can_reraise_priority = true; | 116 can_reraise_priority = true; |
119 } | 117 } |
120 }; | 118 }; |
| 119 |
| 120 bool can_reraise_priority; |
121 }; | 121 }; |
122 | 122 |
123 // static | 123 // static |
124 bool Process::CanBackgroundProcesses() { | 124 bool Process::CanBackgroundProcesses() { |
125 #if defined(OS_CHROMEOS) | 125 #if defined(OS_CHROMEOS) |
126 if (cgroups.Get().enabled) | 126 if (cgroups.Get().enabled) |
127 return true; | 127 return true; |
128 #endif | 128 #endif |
129 | 129 |
130 static LazyInstance<CheckForNicePermission> check_for_nice_permission = | 130 static LazyInstance<CheckForNicePermission> check_for_nice_permission = |
131 LAZY_INSTANCE_INITIALIZER; | 131 LAZY_INSTANCE_INITIALIZER; |
132 return check_for_nice_permission.Get().can_reraise_priority; | 132 return check_for_nice_permission.Get().can_reraise_priority; |
133 } | 133 } |
134 | 134 |
135 } // namespace base | 135 } // namespace base |
OLD | NEW |