-rw-r--r-- | library/process_unix.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/library/process_unix.cpp b/library/process_unix.cpp index b599edb..e0fbf8c 100644 --- a/library/process_unix.cpp +++ b/library/process_unix.cpp @@ -1,260 +1,260 @@ /********************************************************************** -** Copyright (C) 2000 Trolltech AS. All rights reserved. +** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. ** -** This file is part of Qtopia Environment. +** This file is part of the Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #ifndef QT_H # include <qfeatures.h> #endif // QT_H #ifndef QT_NO_PROCESS //#include "qplatformdefs.h" #include <stdio.h> #include <unistd.h> #include <signal.h> #include <sys/types.h> #include <sys/socket.h> #include <fcntl.h> #include "process.h" #include "qapplication.h" //#include "qptrqueue.h" //#include "qptrlist.h" #include "qsocketnotifier.h" #include "qtimer.h" //#include "qcleanuphandler.h" #include "qregexp.h" #include <stdlib.h> #include <errno.h> #define QPtrList QList //#define QT_QPROCESS_DEBUG class Proc; class ProcessManager; class ProcessPrivate { public: ProcessPrivate(); ~ProcessPrivate(); void closeOpenSocketsForChild(); void newProc( pid_t pid, Process *process ); QByteArray bufStdout; QByteArray bufStderr; QSocketNotifier *notifierStdin; QSocketNotifier *notifierStdout; QSocketNotifier *notifierStderr; ssize_t stdinBufRead; Proc *proc; bool exitValuesCalculated; bool socketReadCalled; static ProcessManager *procManager; }; /*********************************************************************** * * Proc * **********************************************************************/ /* The class Process does not necessarily map exactly to the running child processes: if the process is finished, the Process class may still be there; furthermore a user can use Process to start more than one process. The helper-class Proc has the semantics that one instance of this class maps directly to a running child process. */ class Proc { public: Proc( pid_t p, Process *proc=0 ) : pid(p), process(proc) { #if defined(QT_QPROCESS_DEBUG) qDebug( "Proc: Constructor for pid %d and Process %p", pid, process ); #endif socketStdin = 0; socketStdout = 0; socketStderr = 0; } ~Proc() { #if defined(QT_QPROCESS_DEBUG) qDebug( "Proc: Destructor for pid %d and Process %p", pid, process ); #endif if ( process != 0 ) { if ( process->d->notifierStdin ) process->d->notifierStdin->setEnabled( FALSE ); if ( process->d->notifierStdout ) process->d->notifierStdout->setEnabled( FALSE ); if ( process->d->notifierStderr ) process->d->notifierStderr->setEnabled( FALSE ); process->d->proc = 0; } if( socketStdin != 0 ) ::close( socketStdin ); // ### close these sockets even on parent exit or is it better only on // sigchld (but what do I have to do with them on exit then)? if( socketStdout != 0 ) ::close( socketStdout ); if( socketStderr != 0 ) ::close( socketStderr ); } pid_t pid; int socketStdin; int socketStdout; int socketStderr; Process *process; }; /*********************************************************************** * * ProcessManager * **********************************************************************/ class ProcessManager : public QObject { Q_OBJECT public: ProcessManager(); ~ProcessManager(); void append( Proc *p ); void remove( Proc *p ); public slots: void removeMe(); public: struct sigaction oldactChld; struct sigaction oldactPipe; QPtrList<Proc> *procList; int sigchldFd[2]; }; ProcessManager::ProcessManager() { procList = new QPtrList<Proc>; procList->setAutoDelete( TRUE ); } ProcessManager::~ProcessManager() { delete procList; } void ProcessManager::append( Proc *p ) { procList->append( p ); #if defined(QT_QPROCESS_DEBUG) qDebug( "ProcessManager: append process (procList.count(): %d)", procList->count() ); #endif } void ProcessManager::remove( Proc *p ) { procList->remove( p ); #if defined(QT_QPROCESS_DEBUG) qDebug( "ProcessManager: remove process (procList.count(): %d)", procList->count() ); #endif if ( procList->count() == 0 ) { QTimer::singleShot( 0, this, SLOT(removeMe()) ); } } void ProcessManager::removeMe() { ProcessPrivate::procManager = 0; delete this; } #include "process_unix.moc" /*********************************************************************** * * ProcessPrivate * **********************************************************************/ ProcessManager *ProcessPrivate::procManager = 0; ProcessPrivate::ProcessPrivate() { #if defined(QT_QPROCESS_DEBUG) qDebug( "ProcessPrivate: Constructor" ); #endif stdinBufRead = 0; notifierStdin = 0; notifierStdout = 0; notifierStderr = 0; exitValuesCalculated = FALSE; socketReadCalled = FALSE; proc = 0; } ProcessPrivate::~ProcessPrivate() { #if defined(QT_QPROCESS_DEBUG) qDebug( "ProcessPrivate: Destructor" ); #endif if ( proc != 0 ) { if ( proc->socketStdin != 0 ) { ::close( proc->socketStdin ); proc->socketStdin = 0; } proc->process = 0; } delete notifierStdin; delete notifierStdout; delete notifierStderr; } /* Closes all open sockets in the child process that are not needed by the child process. Otherwise one child may have an open socket on standard input, etc. of another child. */ void ProcessPrivate::closeOpenSocketsForChild() { if ( procManager != 0 ) { if ( procManager->sigchldFd[0] != 0 ) ::close( procManager->sigchldFd[0] ); if ( procManager->sigchldFd[1] != 0 ) ::close( procManager->sigchldFd[1] ); // close also the sockets from other Process instances Proc *proc; for ( proc=procManager->procList->first(); proc!=0; proc=procManager->procList->next() ) { |