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

Side by Side Diff: base/directory_watcher_inotify.cc

Issue 147052: Fix a race condition in directory_watcher_inotify.cc: release lock before sig... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 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 | « 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/directory_watcher.h" 5 #include "base/directory_watcher.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <string.h> 8 #include <string.h>
9 #include <sys/inotify.h> 9 #include <sys/inotify.h>
10 #include <sys/ioctl.h> 10 #include <sys/ioctl.h>
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 390
391 bool DirectoryWatcherImpl::OnEnumeratedSubtree(const FilePathSet& subtree) { 391 bool DirectoryWatcherImpl::OnEnumeratedSubtree(const FilePathSet& subtree) {
392 DCHECK(recursive_); 392 DCHECK(recursive_);
393 393
394 if (watch_ == InotifyReader::kInvalidWatch) { 394 if (watch_ == InotifyReader::kInvalidWatch) {
395 recursive_setup_finished_.Signal(); 395 recursive_setup_finished_.Signal();
396 return false; 396 return false;
397 } 397 }
398 398
399 bool success = true; 399 bool success = true;
400 AutoLock auto_lock(lock_); 400
401 for (FilePathSet::iterator subdirectory = subtree.begin(); 401 {
402 subdirectory != subtree.end(); 402 // Limit the scope of auto_lock so it releases lock_ before we signal
403 ++subdirectory) { 403 // recursive_setup_finished_. Our dtor waits on recursive_setup_finished_
404 ino_t inode; 404 // and could otherwise destroy the lock before we release it.
405 if (!file_util::GetInode(*subdirectory, &inode)) { 405 AutoLock auto_lock(lock_);
406 success = false; 406
407 continue; 407 for (FilePathSet::iterator subdirectory = subtree.begin();
408 } 408 subdirectory != subtree.end();
409 if (IsInodeWatched(inode)) 409 ++subdirectory) {
410 continue; 410 ino_t inode;
411 InotifyReader::Watch watch = 411 if (!file_util::GetInode(*subdirectory, &inode)) {
412 Singleton<InotifyReader>::get()->AddWatch(*subdirectory, this); 412 success = false;
413 if (watch != InotifyReader::kInvalidWatch) { 413 continue;
414 watches_.insert(watch); 414 }
415 inodes_watched_.insert(inode); 415 if (IsInodeWatched(inode))
416 continue;
417 InotifyReader::Watch watch =
418 Singleton<InotifyReader>::get()->AddWatch(*subdirectory, this);
419 if (watch != InotifyReader::kInvalidWatch) {
420 watches_.insert(watch);
421 inodes_watched_.insert(inode);
422 }
416 } 423 }
417 } 424 }
425
418 recursive_setup_finished_.Signal(); 426 recursive_setup_finished_.Signal();
419 return success; 427 return success;
420 } 428 }
421 429
422 bool DirectoryWatcherImpl::Watch(const FilePath& path, 430 bool DirectoryWatcherImpl::Watch(const FilePath& path,
423 DirectoryWatcher::Delegate* delegate, 431 DirectoryWatcher::Delegate* delegate,
424 MessageLoop* backend_loop, bool recursive) { 432 MessageLoop* backend_loop, bool recursive) {
425 433
426 // Can only watch one path. 434 // Can only watch one path.
427 DCHECK(watch_ == InotifyReader::kInvalidWatch); 435 DCHECK(watch_ == InotifyReader::kInvalidWatch);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 467
460 return true; 468 return true;
461 } 469 }
462 470
463 } // namespace 471 } // namespace
464 472
465 DirectoryWatcher::DirectoryWatcher() { 473 DirectoryWatcher::DirectoryWatcher() {
466 impl_ = new DirectoryWatcherImpl(); 474 impl_ = new DirectoryWatcherImpl();
467 } 475 }
468 476
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