diff options
author | Fabian Schillinger | 2010-11-01 16:53:24 +0100 |
---|---|---|
committer | Fabian Schillinger | 2010-11-01 16:53:24 +0100 |
commit | 0d97a7378ffe5f6be408201cd1f5595607ed5f87 (patch) | |
tree | 78ccd691a67c2f63f8fa4d1032d4cabfae0e80fa /src/pvs.cpp | |
parent | [PVSGUI] parsing cmdargs fixed (diff) | |
download | pvs-0d97a7378ffe5f6be408201cd1f5595607ed5f87.tar.gz pvs-0d97a7378ffe5f6be408201cd1f5595607ed5f87.tar.xz pvs-0d97a7378ffe5f6be408201cd1f5595607ed5f87.zip |
Process start/stop/view functionality
processWidget - shows a list of processes on one client, allows to start ans stop processes
processesDialog - shows every processWidget as a tab
processesStartDialog - starts process entered in messageEdit
added handling of new pvscommands
Diffstat (limited to 'src/pvs.cpp')
-rwxr-xr-x | src/pvs.cpp | 83 |
1 files changed, 78 insertions, 5 deletions
diff --git a/src/pvs.cpp b/src/pvs.cpp index 2aaec8a..b343f29 100755 --- a/src/pvs.cpp +++ b/src/pvs.cpp @@ -183,15 +183,21 @@ void PVS::onCommand(PVSMsg cmdMessage) } if (ident.compare("SHOWPROCESSES") == 0) { - // do stuff to show processes - // to test if SHOWPROCESSES command is submitted correct uncomment following lines - // a messagebox will appear on the client - // emit showMessage("Show Processes", "", true); + _pvsServerConnection->sendMessage(PVSMsg(PVSCOMMAND, "PROCESSES", "SHOW clear")); //tell the client that we want to clear his process-list + showProc(); return; } + if (ident.compare("STARTPROCESS") == 0) + { + 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")); + return; + } if (ident.compare("KILLPROCESS") == 0) { - // do stuff to kill a process + QProcess *proc = new QProcess( this ); + proc->start("kill "+message); //we try to kill the process with the given ID return; } @@ -658,3 +664,70 @@ QString PVS::getConfigValue(QString key) return _settings.value(key).toString(); } +void PVS::showProc() +{ + //look at procfs + QDir procfs("/proc"); + QStringList proc = procfs.entryList(); + int uid = getuid(); + bool write; + + for (int i=0;i<proc.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 name = ""; + QFile file("/proc/"+tmp+QString("/status")); //read status file + if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) + return; + + QTextStream in(&file); + QString line = in.readLine(); + while (!line.isNull()) + { + 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 + { + line.remove(0,5); + if (line.startsWith(QString::number(uid))) + write = true; + else break; + + } + line = in.readLine(); + } + if (write) + { + if ((name.startsWith("pvs")) || (name.startsWith("dbus"))) + 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 + if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) + return; + + QTextStream in(&file); + 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 + 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 finished")); //at the end we send that every process has been sent +} |