summaryrefslogtreecommitdiff
path: root/libopie2/opiecore/oprocess.cpp
Side-by-side diff
Diffstat (limited to 'libopie2/opiecore/oprocess.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiecore/oprocess.cpp30
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
@@ -15,52 +15,54 @@ _;:,     .>    :=|. This program is free software; you can
  .i_,=:_.      -<s. This program 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
..}^=.=       =       ; Library General Public License for more
++=   -.     .`     .: details.
:     =  ...= . :.=-
-.   .:....=;==+<; 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>
#endif
#ifdef HAVE_INITGROUPS
#include <grp.h>
#endif
class OProcessPrivate
{
public:
@@ -892,24 +894,52 @@ bool OProcess::isExecutable( const QCString &filename )
// CC: return false if the file does not exist
// CC: anyway, we cannot execute directories, block/character devices, fifos or sockets
if ( ( S_ISDIR( fileinfo.st_mode ) ) ||
( S_ISCHR( fileinfo.st_mode ) ) ||
( S_ISBLK( fileinfo.st_mode ) ) ||
#ifdef S_ISSOCK
// CC: SYSVR4 systems don't have that macro
( 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;
+ }
+}