summaryrefslogtreecommitdiff
path: root/libopie2/opiecore/oprocess.cpp
Unidiff
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
15   .i_,=:_.      -<s. This program is distributed in the hope that 15   .i_,=:_.      -<s. This program is distributed in the hope that
16    +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 16    +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
17   : ..    .:,     . . . without even the implied warranty of 17   : ..    .:,     . . . without even the implied warranty of
18   =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 18   =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
19 _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 19 _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
20..}^=.=       =       ; Library General Public License for more 20..}^=.=       =       ; Library General Public License for more
21++=   -.     .`     .: details. 21++=   -.     .`     .: details.
22:     =  ...= . :.=- 22:     =  ...= . :.=-
23-.   .:....=;==+<; You should have received a copy of the GNU 23-.   .:....=;==+<; You should have received a copy of the GNU
24 -_. . .   )=.  = Library General Public License along with 24 -_. . .   )=.  = Library General Public License along with
25   --        :-=` this library; see the file COPYING.LIB. 25   --        :-=` this library; see the file COPYING.LIB.
26 If not, write to the Free Software Foundation, 26 If not, write to the Free Software Foundation,
27 Inc., 59 Temple Place - Suite 330, 27 Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. 28 Boston, MA 02111-1307, USA.
29*/ 29*/
30 30
31#include "oprocctrl.h" 31#include "oprocctrl.h"
32 32
33/* OPIE */ 33/* OPIE */
34#include <opie2/oprocess.h> 34#include <opie2/oprocess.h>
35 35
36/* QT */ 36/* QT */
37 37
38#include <qapplication.h> 38#include <qapplication.h>
39#include <qdir.h>
39#include <qfile.h> 40#include <qfile.h>
40#include <qmap.h> 41#include <qmap.h>
41#include <qregexp.h> 42#include <qregexp.h>
42#include <qsocketnotifier.h> 43#include <qsocketnotifier.h>
44#include <qtextstream.h>
43 45
44/* STD */ 46/* STD */
45#include <errno.h> 47#include <errno.h>
46#include <fcntl.h> 48#include <fcntl.h>
47#include <pwd.h> 49#include <pwd.h>
48#include <stdlib.h> 50#include <stdlib.h>
49#include <signal.h> 51#include <signal.h>
50#include <stdio.h> 52#include <stdio.h>
51#include <string.h> 53#include <string.h>
52#include <sys/time.h> 54#include <sys/time.h>
53#include <sys/types.h> 55#include <sys/types.h>
54#include <sys/stat.h> 56#include <sys/stat.h>
55#include <sys/socket.h> 57#include <sys/socket.h>
56#include <unistd.h> 58#include <unistd.h>
57#ifdef HAVE_SYS_SELECT_H 59#ifdef HAVE_SYS_SELECT_H
58#include <sys/select.h> 60#include <sys/select.h>
59#endif 61#endif
60#ifdef HAVE_INITGROUPS 62#ifdef HAVE_INITGROUPS
61#include <grp.h> 63#include <grp.h>
62#endif 64#endif
63 65
64class OProcessPrivate 66class OProcessPrivate
65{ 67{
66public: 68public:
@@ -892,24 +894,52 @@ bool OProcess::isExecutable( const QCString &filename )
892 // CC: return false if the file does not exist 894 // CC: return false if the file does not exist
893 895
894 // CC: anyway, we cannot execute directories, block/character devices, fifos or sockets 896 // CC: anyway, we cannot execute directories, block/character devices, fifos or sockets
895 if ( ( S_ISDIR( fileinfo.st_mode ) ) || 897 if ( ( S_ISDIR( fileinfo.st_mode ) ) ||
896 ( S_ISCHR( fileinfo.st_mode ) ) || 898 ( S_ISCHR( fileinfo.st_mode ) ) ||
897 ( S_ISBLK( fileinfo.st_mode ) ) || 899 ( S_ISBLK( fileinfo.st_mode ) ) ||
898#ifdef S_ISSOCK 900#ifdef S_ISSOCK
899 // CC: SYSVR4 systems don't have that macro 901 // CC: SYSVR4 systems don't have that macro
900 ( S_ISSOCK( fileinfo.st_mode ) ) || 902 ( S_ISSOCK( fileinfo.st_mode ) ) ||
901#endif 903#endif
902 ( S_ISFIFO( fileinfo.st_mode ) ) || 904 ( S_ISFIFO( fileinfo.st_mode ) ) ||
903 ( S_ISDIR( fileinfo.st_mode ) ) ) 905 ( S_ISDIR( fileinfo.st_mode ) ) )
904 { 906 {
905 return false; 907 return false;
906 } 908 }
907 909
908 // CC: now check for permission to execute the file 910 // CC: now check for permission to execute the file
909 if ( access( filename.data(), X_OK ) != 0 ) 911 if ( access( filename.data(), X_OK ) != 0 )
910 return false; 912 return false;
911 913
912 // CC: we've passed all the tests... 914 // CC: we've passed all the tests...
913 return true; 915 return true;
914} 916}
915 917
918int OProcess::processPID( const QString& process )
919{
920 QString line;
921 QDir d = QDir( "/proc" );
922 QStringList dirs = d.entryList( QDir::Dirs );
923 QStringList::Iterator it;
924 for ( it = dirs.begin(); it != dirs.end(); ++it )
925 {
926 //qDebug( "next entry: %s", (const char*) *it );
927 QFile file( "/proc/"+*it+"/cmdline" );
928 file.open( IO_ReadOnly );
929 if ( !file.isOpen() ) continue;
930 QTextStream t( &file );
931 line = t.readLine();
932 //qDebug( "cmdline = %s", (const char*) line );
933 if ( line.contains( process ) ) break; //FIXME: That may find also other process, if the name is not long enough ;)
934 }
935 if ( line.contains( process ) )
936 {
937 //qDebug( "found process id #%d", (*it).toInt() );
938 return (*it).toInt();
939 }
940 else
941 {
942 //qDebug( "process '%s' not found", (const char*) process );
943 return -1;
944 }
945}