From dc549c3641efcd9cf0af5999f380796cce3fb0b6 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Sat, 7 Dec 2024 17:20:25 +0900 Subject: Rename kprocctrl.{h,cpp} to tdeprocctrl.{h.cpp}. Add temporary kprocctrl.h to keep things building. Signed-off-by: Michele Calgaro --- tdecore/CMakeLists.txt | 4 +- tdecore/MAINTAINERS | 2 +- tdecore/Makefile.am | 4 +- tdecore/kprocctrl.cpp | 277 --------------------------------------------- tdecore/kprocctrl.h | 151 +----------------------- tdecore/tdeapplication.cpp | 2 +- tdecore/tdeprocctrl.cpp | 277 +++++++++++++++++++++++++++++++++++++++++++++ tdecore/tdeprocctrl.h | 150 ++++++++++++++++++++++++ tdecore/tdeprocess.cpp | 2 +- 9 files changed, 435 insertions(+), 434 deletions(-) delete mode 100644 tdecore/kprocctrl.cpp create mode 100644 tdecore/tdeprocctrl.cpp create mode 100644 tdecore/tdeprocctrl.h (limited to 'tdecore') diff --git a/tdecore/CMakeLists.txt b/tdecore/CMakeLists.txt index 47b055921..cabd1d26e 100644 --- a/tdecore/CMakeLists.txt +++ b/tdecore/CMakeLists.txt @@ -53,7 +53,7 @@ install( FILES tdeconfigdialogmanager.h tdeconfigbase.h kdesktopfile.h kurl.h ksock.h tdeaboutdata.h tdecmdlineargs.h tdeconfigbackend.h tdeapplication.h tdeuniqueapplication.h - kcharsets.h tdeversion.h kpty.h tdeprocess.h kprocctrl.h + kcharsets.h tdeversion.h kpty.h tdeprocess.h tdeprocctrl.h kprocctrl.h tdelocale.h kicontheme.h kiconloader.h kdebug.h twinmodule.h twin.h krootprop.h tdeshortcut.h kkeynative.h tdeaccel.h kglobalaccel.h tdestdaccel.h tdeshortcutlist.h kcatalogue.h @@ -108,7 +108,7 @@ set( ${target}_SRCS libintl.cpp tdeapplication.cpp kdebug.cpp netwm.cpp tdeconfigbase.cpp tdeconfig.cpp ksimpleconfig.cpp tdeconfigbackend.cpp kmanagerselection.cpp kdesktopfile.cpp kstandarddirs.cpp - ksock.cpp kpty.cpp tdeprocess.cpp kprocctrl.cpp tdelocale.cpp + ksock.cpp kpty.cpp tdeprocess.cpp tdeprocctrl.cpp tdelocale.cpp krfcdate.cpp kiconeffect.cpp kicontheme.cpp kiconloader.cpp twin.cpp twinmodule.cpp krootprop.cpp kcharsets.cpp kckey.cpp tdeshortcut.cpp kkeynative_x11.cpp kkeyserver_x11.cpp diff --git a/tdecore/MAINTAINERS b/tdecore/MAINTAINERS index d7012b321..1bc8f7a8c 100644 --- a/tdecore/MAINTAINERS +++ b/tdecore/MAINTAINERS @@ -48,7 +48,7 @@ tdemultipledrag.cpp David Faure knotifyclient.cpp kpalette.cpp Waldo Bastian kpixmapprovider.cpp Carsten Pfeiffer -kprocctrl.cpp Waldo Bastian +tdeprocctrl.cpp Waldo Bastian tdeprocess.cpp Waldo Bastian kprocio.cpp Waldo Bastian krandomsequence.cpp Waldo Bastian diff --git a/tdecore/Makefile.am b/tdecore/Makefile.am index 94609314c..c03350fbb 100644 --- a/tdecore/Makefile.am +++ b/tdecore/Makefile.am @@ -41,7 +41,7 @@ include_HEADERS = tdeconfig.h tdeconfigskeleton.h \ tdeconfigbase.h kdesktopfile.h kurl.h ksock.h tdeaboutdata.h \ tdecmdlineargs.h tdeconfigbackend.h tdeapplication.h \ tdeuniqueapplication.h kcharsets.h tdeversion.h kpty.h tdeprocess.h \ - kprocctrl.h tdelocale.h kicontheme.h kiconloader.h kdebug.h \ + kprocctrl.h tdeprocctrl.h tdelocale.h kicontheme.h kiconloader.h kdebug.h \ twinmodule.h twin.h krootprop.h tdeshortcut.h kkeynative.h tdeaccel.h \ kglobalaccel.h tdestdaccel.h tdeshortcutlist.h kcatalogue.h \ kregexp.h kcompletion.h kstringhandler.h \ @@ -92,7 +92,7 @@ noinst_HEADERS = tdeaccelaction.h tdeaccelbase.h tdeaccelprivate.h kckey.h \ libtdecore_la_SOURCES = libintl.cpp tdeapplication.cpp \ kdebug.cpp netwm.cpp tdeconfigbase.cpp tdeconfig.cpp ksimpleconfig.cpp \ tdeconfigbackend.cpp kmanagerselection.cpp kdesktopfile.cpp \ - kstandarddirs.cpp ksock.cpp kpty.cpp tdeprocess.cpp kprocctrl.cpp \ + kstandarddirs.cpp ksock.cpp kpty.cpp tdeprocess.cpp tdeprocctrl.cpp \ tdelocale.cpp krfcdate.cpp kiconeffect.cpp kicontheme.cpp \ kiconloader.cpp twin.cpp twinmodule.cpp krootprop.cpp kcharsets.cpp \ kckey.cpp tdeshortcut.cpp kkeynative_x11.cpp kkeyserver_x11.cpp \ diff --git a/tdecore/kprocctrl.cpp b/tdecore/kprocctrl.cpp deleted file mode 100644 index 471642ddb..000000000 --- a/tdecore/kprocctrl.cpp +++ /dev/null @@ -1,277 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 1997 Christian Czezakte (e9025461@student.tuwien.ac.at) - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include "tdeprocess.h" -#include "kprocctrl.h" - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -TDEProcessController *TDEProcessController::theTDEProcessController; -int TDEProcessController::refCount; - -void TDEProcessController::ref() -{ - if( !refCount ) { - theTDEProcessController = new TDEProcessController; - setupHandlers(); - } - refCount++; -} - -void TDEProcessController::deref() -{ - refCount--; - if( !refCount ) { - resetHandlers(); - delete theTDEProcessController; - theTDEProcessController = 0; - } -} - -TDEProcessController::TDEProcessController() - : needcheck( false ) -{ - if( pipe( fd ) ) - { - perror( "pipe" ); - abort(); - } - - fcntl( fd[0], F_SETFL, O_NONBLOCK ); // in case slotDoHousekeeping is called without polling first - fcntl( fd[1], F_SETFL, O_NONBLOCK ); // in case it fills up - fcntl( fd[0], F_SETFD, FD_CLOEXEC ); - fcntl( fd[1], F_SETFD, FD_CLOEXEC ); - - notifier = new TQSocketNotifier( fd[0], TQSocketNotifier::Read ); - notifier->setEnabled( true ); - TQObject::connect( notifier, TQ_SIGNAL(activated(int)), - TQ_SLOT(slotDoHousekeeping())); -} - -TDEProcessController::~TDEProcessController() -{ - delete notifier; - - close( fd[0] ); - close( fd[1] ); -} - - -extern "C" { -static void theReaper( int num ) -{ - TDEProcessController::theSigCHLDHandler( num ); -} -} - -#ifdef Q_OS_UNIX -struct sigaction TDEProcessController::oldChildHandlerData; -#endif -bool TDEProcessController::handlerSet = false; - -void TDEProcessController::setupHandlers() -{ - if( handlerSet ) - return; - handlerSet = true; - -#ifdef Q_OS_UNIX - struct sigaction act; - sigemptyset( &act.sa_mask ); - - act.sa_handler = SIG_IGN; - act.sa_flags = 0; - sigaction( SIGPIPE, &act, 0L ); - - act.sa_handler = theReaper; - act.sa_flags = SA_NOCLDSTOP; - // CC: take care of SunOS which automatically restarts interrupted system - // calls (and thus does not have SA_RESTART) -#ifdef SA_RESTART - act.sa_flags |= SA_RESTART; -#endif - sigaction( SIGCHLD, &act, &oldChildHandlerData ); - - sigaddset( &act.sa_mask, SIGCHLD ); - // Make sure we don't block this signal. gdb tends to do that :-( - sigprocmask( SIG_UNBLOCK, &act.sa_mask, 0 ); -#else - //TODO: win32 -#endif -} - -void TDEProcessController::resetHandlers() -{ - if( !handlerSet ) - return; - handlerSet = false; - -#ifdef Q_OS_UNIX - sigaction( SIGCHLD, &oldChildHandlerData, 0 ); -#else - //TODO: win32 -#endif - // there should be no problem with SIGPIPE staying SIG_IGN -} - -// the pipe is needed to sync the child reaping with our event processing, -// as otherwise there are race conditions, locking requirements, and things -// generally get harder -void TDEProcessController::theSigCHLDHandler( int arg ) -{ - int saved_errno = errno; - - char dummy = 0; - ::write( theTDEProcessController->fd[1], &dummy, 1 ); - -#ifdef Q_OS_UNIX - if( oldChildHandlerData.sa_handler != SIG_IGN && - oldChildHandlerData.sa_handler != SIG_DFL ) - oldChildHandlerData.sa_handler( arg ); // call the old handler -#else - //TODO: win32 -#endif - - errno = saved_errno; -} - -int TDEProcessController::notifierFd() const -{ - return fd[0]; -} - -void TDEProcessController::unscheduleCheck() -{ - char dummy[16]; // somewhat bigger - just in case several have queued up - if( ::read( fd[0], dummy, sizeof(dummy) ) > 0 ) - needcheck = true; -} - -void -TDEProcessController::rescheduleCheck() -{ - if( needcheck ) - { - needcheck = false; - char dummy = 0; - ::write( fd[1], &dummy, 1 ); - } -} - -void TDEProcessController::slotDoHousekeeping() -{ - char dummy[16]; // somewhat bigger - just in case several have queued up - ::read( fd[0], dummy, sizeof(dummy) ); - - int status; - again: - TQValueListIterator it( kProcessList.begin() ); - TQValueListIterator eit( kProcessList.end() ); - while( it != eit ) - { - TDEProcess *prc = *it; - if( prc->runs && waitpid( prc->pid_, &status, WNOHANG ) > 0 ) - { - prc->processHasExited( status ); - // the callback can nuke the whole process list and even 'this' - if (!theTDEProcessController) - return; - goto again; - } - ++it; - } - TQValueListIterator uit( unixProcessList.begin() ); - TQValueListIterator ueit( unixProcessList.end() ); - while( uit != ueit ) - { - if( waitpid( *uit, 0, WNOHANG ) > 0 ) - { - uit = unixProcessList.remove( uit ); - deref(); // counterpart to addProcess, can invalidate 'this' - } else - ++uit; - } -} - -bool TDEProcessController::waitForProcessExit( int timeout ) -{ -#ifdef Q_OS_UNIX - for(;;) - { - struct timeval tv, *tvp; - if (timeout < 0) - tvp = 0; - else - { - tv.tv_sec = timeout; - tv.tv_usec = 0; - tvp = &tv; - } - - fd_set fds; - FD_ZERO( &fds ); - FD_SET( fd[0], &fds ); - - switch( select( fd[0]+1, &fds, 0, 0, tvp ) ) - { - case -1: - if( errno == EINTR ) - continue; - // fall through; should never happen - case 0: - return false; - default: - slotDoHousekeeping(); - return true; - } - } -#else - //TODO: win32 - return false; -#endif -} - -void TDEProcessController::addTDEProcess( TDEProcess* p ) -{ - kProcessList.append( p ); -} - -void TDEProcessController::removeTDEProcess( TDEProcess* p ) -{ - kProcessList.remove( p ); -} - -void TDEProcessController::addProcess( int pid ) -{ - unixProcessList.append( pid ); - ref(); // make sure we stay around when the TDEProcess goes away -} - -#include "kprocctrl.moc" diff --git a/tdecore/kprocctrl.h b/tdecore/kprocctrl.h index ddd59179b..13b6d585b 100644 --- a/tdecore/kprocctrl.h +++ b/tdecore/kprocctrl.h @@ -1,150 +1 @@ -/* This file is part of the KDE libraries - Copyright (C) 1997 Christian Czezakte (e9025461@student.tuwien.ac.at) - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef __KPROCCTRL_H__ -#define __KPROCCTRL_H__ - -#include - -#include "tdeprocess.h" - -class TQSocketNotifier; - -/** - * @short Used internally by TDEProcess - * @internal - * @author Christian Czezatke - * - * A class for internal use by TDEProcess only. -- Exactly one instance - * of this class is created by TDEApplication. - * - * This class takes care of the actual (UN*X) signal handling. - */ -class TDECORE_EXPORT TDEProcessController : public TQObject -{ - TQ_OBJECT - -public: - /** - * Create an instance if none exists yet. - * Called by TDEApplication::TDEApplication() - */ - static void ref(); - - /** - * Destroy the instance if one exists and it is not referenced any more. - * Called by TDEApplication::~TDEApplication() - */ - static void deref(); - - /** - * Only a single instance of this class is allowed at a time, - * and this static variable is used to track the one instance. - */ - static TDEProcessController *theTDEProcessController; // kde4: rename: instance - - /** - * Automatically called upon SIGCHLD. Never call it directly. - * If your application (or some library it uses) redirects SIGCHLD, - * the new signal handler (and only it) should call the old handler - * returned by sigaction(). - * @internal - */ - static void theSigCHLDHandler(int signal); // KDE4: private - - /** - * Wait for any process to exit and handle their exit without - * starting an event loop. - * This function may cause TDEProcess to emit any of its signals. - * - * @param timeout the timeout in seconds. -1 means no timeout. - * @return true if a process exited, false - * if no process exited within @p timeout seconds. - * @since 3.1 - */ - bool waitForProcessExit(int timeout); - - /** - * Call this function to defer processing of the data that became available - * on notifierFd(). - * @since 3.2 - */ - void unscheduleCheck(); - - /** - * This function @em must be called at some point after calling - * unscheduleCheck(). - * @since 3.2 - */ - void rescheduleCheck(); - - /* - * Obtain the file descriptor TDEProcessController uses to get notified - * about process exits. select() or poll() on it if you create a custom - * event loop that needs to act upon SIGCHLD. - * @return the file descriptor of the reading end of the notification pipe - * @since 3.2 - */ - int notifierFd() const; - - /** - * @internal - */ - void addTDEProcess( TDEProcess* ); - /** - * @internal - */ - void removeTDEProcess( TDEProcess* ); - /** - * @internal - */ - void addProcess( int pid ); - -private slots: - void slotDoHousekeeping(); - -private: - friend class I_just_love_gcc; - - int fd[2]; - bool needcheck; - TQSocketNotifier *notifier; - TQValueList kProcessList; - TQValueList unixProcessList; - - static void setupHandlers(); - static void resetHandlers(); - static struct sigaction oldChildHandlerData; - static bool handlerSet; - - static int refCount; - - // Disallow instantiation - TDEProcessController(); - ~TDEProcessController(); - - // Disallow assignment and copy-construction - TDEProcessController( const TDEProcessController& ); - TDEProcessController& operator= ( const TDEProcessController& ); -}; - - - -#endif - +#include "tdeprocctrl.h" diff --git a/tdecore/tdeapplication.cpp b/tdecore/tdeapplication.cpp index 6b48f805a..cc5410d7a 100644 --- a/tdecore/tdeapplication.cpp +++ b/tdecore/tdeapplication.cpp @@ -128,7 +128,7 @@ #include #endif -#include "kprocctrl.h" +#include "tdeprocctrl.h" #ifdef HAVE_PATHS_H #include diff --git a/tdecore/tdeprocctrl.cpp b/tdecore/tdeprocctrl.cpp new file mode 100644 index 000000000..05ff0566a --- /dev/null +++ b/tdecore/tdeprocctrl.cpp @@ -0,0 +1,277 @@ +/* This file is part of the KDE libraries + Copyright (C) 1997 Christian Czezakte (e9025461@student.tuwien.ac.at) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "tdeprocess.h" +#include "tdeprocctrl.h" + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +TDEProcessController *TDEProcessController::theTDEProcessController; +int TDEProcessController::refCount; + +void TDEProcessController::ref() +{ + if( !refCount ) { + theTDEProcessController = new TDEProcessController; + setupHandlers(); + } + refCount++; +} + +void TDEProcessController::deref() +{ + refCount--; + if( !refCount ) { + resetHandlers(); + delete theTDEProcessController; + theTDEProcessController = 0; + } +} + +TDEProcessController::TDEProcessController() + : needcheck( false ) +{ + if( pipe( fd ) ) + { + perror( "pipe" ); + abort(); + } + + fcntl( fd[0], F_SETFL, O_NONBLOCK ); // in case slotDoHousekeeping is called without polling first + fcntl( fd[1], F_SETFL, O_NONBLOCK ); // in case it fills up + fcntl( fd[0], F_SETFD, FD_CLOEXEC ); + fcntl( fd[1], F_SETFD, FD_CLOEXEC ); + + notifier = new TQSocketNotifier( fd[0], TQSocketNotifier::Read ); + notifier->setEnabled( true ); + TQObject::connect( notifier, TQ_SIGNAL(activated(int)), + TQ_SLOT(slotDoHousekeeping())); +} + +TDEProcessController::~TDEProcessController() +{ + delete notifier; + + close( fd[0] ); + close( fd[1] ); +} + + +extern "C" { +static void theReaper( int num ) +{ + TDEProcessController::theSigCHLDHandler( num ); +} +} + +#ifdef Q_OS_UNIX +struct sigaction TDEProcessController::oldChildHandlerData; +#endif +bool TDEProcessController::handlerSet = false; + +void TDEProcessController::setupHandlers() +{ + if( handlerSet ) + return; + handlerSet = true; + +#ifdef Q_OS_UNIX + struct sigaction act; + sigemptyset( &act.sa_mask ); + + act.sa_handler = SIG_IGN; + act.sa_flags = 0; + sigaction( SIGPIPE, &act, 0L ); + + act.sa_handler = theReaper; + act.sa_flags = SA_NOCLDSTOP; + // CC: take care of SunOS which automatically restarts interrupted system + // calls (and thus does not have SA_RESTART) +#ifdef SA_RESTART + act.sa_flags |= SA_RESTART; +#endif + sigaction( SIGCHLD, &act, &oldChildHandlerData ); + + sigaddset( &act.sa_mask, SIGCHLD ); + // Make sure we don't block this signal. gdb tends to do that :-( + sigprocmask( SIG_UNBLOCK, &act.sa_mask, 0 ); +#else + //TODO: win32 +#endif +} + +void TDEProcessController::resetHandlers() +{ + if( !handlerSet ) + return; + handlerSet = false; + +#ifdef Q_OS_UNIX + sigaction( SIGCHLD, &oldChildHandlerData, 0 ); +#else + //TODO: win32 +#endif + // there should be no problem with SIGPIPE staying SIG_IGN +} + +// the pipe is needed to sync the child reaping with our event processing, +// as otherwise there are race conditions, locking requirements, and things +// generally get harder +void TDEProcessController::theSigCHLDHandler( int arg ) +{ + int saved_errno = errno; + + char dummy = 0; + ::write( theTDEProcessController->fd[1], &dummy, 1 ); + +#ifdef Q_OS_UNIX + if( oldChildHandlerData.sa_handler != SIG_IGN && + oldChildHandlerData.sa_handler != SIG_DFL ) + oldChildHandlerData.sa_handler( arg ); // call the old handler +#else + //TODO: win32 +#endif + + errno = saved_errno; +} + +int TDEProcessController::notifierFd() const +{ + return fd[0]; +} + +void TDEProcessController::unscheduleCheck() +{ + char dummy[16]; // somewhat bigger - just in case several have queued up + if( ::read( fd[0], dummy, sizeof(dummy) ) > 0 ) + needcheck = true; +} + +void +TDEProcessController::rescheduleCheck() +{ + if( needcheck ) + { + needcheck = false; + char dummy = 0; + ::write( fd[1], &dummy, 1 ); + } +} + +void TDEProcessController::slotDoHousekeeping() +{ + char dummy[16]; // somewhat bigger - just in case several have queued up + ::read( fd[0], dummy, sizeof(dummy) ); + + int status; + again: + TQValueListIterator it( kProcessList.begin() ); + TQValueListIterator eit( kProcessList.end() ); + while( it != eit ) + { + TDEProcess *prc = *it; + if( prc->runs && waitpid( prc->pid_, &status, WNOHANG ) > 0 ) + { + prc->processHasExited( status ); + // the callback can nuke the whole process list and even 'this' + if (!theTDEProcessController) + return; + goto again; + } + ++it; + } + TQValueListIterator uit( unixProcessList.begin() ); + TQValueListIterator ueit( unixProcessList.end() ); + while( uit != ueit ) + { + if( waitpid( *uit, 0, WNOHANG ) > 0 ) + { + uit = unixProcessList.remove( uit ); + deref(); // counterpart to addProcess, can invalidate 'this' + } else + ++uit; + } +} + +bool TDEProcessController::waitForProcessExit( int timeout ) +{ +#ifdef Q_OS_UNIX + for(;;) + { + struct timeval tv, *tvp; + if (timeout < 0) + tvp = 0; + else + { + tv.tv_sec = timeout; + tv.tv_usec = 0; + tvp = &tv; + } + + fd_set fds; + FD_ZERO( &fds ); + FD_SET( fd[0], &fds ); + + switch( select( fd[0]+1, &fds, 0, 0, tvp ) ) + { + case -1: + if( errno == EINTR ) + continue; + // fall through; should never happen + case 0: + return false; + default: + slotDoHousekeeping(); + return true; + } + } +#else + //TODO: win32 + return false; +#endif +} + +void TDEProcessController::addTDEProcess( TDEProcess* p ) +{ + kProcessList.append( p ); +} + +void TDEProcessController::removeTDEProcess( TDEProcess* p ) +{ + kProcessList.remove( p ); +} + +void TDEProcessController::addProcess( int pid ) +{ + unixProcessList.append( pid ); + ref(); // make sure we stay around when the TDEProcess goes away +} + +#include "tdeprocctrl.moc" diff --git a/tdecore/tdeprocctrl.h b/tdecore/tdeprocctrl.h new file mode 100644 index 000000000..fa9a8b3b4 --- /dev/null +++ b/tdecore/tdeprocctrl.h @@ -0,0 +1,150 @@ +/* This file is part of the KDE libraries + Copyright (C) 1997 Christian Czezakte (e9025461@student.tuwien.ac.at) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef __TDEPROCCTRL_H__ +#define __TDEPROCCTRL_H__ + +#include + +#include "tdeprocess.h" + +class TQSocketNotifier; + +/** + * @short Used internally by TDEProcess + * @internal + * @author Christian Czezatke + * + * A class for internal use by TDEProcess only. -- Exactly one instance + * of this class is created by TDEApplication. + * + * This class takes care of the actual (UN*X) signal handling. + */ +class TDECORE_EXPORT TDEProcessController : public TQObject +{ + TQ_OBJECT + +public: + /** + * Create an instance if none exists yet. + * Called by TDEApplication::TDEApplication() + */ + static void ref(); + + /** + * Destroy the instance if one exists and it is not referenced any more. + * Called by TDEApplication::~TDEApplication() + */ + static void deref(); + + /** + * Only a single instance of this class is allowed at a time, + * and this static variable is used to track the one instance. + */ + static TDEProcessController *theTDEProcessController; // kde4: rename: instance + + /** + * Automatically called upon SIGCHLD. Never call it directly. + * If your application (or some library it uses) redirects SIGCHLD, + * the new signal handler (and only it) should call the old handler + * returned by sigaction(). + * @internal + */ + static void theSigCHLDHandler(int signal); // KDE4: private + + /** + * Wait for any process to exit and handle their exit without + * starting an event loop. + * This function may cause TDEProcess to emit any of its signals. + * + * @param timeout the timeout in seconds. -1 means no timeout. + * @return true if a process exited, false + * if no process exited within @p timeout seconds. + * @since 3.1 + */ + bool waitForProcessExit(int timeout); + + /** + * Call this function to defer processing of the data that became available + * on notifierFd(). + * @since 3.2 + */ + void unscheduleCheck(); + + /** + * This function @em must be called at some point after calling + * unscheduleCheck(). + * @since 3.2 + */ + void rescheduleCheck(); + + /* + * Obtain the file descriptor TDEProcessController uses to get notified + * about process exits. select() or poll() on it if you create a custom + * event loop that needs to act upon SIGCHLD. + * @return the file descriptor of the reading end of the notification pipe + * @since 3.2 + */ + int notifierFd() const; + + /** + * @internal + */ + void addTDEProcess( TDEProcess* ); + /** + * @internal + */ + void removeTDEProcess( TDEProcess* ); + /** + * @internal + */ + void addProcess( int pid ); + +private slots: + void slotDoHousekeeping(); + +private: + friend class I_just_love_gcc; + + int fd[2]; + bool needcheck; + TQSocketNotifier *notifier; + TQValueList kProcessList; + TQValueList unixProcessList; + + static void setupHandlers(); + static void resetHandlers(); + static struct sigaction oldChildHandlerData; + static bool handlerSet; + + static int refCount; + + // Disallow instantiation + TDEProcessController(); + ~TDEProcessController(); + + // Disallow assignment and copy-construction + TDEProcessController( const TDEProcessController& ); + TDEProcessController& operator= ( const TDEProcessController& ); +}; + + + +#endif + diff --git a/tdecore/tdeprocess.cpp b/tdecore/tdeprocess.cpp index 767ddcd2d..d3add5843 100644 --- a/tdecore/tdeprocess.cpp +++ b/tdecore/tdeprocess.cpp @@ -23,7 +23,7 @@ #include "tdeprocess.h" -#include "kprocctrl.h" +#include "tdeprocctrl.h" #include "kpty.h" #include -- cgit v1.2.1