diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2ee7f4da3..3898a9587 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -180,7 +180,6 @@ set(RTAGS_SOURCES ListSymbolsJob.cpp Location.cpp Preprocessor.cpp - ProcThread.cpp Project.cpp QueryJob.cpp QueryMessage.cpp diff --git a/src/ProcThread.cpp b/src/ProcThread.cpp deleted file mode 100644 index 84dbc5603..000000000 --- a/src/ProcThread.cpp +++ /dev/null @@ -1,237 +0,0 @@ -/* This file is part of RTags (http://rtags.net). - - RTags is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - RTags is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with RTags. If not, see . */ - -#include "ProcThread.h" -#include -#include "RTags.h" -#ifdef RTAGS_HAS_PROC -#include -#include -#endif - -ProcThread::ProcThread(int interval) - : Thread(), mInterval(interval) -{ -#ifdef RTAGS_HAS_PROC - mPath = "/proc/"; -#endif -} - -ProcThread::~ProcThread() -{ -} - -void ProcThread::run() -{ - while (true) { - { - std::unique_lock lock(mMutex); - if (!mInterval) { - break; - } - if (mCond.wait_for(lock, std::chrono::milliseconds(mInterval)) != std::cv_status::timeout) { - break; - } - } - readProc(); - } -} - -void ProcThread::stop() -{ - { - std::unique_lock lock(mMutex); - mInterval = 0; - mCond.notify_one(); - } - join(); -} - -struct ParseNode { - char cmdLine[16384]; - char cwd[PATH_MAX]; - List environ; - -}; -void ProcThread::readProc() -{ - for (auto &pair : mNodes) { - pair.second = true; - } -#ifdef RTAGS_HAS_PROC - DIR *dir = opendir("/proc/"); - int found = 0; - StopWatch sw; - List nodes(1); - while (const dirent *p = readdir(dir)) { -#if defined(_DIRENT_HAVE_D_TYPE) && defined(_BSD_SOURCE) - if (p->d_type != DT_DIR) - continue; -#endif - const int pid = atoi(p->d_name); - if (!pid) - continue; - auto it = mNodes.find(pid); - if (it != mNodes.end()) { - it->second = false; - continue; - } else { - mNodes[pid] = false; - } - - char file[PATH_MAX]; // should be enough for everyone - snprintf(file, sizeof(file), "/proc/%s/cmdline", p->d_name); - FILE *f = fopen(file, "r"); - if (!f) { - // error("Can't open %s for reading", file); - continue; - } - - auto &node = nodes.back(); - - size_t read = fread(node.cmdLine, 1, sizeof(node.cmdLine), f); - fclose(f); - if (!read) { - // error("Can't read from %s", file); - continue; - } - - if (!strncmp(node.cmdLine, "/bin/bash", 9) || !strncmp(node.cmdLine, "/bin/sh", 7)) - continue; - - while (read > 0 && !node.cmdLine[read-1]) - --read; // skip trailing zeroes - const char *prev = node.cmdLine; - enum { - Dunno, - Yay, - Nay - } hasSource = Dunno; - for (size_t i=0; i prev; --ext) { - if (*ext == '.') { - char extBuf[16]; - const size_t size = i - 1 - (ext - node.cmdLine); - if (size < sizeof(extBuf)) { - memcpy(extBuf, ext + 1, size); - extBuf[size] = '\0'; - if (Path::isSource(extBuf)) { - hasSource = Yay; - } - } - break; - } - } - } - prev = &node.cmdLine[i]; - default: - break; - } - } - if (hasSource != Yay) - continue; - - // error() << "GOT SOURCE" << node.cmdLine; - - snprintf(file, sizeof(file), "/proc/%s/cwd", p->d_name); - const int w = readlink(file, node.cwd, sizeof(node.cwd) - 2); - if (w <= 0) { - // error("Can't follow link from %s", file); - continue; - } - - if (node.cwd[w - 1] != '/') { - node.cwd[w] = '/'; - node.cwd[w + 1] = '\0'; - } else { - node.cwd[w] = '\0'; - } - - snprintf(file, sizeof(file), "/proc/%s/environ", p->d_name); - f = fopen(file, "r"); - if (!f) { - // error("Can't open file %s", file); - continue; - } - - char env[16384]; - read = fread(env, 1, sizeof(env), f); - fclose(f); - if (!read) { - // error("Can't read from from %s", file); - continue; - } - - while (read > 0 && !node.cmdLine[read-1]) - --read; // skip trailing zeroes - size_t last = 0; - for (size_t i=0; i last) { - node.environ.append(String(env + last, read - last)); - } - nodes.append(ParseNode()); - // error() << "GONNA PARSE" << node.cmdLine; - // if (!sources.isEmpty()) { - // error() << "GOT SOURCES" << sources[0].sourceFile(); - // } - ++found; - } - SourceCache cache; - for (size_t i=0; i paths; - SourceList sources = Source::parse(node.cmdLine, node.cwd, node.environ, &paths, &cache); - if (sources.size()) { - error() << "GOT SOURCES" << node.cmdLine; - } - // error() << "GOT SOURCES" << sources.size() << "from" << node.cmdLine - // << paths; - } - - Hash::iterator it = mNodes.begin(); - while (it != mNodes.end()) { - if (it->second) { - mNodes.erase(it++); - } else { - ++it; - } - } - // printf("%d took %llu\n", found, sw.elapsed()); - closedir(dir); -#endif -} diff --git a/src/ProcThread.h b/src/ProcThread.h deleted file mode 100644 index d853714dc..000000000 --- a/src/ProcThread.h +++ /dev/null @@ -1,56 +0,0 @@ -/* This file is part of RTags (http://rtags.net). - - RTags is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - RTags is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with RTags. If not, see . */ - -#ifndef ProcThread_h -#define ProcThread_h - -#include -#include -#include -#include -#include -#include -#include -#include -#include "Source.h" - -#if defined(OS_Linux) || defined(OS_FreeBSD) || 1 -#define RTAGS_HAS_PROC -#endif - -class ProcThread : public Thread -{ -public: - ProcThread(int interval); - ~ProcThread(); - - void stop(); - virtual void run(); - Signal > &command() { return mCommand; } -private: - void readProc(); - - Signal > mCommand; - std::mutex mMutex; - std::condition_variable mCond; - int mInterval; - -#ifdef RTAGS_HAS_PROC - Path mPath; -#endif - Hash mNodes; -}; - -#endif diff --git a/src/Server.h b/src/Server.h index 882a3ed57..bc5ee30db 100644 --- a/src/Server.h +++ b/src/Server.h @@ -36,7 +36,6 @@ class Match; class CompletionThread; class Connection; -class ErrorMessage; class IndexDataMessage; class QueryJob; class LogOutputMessage; @@ -159,7 +158,6 @@ class Server void handleIndexMessage(const std::shared_ptr &message, const std::shared_ptr &conn); void handleIndexDataMessage(const std::shared_ptr &message, const std::shared_ptr &conn); void handleQueryMessage(const std::shared_ptr &message, const std::shared_ptr &conn); - void handleErrorMessage(const std::shared_ptr &message, const std::shared_ptr &conn); void handleLogOutputMessage(const std::shared_ptr &message, const std::shared_ptr &conn); void handleVisitFileMessage(const std::shared_ptr &message, const std::shared_ptr &conn); @@ -231,7 +229,6 @@ class Server Set > mConnections; Signal > mIndexDataMessageReceived; - friend void saveFileIds(); }; RCT_FLAGS(Server::Option); RCT_FLAGS(Server::FileIdsFileFlag);