Diffstat (limited to 'libopie2/opiecore/oprocess.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiecore/oprocess.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/libopie2/opiecore/oprocess.cpp b/libopie2/opiecore/oprocess.cpp index f1a5f3b..5cfcf32 100644 --- a/libopie2/opiecore/oprocess.cpp +++ b/libopie2/opiecore/oprocess.cpp @@ -23,36 +23,38 @@ _;:, .> :=|. This program is free software; you can -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "oprocctrl.h" /* OPIE */ #include <opie2/oprocess.h> /* QT */ #include <qapplication.h> +#include <qdir.h> #include <qfile.h> #include <qmap.h> #include <qregexp.h> #include <qsocketnotifier.h> +#include <qtextstream.h> /* STD */ #include <errno.h> #include <fcntl.h> #include <pwd.h> #include <stdlib.h> #include <signal.h> #include <stdio.h> #include <string.h> #include <sys/time.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/socket.h> #include <unistd.h> #ifdef HAVE_SYS_SELECT_H #include <sys/select.h> @@ -900,16 +902,44 @@ bool OProcess::isExecutable( const QCString &filename ) ( S_ISSOCK( fileinfo.st_mode ) ) || #endif ( S_ISFIFO( fileinfo.st_mode ) ) || ( S_ISDIR( fileinfo.st_mode ) ) ) { return false; } // CC: now check for permission to execute the file if ( access( filename.data(), X_OK ) != 0 ) return false; // CC: we've passed all the tests... return true; } +int OProcess::processPID( const QString& process ) +{ + QString line; + QDir d = QDir( "/proc" ); + QStringList dirs = d.entryList( QDir::Dirs ); + QStringList::Iterator it; + for ( it = dirs.begin(); it != dirs.end(); ++it ) + { + //qDebug( "next entry: %s", (const char*) *it ); + QFile file( "/proc/"+*it+"/cmdline" ); + file.open( IO_ReadOnly ); + if ( !file.isOpen() ) continue; + QTextStream t( &file ); + line = t.readLine(); + //qDebug( "cmdline = %s", (const char*) line ); + if ( line.contains( process ) ) break; //FIXME: That may find also other process, if the name is not long enough ;) + } + if ( line.contains( process ) ) + { + //qDebug( "found process id #%d", (*it).toInt() ); + return (*it).toInt(); + } + else + { + //qDebug( "process '%s' not found", (const char*) process ); + return -1; + } +} |