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

Side by Side Diff: base/process_util_posix.cc

Issue 10827112: base: Fix minor warnings reported by cppcheck. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 months 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 | Annotate | Revision Log
OLDNEW
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 #include <dirent.h> 5 #include <dirent.h>
6 #include <errno.h> 6 #include <errno.h>
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <signal.h> 8 #include <signal.h>
9 #include <stdlib.h> 9 #include <stdlib.h>
10 #include <sys/resource.h> 10 #include <sys/resource.h>
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 return process; 246 return process;
247 } 247 }
248 248
249 // Attempts to kill the process identified by the given process 249 // Attempts to kill the process identified by the given process
250 // entry structure. Ignores specified exit_code; posix can't force that. 250 // entry structure. Ignores specified exit_code; posix can't force that.
251 // Returns true if this is successful, false otherwise. 251 // Returns true if this is successful, false otherwise.
252 bool KillProcess(ProcessHandle process_id, int exit_code, bool wait) { 252 bool KillProcess(ProcessHandle process_id, int exit_code, bool wait) {
253 DCHECK_GT(process_id, 1) << " tried to kill invalid process_id"; 253 DCHECK_GT(process_id, 1) << " tried to kill invalid process_id";
254 if (process_id <= 1) 254 if (process_id <= 1)
255 return false; 255 return false;
256 static unsigned kMaxSleepMs = 1000;
257 unsigned sleep_ms = 4;
258
259 bool result = kill(process_id, SIGTERM) == 0; 256 bool result = kill(process_id, SIGTERM) == 0;
260
261 if (result && wait) { 257 if (result && wait) {
262 int tries = 60; 258 int tries = 60;
263 259
264 if (RunningOnValgrind()) { 260 if (RunningOnValgrind()) {
265 // Wait for some extra time when running under Valgrind since the child 261 // Wait for some extra time when running under Valgrind since the child
266 // processes may take some time doing leak checking. 262 // processes may take some time doing leak checking.
267 tries *= 2; 263 tries *= 2;
268 } 264 }
269 265
266 static const unsigned kMaxSleepMs = 1000;
jar (doing other things) 2012/08/03 17:20:19 nit: No need for static. Also, declare as close a
267 unsigned sleep_ms = 4;
268
270 // The process may not end immediately due to pending I/O 269 // The process may not end immediately due to pending I/O
271 bool exited = false; 270 bool exited = false;
272 while (tries-- > 0) { 271 while (tries-- > 0) {
273 pid_t pid = HANDLE_EINTR(waitpid(process_id, NULL, WNOHANG)); 272 pid_t pid = HANDLE_EINTR(waitpid(process_id, NULL, WNOHANG));
274 if (pid == process_id) { 273 if (pid == process_id) {
275 exited = true; 274 exited = true;
276 break; 275 break;
277 } 276 }
278 if (pid == -1) { 277 if (pid == -1) {
279 if (errno == ECHILD) { 278 if (errno == ECHILD) {
(...skipping 1051 matching lines...) Expand 10 before | Expand all | Expand 10 after
1331 if (IsChildDead(process)) 1330 if (IsChildDead(process))
1332 return; 1331 return;
1333 1332
1334 BackgroundReaper* reaper = new BackgroundReaper(process, 0); 1333 BackgroundReaper* reaper = new BackgroundReaper(process, 0);
1335 PlatformThread::CreateNonJoinable(0, reaper); 1334 PlatformThread::CreateNonJoinable(0, reaper);
1336 } 1335 }
1337 1336
1338 #endif // !defined(OS_MACOSX) 1337 #endif // !defined(OS_MACOSX)
1339 1338
1340 } // namespace base 1339 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698