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

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: fix nit 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
« no previous file with comments | « base/observer_list_unittest.cc ('k') | base/system_monitor/system_monitor_unittest.cc » ('j') | 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) 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 unsigned sleep_ms = 4;
267
270 // The process may not end immediately due to pending I/O 268 // The process may not end immediately due to pending I/O
271 bool exited = false; 269 bool exited = false;
272 while (tries-- > 0) { 270 while (tries-- > 0) {
273 pid_t pid = HANDLE_EINTR(waitpid(process_id, NULL, WNOHANG)); 271 pid_t pid = HANDLE_EINTR(waitpid(process_id, NULL, WNOHANG));
274 if (pid == process_id) { 272 if (pid == process_id) {
275 exited = true; 273 exited = true;
276 break; 274 break;
277 } 275 }
278 if (pid == -1) { 276 if (pid == -1) {
279 if (errno == ECHILD) { 277 if (errno == ECHILD) {
280 // The wait may fail with ECHILD if another process also waited for 278 // The wait may fail with ECHILD if another process also waited for
281 // the same pid, causing the process state to get cleaned up. 279 // the same pid, causing the process state to get cleaned up.
282 exited = true; 280 exited = true;
283 break; 281 break;
284 } 282 }
285 DPLOG(ERROR) << "Error waiting for process " << process_id; 283 DPLOG(ERROR) << "Error waiting for process " << process_id;
286 } 284 }
287 285
288 usleep(sleep_ms * 1000); 286 usleep(sleep_ms * 1000);
287 const unsigned kMaxSleepMs = 1000;
289 if (sleep_ms < kMaxSleepMs) 288 if (sleep_ms < kMaxSleepMs)
290 sleep_ms *= 2; 289 sleep_ms *= 2;
291 } 290 }
292 291
293 // If we're waiting and the child hasn't died by now, force it 292 // If we're waiting and the child hasn't died by now, force it
294 // with a SIGKILL. 293 // with a SIGKILL.
295 if (!exited) 294 if (!exited)
296 result = kill(process_id, SIGKILL) == 0; 295 result = kill(process_id, SIGKILL) == 0;
297 } 296 }
298 297
(...skipping 1029 matching lines...) Expand 10 before | Expand all | Expand 10 after
1328 if (IsChildDead(process)) 1327 if (IsChildDead(process))
1329 return; 1328 return;
1330 1329
1331 BackgroundReaper* reaper = new BackgroundReaper(process, 0); 1330 BackgroundReaper* reaper = new BackgroundReaper(process, 0);
1332 PlatformThread::CreateNonJoinable(0, reaper); 1331 PlatformThread::CreateNonJoinable(0, reaper);
1333 } 1332 }
1334 1333
1335 #endif // !defined(OS_MACOSX) 1334 #endif // !defined(OS_MACOSX)
1336 1335
1337 } // namespace base 1336 } // namespace base
OLDNEW
« no previous file with comments | « base/observer_list_unittest.cc ('k') | base/system_monitor/system_monitor_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698