Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: base/process_linux.cc

Issue 8989035: CheckForNicePermission: Make sure can_reraise_priority is set in ctor (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: move data to the bottom of the struct Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698