diff --git a/src/inotify_watch.cpp b/src/inotify_watch.cpp index 268e0f89991c862544515c0841140359bafefe07..6617781f0ccec5069465d945b8fe4d691bab1403 100644 --- a/src/inotify_watch.cpp +++ b/src/inotify_watch.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -295,6 +296,17 @@ class watchedDirType { } public: + static void dump(std::ostream& out) { + out << "begin list of watched directories (" << getWatchedDirs().size() << "):\n"; + for (const auto& item: getWatchedDirs()) { + std::string path; + item.second->buildPath(path); + out << item.first << ": " << path << "\n"; + } + out << "end list of watched directories.\n"; + } + + /// fill path with the fill path to this directory void buildPath(std::string& path) { if (parent) { @@ -544,7 +556,10 @@ static void sigTermHandler(int) { static void sigPipeHandler(int) { std::exit(EXIT_FAILURE); } - +static std::atomic dumpRequested(false); +static void sigUsrHandler(int) { + dumpRequested = true; +} /** \brief class used to send messages via stdout. Makes sure uniform format is produced for all messages, @@ -655,6 +670,7 @@ int main(int argc, const char* argv[]) { } std::signal(SIGPIPE, sigPipeHandler); + std::signal(SIGUSR1, sigUsrHandler); auto fd = throwcall::badval(inotify_init(), -1, "inotify_init"); @@ -677,6 +693,10 @@ int main(int argc, const char* argv[]) { commandSender sender; while (true) { + if (dumpRequested) { + dumpRequested = false; + watchedDirType::dump(*errStream); + } { { // process single events that took forever to get a partner