summaryrefslogtreecommitdiff
path: root/library
authorsandman <sandman>2002-12-17 00:29:22 (UTC)
committer sandman <sandman>2002-12-17 00:29:22 (UTC)
commit2d39ff65b27c1a680a56c1b70b534e3cb767e08f (patch) (side-by-side diff)
tree09e5cc3f7157681fe51fe83bb54ebbaa548d8c64 /library
parent70090722d240bed8c390281e072c9bcfc5ba7782 (diff)
downloadopie-2d39ff65b27c1a680a56c1b70b534e3cb767e08f.zip
opie-2d39ff65b27c1a680a56c1b70b534e3cb767e08f.tar.gz
opie-2d39ff65b27c1a680a56c1b70b534e3cb767e08f.tar.bz2
replaced the simple fork and execv method of starting applications with a
more sophisticated method (mostly taken from K/OProcess, because we can't use libopie in libqpe). We can detect now, if apps can not be started.
Diffstat (limited to 'library') (more/less context) (show whitespace changes)
-rw-r--r--library/global.cpp49
1 files changed, 46 insertions, 3 deletions
diff --git a/library/global.cpp b/library/global.cpp
index d6ba84f..68a3a75 100644
--- a/library/global.cpp
+++ b/library/global.cpp
@@ -44,2 +44,3 @@
#include <unistd.h>
+#include <errno.h>
@@ -606,6 +607,20 @@ void Global::invoke(const QString &c)
{
- if ( !::vfork() ) {
- for ( int fd = 3; fd < 100; fd++ )
+ bool success = false;
+ int pfd [2];
+ if ( ::pipe ( pfd ) < 0 )
+ pfd [0] = pfd [1] = -1;
+
+ pid_t pid = ::fork ( );
+
+ if ( pid == 0 ) { // child
+ for ( int fd = 3; fd < 100; fd++ ) {
+ if ( fd != pfd [1] )
::close( fd );
+ }
::setpgid( ::getpid(), ::getppid() );
+
+ // Closing of fd[1] indicates that the execvp succeeded!
+ if ( pfd [1] >= 0 )
+ ::fcntl ( pfd [1], F_SETFD, FD_CLOEXEC );
+
// Try bindir first, so that foo/bar works too
@@ -613,6 +628,34 @@ void Global::invoke(const QString &c)
::execvp( args[0], (char * const *)args );
- _exit( -1 );
+
+ char resultByte = 1;
+ if ( pfd [1] >= 0 )
+ ::write ( pfd [1], &resultByte, 1 );
+ ::_exit ( -1 );
+ }
+ else if ( pid > 0 ) {
+ success = true;
+
+ if ( pfd [1] >= 0 )
+ ::close ( pfd [1] );
+ if ( pfd [0] >= 0 ) {
+ while ( true ) {
+ char resultByte;
+ int n = ::read ( pfd [0], &resultByte, 1 );
+ if ( n == 1 ) {
+ success = false;
+ break;
+ }
+ if (( n == -1 ) && (( errno == ECHILD ) || ( errno == EINTR )))
+ continue;
+
+ break; // success
+ }
+ ::close ( pfd [0] );
}
}
+ if ( success )
StartingAppList::add( list[0] );
+ else
+ QMessageBox::warning( 0, "Error", "Could not start the application " + c, "Ok", 0, 0, 0, 1 );
+ }
#endif //QT_NO_QWS_MULTIPROCESS