Diffstat (limited to 'libopie2/opiecore/oprocess.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiecore/oprocess.cpp | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/libopie2/opiecore/oprocess.cpp b/libopie2/opiecore/oprocess.cpp index 6349c83..dfde74a 100644 --- a/libopie2/opiecore/oprocess.cpp +++ b/libopie2/opiecore/oprocess.cpp | |||
@@ -16,108 +16,113 @@ _;:, .> :=|. This program is free software; you can | |||
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 <qdir.h> |
40 | #include <qmap.h> | 40 | #include <qmap.h> |
41 | #include <qsocketnotifier.h> | 41 | #include <qsocketnotifier.h> |
42 | #include <qtextstream.h> | 42 | #include <qtextstream.h> |
43 | 43 | ||
44 | /* STD */ | 44 | /* STD */ |
45 | #include <errno.h> | 45 | #include <errno.h> |
46 | #include <fcntl.h> | 46 | #include <fcntl.h> |
47 | #include <pwd.h> | 47 | #include <pwd.h> |
48 | #include <stdlib.h> | 48 | #include <stdlib.h> |
49 | #include <signal.h> | 49 | #include <signal.h> |
50 | #include <stdio.h> | 50 | #include <stdio.h> |
51 | #include <string.h> | 51 | #include <string.h> |
52 | #include <sys/time.h> | 52 | #include <sys/time.h> |
53 | #include <sys/types.h> | 53 | #include <sys/types.h> |
54 | #include <sys/stat.h> | 54 | #include <sys/stat.h> |
55 | #include <sys/socket.h> | 55 | #include <sys/socket.h> |
56 | #include <unistd.h> | 56 | #include <unistd.h> |
57 | #ifdef HAVE_SYS_SELECT_H | 57 | #ifdef HAVE_SYS_SELECT_H |
58 | #include <sys/select.h> | 58 | #include <sys/select.h> |
59 | #endif | 59 | #endif |
60 | #ifdef HAVE_INITGROUPS | 60 | #ifdef HAVE_INITGROUPS |
61 | #include <grp.h> | 61 | #include <grp.h> |
62 | #endif | 62 | #endif |
63 | 63 | ||
64 | using namespace Opie::Core::Private; | ||
65 | |||
66 | namespace Opie { | ||
67 | namespace Core { | ||
68 | namespace Private { | ||
64 | class OProcessPrivate | 69 | class OProcessPrivate |
65 | { | 70 | { |
66 | public: | 71 | public: |
67 | OProcessPrivate() : useShell( false ) | 72 | OProcessPrivate() : useShell( false ) |
68 | { } | 73 | { } |
69 | 74 | ||
70 | bool useShell; | 75 | bool useShell; |
71 | QMap<QString, QString> env; | 76 | QMap<QString, QString> env; |
72 | QString wd; | 77 | QString wd; |
73 | QCString shell; | 78 | QCString shell; |
74 | }; | 79 | }; |
75 | 80 | } | |
76 | 81 | ||
77 | OProcess::OProcess( QObject *parent, const char *name ) | 82 | OProcess::OProcess( QObject *parent, const char *name ) |
78 | : QObject( parent, name ) | 83 | : QObject( parent, name ) |
79 | { | 84 | { |
80 | init ( ); | 85 | init ( ); |
81 | } | 86 | } |
82 | 87 | ||
83 | OProcess::OProcess( const QString &arg0, QObject *parent, const char *name ) | 88 | OProcess::OProcess( const QString &arg0, QObject *parent, const char *name ) |
84 | : QObject( parent, name ) | 89 | : QObject( parent, name ) |
85 | { | 90 | { |
86 | init ( ); | 91 | init ( ); |
87 | *this << arg0; | 92 | *this << arg0; |
88 | } | 93 | } |
89 | 94 | ||
90 | OProcess::OProcess( const QStringList &args, QObject *parent, const char *name ) | 95 | OProcess::OProcess( const QStringList &args, QObject *parent, const char *name ) |
91 | : QObject( parent, name ) | 96 | : QObject( parent, name ) |
92 | { | 97 | { |
93 | init ( ); | 98 | init ( ); |
94 | *this << args; | 99 | *this << args; |
95 | } | 100 | } |
96 | 101 | ||
97 | void OProcess::init ( ) | 102 | void OProcess::init ( ) |
98 | { | 103 | { |
99 | run_mode = NotifyOnExit; | 104 | run_mode = NotifyOnExit; |
100 | runs = false; | 105 | runs = false; |
101 | pid_ = 0; | 106 | pid_ = 0; |
102 | status = 0; | 107 | status = 0; |
103 | keepPrivs = false; | 108 | keepPrivs = false; |
104 | innot = 0; | 109 | innot = 0; |
105 | outnot = 0; | 110 | outnot = 0; |
106 | errnot = 0; | 111 | errnot = 0; |
107 | communication = NoCommunication; | 112 | communication = NoCommunication; |
108 | input_data = 0; | 113 | input_data = 0; |
109 | input_sent = 0; | 114 | input_sent = 0; |
110 | input_total = 0; | 115 | input_total = 0; |
111 | d = 0; | 116 | d = 0; |
112 | 117 | ||
113 | if ( 0 == OProcessController::theOProcessController ) | 118 | if ( 0 == OProcessController::theOProcessController ) |
114 | { | 119 | { |
115 | ( void ) new OProcessController(); | 120 | ( void ) new OProcessController(); |
116 | CHECK_PTR( OProcessController::theOProcessController ); | 121 | CHECK_PTR( OProcessController::theOProcessController ); |
117 | } | 122 | } |
118 | 123 | ||
119 | OProcessController::theOProcessController->addOProcess( this ); | 124 | OProcessController::theOProcessController->addOProcess( this ); |
120 | out[ 0 ] = out[ 1 ] = -1; | 125 | out[ 0 ] = out[ 1 ] = -1; |
121 | in[ 0 ] = in[ 1 ] = -1; | 126 | in[ 0 ] = in[ 1 ] = -1; |
122 | err[ 0 ] = err[ 1 ] = -1; | 127 | err[ 0 ] = err[ 1 ] = -1; |
123 | } | 128 | } |
@@ -896,48 +901,51 @@ bool OProcess::isExecutable( const QCString &filename ) | |||
896 | ( S_ISCHR( fileinfo.st_mode ) ) || | 901 | ( S_ISCHR( fileinfo.st_mode ) ) || |
897 | ( S_ISBLK( fileinfo.st_mode ) ) || | 902 | ( S_ISBLK( fileinfo.st_mode ) ) || |
898 | #ifdef S_ISSOCK | 903 | #ifdef S_ISSOCK |
899 | // CC: SYSVR4 systems don't have that macro | 904 | // CC: SYSVR4 systems don't have that macro |
900 | ( S_ISSOCK( fileinfo.st_mode ) ) || | 905 | ( S_ISSOCK( fileinfo.st_mode ) ) || |
901 | #endif | 906 | #endif |
902 | ( S_ISFIFO( fileinfo.st_mode ) ) || | 907 | ( S_ISFIFO( fileinfo.st_mode ) ) || |
903 | ( S_ISDIR( fileinfo.st_mode ) ) ) | 908 | ( S_ISDIR( fileinfo.st_mode ) ) ) |
904 | { | 909 | { |
905 | return false; | 910 | return false; |
906 | } | 911 | } |
907 | 912 | ||
908 | // CC: now check for permission to execute the file | 913 | // CC: now check for permission to execute the file |
909 | if ( access( filename.data(), X_OK ) != 0 ) | 914 | if ( access( filename.data(), X_OK ) != 0 ) |
910 | return false; | 915 | return false; |
911 | 916 | ||
912 | // CC: we've passed all the tests... | 917 | // CC: we've passed all the tests... |
913 | return true; | 918 | return true; |
914 | } | 919 | } |
915 | 920 | ||
916 | int OProcess::processPID( const QString& process ) | 921 | int OProcess::processPID( const QString& process ) |
917 | { | 922 | { |
918 | QString line; | 923 | QString line; |
919 | QDir d = QDir( "/proc" ); | 924 | QDir d = QDir( "/proc" ); |
920 | QStringList dirs = d.entryList( QDir::Dirs ); | 925 | QStringList dirs = d.entryList( QDir::Dirs ); |
921 | QStringList::Iterator it; | 926 | QStringList::Iterator it; |
922 | for ( it = dirs.begin(); it != dirs.end(); ++it ) | 927 | for ( it = dirs.begin(); it != dirs.end(); ++it ) |
923 | { | 928 | { |
924 | //qDebug( "next entry: %s", (const char*) *it ); | 929 | //qDebug( "next entry: %s", (const char*) *it ); |
925 | QFile file( "/proc/"+*it+"/cmdline" ); | 930 | QFile file( "/proc/"+*it+"/cmdline" ); |
926 | file.open( IO_ReadOnly ); | 931 | file.open( IO_ReadOnly ); |
927 | if ( !file.isOpen() ) continue; | 932 | if ( !file.isOpen() ) continue; |
928 | QTextStream t( &file ); | 933 | QTextStream t( &file ); |
929 | line = t.readLine(); | 934 | line = t.readLine(); |
930 | //qDebug( "cmdline = %s", (const char*) line ); | 935 | //qDebug( "cmdline = %s", (const char*) line ); |
931 | if ( line.contains( process ) ) break; //FIXME: That may find also other process, if the name is not long enough ;) | 936 | if ( line.contains( process ) ) break; //FIXME: That may find also other process, if the name is not long enough ;) |
932 | } | 937 | } |
933 | if ( line.contains( process ) ) | 938 | if ( line.contains( process ) ) |
934 | { | 939 | { |
935 | //qDebug( "found process id #%d", (*it).toInt() ); | 940 | //qDebug( "found process id #%d", (*it).toInt() ); |
936 | return (*it).toInt(); | 941 | return (*it).toInt(); |
937 | } | 942 | } |
938 | else | 943 | else |
939 | { | 944 | { |
940 | //qDebug( "process '%s' not found", (const char*) process ); | 945 | //qDebug( "process '%s' not found", (const char*) process ); |
941 | return 0; | 946 | return 0; |
942 | } | 947 | } |
943 | } | 948 | } |
949 | |||
950 | } | ||
951 | } | ||