[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdelibs/kinit
From: Patrick Spendrin <ps_ml () gmx ! de>
Date: 2010-07-10 2:58:41
Message-ID: 20100710030822.8222EAC867 () svn ! kde ! org
[Download RAW message or body]
SVN commit 1148198 by sengels:
restrict process checks to the installation directory
also fix bug so that --terminate etc work again
M +51 -9 kinit_win.cpp
--- trunk/KDE/kdelibs/kinit/kinit_win.cpp #1148197:1148198
@@ -106,6 +106,7 @@
ProcessListEntry *hasProcessInList(const QString &name, K_UID owner=0 );
bool terminateProcess(const QString &name);
QList<ProcessListEntry *> &list() { return processList; }
+ QList<ProcessListEntry *> listProcesses();
private:
void initProcessList();
void getProcessNameAndID( DWORD processID );
@@ -216,11 +217,36 @@
getProcessNameAndID( aProcesses[i] );
}
+QList<ProcessListEntry*> ProcessList::listProcesses()
+{
+ // Get the list of process identifiers.
+ DWORD aProcesses[1024], cbNeeded, cProcesses;
+ unsigned int i;
+
+ if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) )
+ return QList<ProcessListEntry*>();
+
+ // Calculate how many process identifiers were returned.
+
+ cProcesses = cbNeeded / sizeof(DWORD);
+
+ // Print the name and process identifier for each process.
+
+ processList.erase(processList.begin(), processList.end());
+ for ( i = 0; i < cProcesses; i++ )
+ if( aProcesses[i] != 0 )
+ getProcessNameAndID( aProcesses[i] );
+
+ return processList;
+}
+
+
ProcessList::~ProcessList()
{
ProcessListEntry *ple;
- foreach(ple,processList) {
+ QList<ProcessListEntry*> l = listProcesses();
+ foreach(ple,l) {
CloseHandle(ple->handle);
delete ple;
}
@@ -237,7 +263,17 @@
qDebug() << "negative pid!";
continue;
}
- if (ple->name == name || ple->name == name + ".exe") {
+
+ if (ple->name != name && ple->name != name + ".exe") {
+ continue;
+ }
+
+ if (!ple->path.isEmpty() && \
!ple->path.toLower().startsWith(KStandardDirs::installPath("kdedir").toLower())) { + \
// process is outside of installation directory + qDebug() << "path of the \
process" << name << "seems to be outside of the installPath:" << ple->path << \
KStandardDirs::installPath("kdedir"); + continue;
+ }
+
if(owner)
{
// owner is set
@@ -250,7 +286,6 @@
if(EqualSid(user.uid(), ple->owner)) return ple;
}
}
- }
return NULL;
}
@@ -259,13 +294,18 @@
*/
bool ProcessList::terminateProcess(const QString &name)
{
+ qDebug() << "going to terminate process" << name;
ProcessListEntry *p = hasProcessInList(name);
- if (!p)
+ if (!p) {
+ qDebug() << "could not find ProcessListEntry for process name" << name;
return false;
+ }
bool ret = TerminateProcess(p->handle,0);
if (ret) {
CloseHandle(p->handle);
+ int i = processList.indexOf(p);
+ if(i != -1) processList.removeAt(i);
delete p;
return true;
} else {
@@ -292,7 +332,7 @@
}
else {
if (verbose)
- fprintf(stderr, "kdeinit4: could not launch %s, \
exiting",qPrintable(cmd)); + fprintf(stderr, "kdeinit4: could not launch \
%s, exiting\n",qPrintable(cmd)); }
return pid;
}
@@ -321,10 +361,11 @@
{
ProcessListEntry *ple;
QString installPrefix = KStandardDirs::installPath("kdedir");
+ QList<ProcessListEntry*> l = processList.listProcesses();
- foreach(ple,processList.list())
+ foreach(ple,l)
{
- if (ple->path.toLower().startsWith(installPrefix.toLower()))
+ if (!ple->path.isEmpty() && \
ple->path.toLower().startsWith(installPrefix.toLower()))
fprintf(stderr,"path: %s name: %s pid: %u\n", \
ple->path.toLatin1().data(), ple->name.toLatin1().data(), ple->pid); }
}
@@ -333,10 +374,11 @@
{
ProcessListEntry *ple;
QString installPrefix = KStandardDirs::installPath("kdedir");
+ QList<ProcessListEntry*> l = processList.listProcesses();
- foreach(ple,processList.list())
+ foreach(ple,l)
{
- if (ple->path.toLower().startsWith(installPrefix.toLower()))
+ if (!ple->path.isEmpty() && \
ple->path.toLower().startsWith(installPrefix.toLower())) {
if (verbose)
fprintf(stderr,"terminating path: %s name: %s pid: %u\n", \
ple->path.toLatin1().data(), ple->name.toLatin1().data(), ple->pid);
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic