# also see commit 6d1baf99 diff --git src/corelib/io/qfilesystemwatcher_kqueue.cpp src/corelib/io/qfilesystemwatcher_kqueue.cpp index cabeb44..9743649 100644 --- src/corelib/io/qfilesystemwatcher_kqueue.cpp +++ src/corelib/io/qfilesystemwatcher_kqueue.cpp @@ -127,6 +127,7 @@ QStringList QKqueueFileSystemWatcherEngine::addPaths(const QStringList &paths, while (it.hasNext()) { QString path = it.next(); int fd; + errno = 0; #if defined(O_EVTONLY) fd = qt_safe_open(QFile::encodeName(path), O_EVTONLY); #else @@ -135,15 +136,34 @@ QStringList QKqueueFileSystemWatcherEngine::addPaths(const QStringList &paths, if (fd == -1) { perror("QKqueueFileSystemWatcherEngine::addPaths: open"); continue; + } else { + if (errno) { + perror("QKqueueFileSystemWatcherEngine::addPaths: open returned valid descriptor but"); + ::close(fd); + continue; + } } + errno = 0; if (fd >= (int)FD_SETSIZE / 2 && fd < (int)FD_SETSIZE) { int fddup = fcntl(fd, F_DUPFD, FD_SETSIZE); if (fddup != -1) { ::close(fd); fd = fddup; + } else { + perror("QKqueueFileSystemWatcherEngine::addPaths: fddup"); + if (errno = EMFILE) { + // it seems wise not to insist when we just hit the open file limit + ::close(fd); + continue; + } } } + errno = 0; fcntl(fd, F_SETFD, FD_CLOEXEC); + if (errno) { + perror("QKqueueFileSystemWatcherEngine::addPaths: fcntl"); + errno = 0; + } QT_STATBUF st; if (QT_FSTAT(fd, &st) == -1) {