diff options
Diffstat (limited to 'src/pvs.cpp')
| -rwxr-xr-x | src/pvs.cpp | 70 |
1 files changed, 48 insertions, 22 deletions
diff --git a/src/pvs.cpp b/src/pvs.cpp index 755eea5..843a725 100755 --- a/src/pvs.cpp +++ b/src/pvs.cpp @@ -268,15 +268,18 @@ void PVS::onCommand(PVSMsg cmdMessage) } if (ident.compare("STARTPROCESS") == 0) { + processName = message; QProcess *proc = new QProcess( this ); proc->start(message); //we try to run the process with the name message - _pvsServerConnection->sendMessage(PVSMsg(PVSCOMMAND, "PROCESSES", "START Process "+message+": started")); + connect( proc, SIGNAL( error(QProcess::ProcessError)), this, SLOT( processStartErrorOccured(QProcess::ProcessError))); return; } if (ident.compare("KILLPROCESS") == 0) { + processName = message; QProcess *proc = new QProcess( this ); proc->start("kill "+message); //we try to kill the process with the given ID + connect( proc, SIGNAL( error(QProcess::ProcessError)), this, SLOT( processStopErrorOccured(QProcess::ProcessError))); return; } @@ -937,21 +940,28 @@ QString PVS::getConfigValue(QString key) void PVS::showProc() { + QString settings = getConfigValue("RemoteProcess/filter"); + QStringList filter = settings.split(" "); + //look at procfs QDir procfs("/proc"); - QStringList proc = procfs.entryList(); + QStringList procList = procfs.entryList(); int uid = getuid(); bool write; - - for (int i=0;i<proc.length();i++) //every directory in /proc is checked + if (procList.length() < 1) //if we can't read procfs for any reason + { + _pvsServerConnection->sendMessage(PVSMsg(PVSCOMMAND, "PROCESSES", "SHOW ERROR")); + return; + } + for (int i=0;i<procList.length();i++) //every directory in /proc is checked { write = false; - QString tmp = proc.at(i); - QString snd = ""; - if (!tmp.contains(QRegExp("\\D"))) //we have to check if name is number + QString tempFolder = procList.at(i); + QString tempSend = ""; + if (!tempFolder.contains(QRegExp("\\D"))) //we have to check if name is number { QString name = ""; - QFile file("/proc/"+tmp+QString("/status")); //read status file + QFile file("/proc/"+tempFolder+QString("/status")); //read status file if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) return; @@ -962,28 +972,31 @@ void PVS::showProc() if (line.startsWith("Name:")) //to get the name of our process { name = line.remove(0,6); - snd.append(tmp).append(QString("<#>")).append(line).append("<#>"); - //lets check if the process belongs to our PVS better not to show it if we dont want to crash PVS - } else if (line.startsWith("Gid:")) //and to check that the process is a user process - //we had to read name first because every file in /proc - //has size 0 byte + tempSend.append(tempFolder).append(QString("<#>")).append(line).append("<#>"); + //lets check if the process belongs to our PVS. better not to show it if we dont want to crash PVS + } else if (line.startsWith("Uid:")) //and to check that the process is a user process + //we had to read name first { - line.remove(0,5); - if (line.startsWith(QString::number(uid))) + line.remove(QRegExp("\\D")); //remove all non-digit characters (letters+whitespaces) + int llength = line.size(); + line.remove(llength/4,llength); + if (line == QString::number(uid)) write = true; else break; - } line = in.readLine(); } - if (write) + if (write) //check if user belongs to pvs { - if ((name.startsWith("pvs")) || (name.startsWith("dbus"))) + for (int i=0;i<filter.size();i++) + { + if (name == (filter.at(i))) write = false; + } } if (write) //if process belongs to user (and not to PVS) we go on { - QFile file("/proc/"+tmp+QString("/cmdline")); //and read cmdline + QFile file("/proc/"+tempFolder+QString("/cmdline")); //and read cmdline if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) return; @@ -991,14 +1004,27 @@ void PVS::showProc() QString line = in.readLine(); while (!line.isNull()) { - int templength = snd.length()+3; - snd.append(line.left(150+templength)); //but only up to a length of 150-name-id-seperators + int templength = tempSend.length()+3; + tempSend.append(line.left(150+templength)); //but only up to a length of 150-name-id-seperators break; } } if (write) //if process belongs to user we send the line to client - _pvsServerConnection->sendMessage(PVSMsg(PVSCOMMAND, "PROCESSES", "SHOW "+snd)); + _pvsServerConnection->sendMessage(PVSMsg(PVSCOMMAND, "PROCESSES", "SHOW "+tempSend)); } } _pvsServerConnection->sendMessage(PVSMsg(PVSCOMMAND, "PROCESSES", "SHOW finished")); //at the end we send that every process has been sent } + +//tell connectionManager that error occured +void PVS::processStartErrorOccured(QProcess::ProcessError error) +{ + _pvsServerConnection->sendMessage(PVSMsg(PVSCOMMAND, "PROCESSES", "START ERROR "+QString::number(error)+" "+processName)); + processName = ""; +} + +void PVS::processStopErrorOccured(QProcess::ProcessError error) +{ + _pvsServerConnection->sendMessage(PVSMsg(PVSCOMMAND, "PROCESSES", "STOP ERROR "+QString::number(error)+" "+processName)); + processName = ""; +} |
