From kde-commits Mon Jan 17 00:39:10 2011 From: David Faure Date: Mon, 17 Jan 2011 00:39:10 +0000 To: kde-commits Subject: KDE/kdelibs/kdecore Message-Id: <20110117003910.14080AC8B5 () svn ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=129522479309934 SVN commit 1214954 by dfaure: Found how to reproduce the qfswatch hang bug in the unittest. Fixed by adding a qAddPostRoutine which destroys KDirWatch::sef() while qApp is still around. If this proves stable in trunk, let's backport it to the 4.6 branch CCBUG: 261541 M +16 -1 io/kdirwatch.cpp M +11 -0 tests/kdirwatch_unittest.cpp --- trunk/KDE/kdelibs/kdecore/io/kdirwatch.cpp #1214953:1214954 @@ -54,6 +54,7 @@ #include #include #include +#include #include #include @@ -680,6 +681,7 @@ return true; } + kDebug(7001) << "inotify failed for monitoring" << e->path << ":" << strerror(errno); return false; } #endif @@ -1723,11 +1725,17 @@ return s_pKDirWatchSelf; } +// TODO KDE5: is this used anywhere? bool KDirWatch::exists() { - return s_pKDirWatchSelf != 0; + return s_pKDirWatchSelf.exists(); } +static void cleanupKDirWatch() +{ + s_pKDirWatchSelf.destroy(); +} + KDirWatch::KDirWatch (QObject* parent) : QObject(parent), d(createPrivate()) { @@ -1739,7 +1747,14 @@ d->ref(); d->_isStopped = false; + + static bool cleanupRegistered = false; + if (!cleanupRegistered) { + cleanupRegistered = true; + // Must delete kdirwatch before qApp is gone, due to QFileSystemWatcher - bug 261541 + qAddPostRoutine(cleanupKDirWatch); } +} KDirWatch::~KDirWatch() { --- trunk/KDE/kdelibs/kdecore/tests/kdirwatch_unittest.cpp #1214953:1214954 @@ -91,6 +91,7 @@ void watchAndModifyOneFile(); void removeAndReAdd(); void watchNonExistent(); + void watchNonExistentWithSingleton(); void testDelete(); void testDeleteAndRecreateFile(); void testDeleteAndRecreateDir(); @@ -434,6 +435,16 @@ QVERIFY(waitForOneSignal(watch, SIGNAL(dirty(QString)), subdir)); } +void KDirWatch_UnitTest::watchNonExistentWithSingleton() +{ + const QString file = "/root/.ssh/authorized_keys"; + KDirWatch::self()->addFile(file); + // When running this test in KDIRWATCHTEST_METHOD=QFSWatch, or when FAM is not available + // and we fallback to qfswatch when inotify fails above, we end up creating the fsWatch + // in the kdirwatch singleton. Bug 261541 discovered that Qt hanged when deleting fsWatch + // once QCoreApp was gone, this is what this test is about. +} + void KDirWatch_UnitTest::testDelete() { const QString file1 = m_path + "del";