home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kprocess.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-10-08  |  29.4 KB  |  935 lines

  1. /* This file is part of the KDE libraries
  2.     Copyright (C) 1997 Christian Czezakte (e9025461@student.tuwien.ac.at)
  3.  
  4.     This library is free software; you can redistribute it and/or
  5.     modify it under the terms of the GNU Library General Public
  6.     License as published by the Free Software Foundation; either
  7.     version 2 of the License, or (at your option) any later version.
  8.  
  9.     This library is distributed in the hope that it will be useful,
  10.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12.     Library General Public License for more details.
  13.  
  14.     You should have received a copy of the GNU Library General Public License
  15.     along with this library; see the file COPYING.LIB.  If not, write to
  16.     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  17.     Boston, MA 02110-1301, USA.
  18. */
  19.  
  20. #ifndef __kprocess_h__
  21. #define __kprocess_h__
  22.  
  23. #include <sys/types.h> // for pid_t
  24. #include <sys/wait.h>
  25. #include <signal.h>
  26. #include <unistd.h>
  27. #include <qvaluelist.h>
  28. #include <qcstring.h>
  29. #include <qobject.h>
  30. #include "kdelibs_export.h"
  31.  
  32. class QSocketNotifier;
  33. class KProcessPrivate;
  34. class KPty;
  35.  
  36. /**
  37.  * Child process invocation, monitoring and control.
  38.  * This class works only in the application's main thread.
  39.  *
  40.  * <b>General usage and features:</b>\n
  41.  *
  42.  * This class allows a KDE application to start child processes without having
  43.  * to worry about UN*X signal handling issues and zombie process reaping.
  44.  *
  45.  * @see KProcIO
  46.  *
  47.  * Basically, this class distinguishes three different ways of running
  48.  * child processes:
  49.  *
  50.  * @li  DontCare -- The child process is invoked and both the child
  51.  * process and the parent process continue concurrently.
  52.  *
  53.  * The process is started in an own session (see setsid(2)).
  54.  *
  55.  * @li  NotifyOnExit -- The child process is invoked and both the
  56.  * child and the parent process run concurrently.
  57.  *
  58.  * When the child process exits, the KProcess instance
  59.  * corresponding to it emits the Qt signal processExited().
  60.  * Since this signal is @em not emitted from within a UN*X
  61.  * signal handler, arbitrary function calls can be made.
  62.  *
  63.  * Be aware: When the KProcess object gets destructed, the child
  64.  * process will be killed if it is still running!
  65.  * This means in particular, that it usually makes no sense to use
  66.  * a KProcess on the stack with NotifyOnExit.
  67.  *
  68.  * @li  OwnGroup -- like NotifyOnExit, but the child process is started
  69.  * in an own process group (and an own session, FWIW). The behavior of
  70.  * kill() changes to killing the whole process group - this makes
  71.  * this mode useful for implementing primitive job management. It can be
  72.  * used to work around broken wrapper scripts that don't propagate signals
  73.  * to the "real" program. However, use this with care, as you disturb the
  74.  * shell's job management if your program is started from the command line.
  75.  *
  76.  * @li  Block -- The child process starts and the parent process
  77.  * is suspended until the child process exits. (@em Really not recommended
  78.  * for programs with a GUI.)
  79.  * In this mode the parent can read the child's output, but can't send it any
  80.  * input.
  81.  *
  82.  * KProcess also provides several functions for determining the exit status
  83.  * and the pid of the child process it represents.
  84.  *
  85.  * Furthermore it is possible to supply command-line arguments to the process
  86.  * in a clean fashion (no null-terminated stringlists and such...)
  87.  *
  88.  * A small usage example:
  89.  * \code
  90.  *   KProcess *proc = new KProcess;
  91.  *
  92.  *   *proc << "my_executable";
  93.  *   *proc << "These" << "are" << "the" << "command" << "line" << "args";
  94.  *   QApplication::connect(proc, SIGNAL(processExited(KProcess *)),
  95.  *                         pointer_to_my_object, SLOT(my_objects_slot(KProcess *)));
  96.  *   proc->start();
  97.  * \endcode
  98.  *
  99.  * This will start "my_executable" with the commandline arguments "These"...
  100.  *
  101.  * When the child process exits, the slot will be invoked.
  102.  *
  103.  * <b>Communication with the child process:</b>\n
  104.  *
  105.  * KProcess supports communication with the child process through
  106.  * stdin/stdout/stderr.
  107.  *
  108.  * The following functions are provided for getting data from the child
  109.  * process or sending data to the child's stdin (For more information,
  110.  * have a look at the documentation of each function):
  111.  *
  112.  * @li writeStdin()
  113.  *  -- Transmit data to the child process' stdin. When all data was sent, the
  114.  * signal wroteStdin() is emitted.
  115.  *
  116.  * @li When data arrives at stdout or stderr, the signal receivedStdout()
  117.  * resp. receivedStderr() is emitted.
  118.  *
  119.  * @li You can shut down individual communication channels with
  120.  * closeStdin(), closeStdout(), and closeStderr(), resp.
  121.  *
  122.  * @author Christian Czezatke e9025461@student.tuwien.ac.at
  123.  *
  124.  **/
  125. class KDECORE_EXPORT KProcess : public QObject
  126. {
  127.   Q_OBJECT
  128.  
  129. public:
  130.  
  131.   /**
  132.    * Modes in which the communication channel can be opened.
  133.    *
  134.    * If communication for more than one channel is required,
  135.    * the values have to be or'ed together, for example to get
  136.    * communication with stdout as well as with stdin, you would
  137.    * specify @p Stdin | @p Stdout
  138.    *
  139.    * If @p NoRead is specified in conjunction with @p Stdout,
  140.    * no data is actually read from @p Stdout but only
  141.    * the signal receivedStdout(int fd, int &len) is emitted.
  142.    *
  143.    * @p CTtyOnly tells setUsePty() to create a PTY for the process
  144.    * and make it the process' controlling TTY, but does not redirect
  145.    * any I/O channel to the PTY.
  146.    *
  147.    * If @p MergedStderr is specified in conjunction with @p Stdout,
  148.    * Stderr will be redirected onto the same file handle as Stdout,
  149.    * i.e., all error output will be signalled with receivedStdout().
  150.    * Don't specify @p Stderr if you specify @p MergedStderr.
  151.    */
  152.   enum Communication {
  153.        NoCommunication = 0,
  154.        Stdin = 1, Stdout = 2, Stderr = 4,
  155.        AllOutput = 6, All = 7,
  156.        NoRead = 8,
  157.        CTtyOnly = NoRead,
  158.        MergedStderr = 16
  159.   };
  160.  
  161.   /**
  162.    * Run-modes for a child process.
  163.    */
  164.   enum RunMode {
  165.       /**
  166.        * The application does not receive notifications from the subprocess when
  167.        * it is finished or aborted.
  168.        */
  169.        DontCare,
  170.        /**
  171.         * The application is notified when the subprocess dies.
  172.         */
  173.        NotifyOnExit,
  174.        /**
  175.         * The application is suspended until the started process is finished.
  176.         */
  177.        Block,
  178.        /**
  179.         * Same as NotifyOnExit, but the process is run in an own session,
  180.         * just like with DontCare.
  181.         */
  182.        OwnGroup
  183.   };
  184.  
  185.   /**
  186.    * Constructor
  187.    * @since 3.2
  188.    */
  189.   KProcess( QObject* parent, const char *name = 0 );
  190.  
  191.   /**
  192.    * Constructor
  193.    */ // KDE4 merge with the above
  194.   KProcess();
  195.  
  196.   /**
  197.    *Destructor:
  198.    *
  199.    *  If the process is running when the destructor for this class
  200.    *  is called, the child process is killed with a SIGKILL, but
  201.    *  only if the run mode is not of type @p DontCare.
  202.    *  Processes started as @p DontCare keep running anyway.
  203.   */
  204.   virtual ~KProcess();
  205.  
  206.   /**
  207.      @deprecated
  208.      Use operator<<() instead.
  209.  
  210.      Sets the executable to be started with this KProcess object.
  211.      Returns false if the process is currently running (in that
  212.      case the executable remains unchanged).
  213.  
  214.      @see operator<<()
  215.  
  216.   */
  217.   bool setExecutable(const QString& proc) KDE_DEPRECATED;
  218.  
  219.  
  220.   /**
  221.    * Sets the executable and the command line argument list for this process.
  222.    *
  223.    * For example, doing an "ls -l /usr/local/bin" can be achieved by:
  224.    *  \code
  225.    *  KProcess p;
  226.    *  ...
  227.    *  p << "ls" << "-l" << "/usr/local/bin"
  228.    *  \endcode
  229.    *
  230.    * @param arg the argument to add
  231.    * @return a reference to this KProcess
  232.    **/
  233.   KProcess &operator<<(const QString& arg);
  234.   /**
  235.    * Similar to previous method, takes a char *, supposed to be in locale 8 bit already.
  236.    */
  237.   KProcess &operator<<(const char * arg);
  238.   /**
  239.    * Similar to previous method, takes a QCString, supposed to be in locale 8 bit already.
  240.    * @param arg the argument to add
  241.    * @return a reference to this KProcess
  242.    */
  243.   KProcess &operator<<(const QCString & arg);
  244.  
  245.   /**
  246.    * Sets the executable and the command line argument list for this process,
  247.    * in a single method call, or add a list of arguments.
  248.    * @param args the arguments to add
  249.    * @return a reference to this KProcess
  250.    **/
  251.   KProcess &operator<<(const QStringList& args);
  252.  
  253.   /**
  254.    * Clear a command line argument list that has been set by using
  255.    * operator<<.
  256.   */
  257.   void clearArguments();
  258.  
  259.   /**
  260.    *  Starts the process.
  261.    *  For a detailed description of the
  262.    *  various run modes and communication semantics, have a look at the
  263.    *  general description of the KProcess class. Note that if you use
  264.    * setUsePty( Stdout | Stderr, \<bool\> ), you cannot use Stdout | Stderr
  265.    *  here - instead, use Stdout only to receive the mixed output.
  266.    *
  267.    *  The following problems could cause this function to
  268.    *    return false:
  269.    *
  270.    *  @li The process is already running.
  271.    *  @li The command line argument list is empty.
  272.    *  @li The the @p comm parameter is incompatible with the selected pty usage.
  273.    *  @li The starting of the process failed (could not fork).
  274.    *  @li The executable was not found.
  275.    *
  276.    *  @param runmode The Run-mode for the process.
  277.    *  @param comm  Specifies which communication links should be
  278.    *  established to the child process (stdin/stdout/stderr). By default,
  279.    *  no communication takes place and the respective communication
  280.    *  signals will never get emitted.
  281.    *
  282.    *  @return true on success, false on error
  283.    *  (see above for error conditions)
  284.    **/
  285.   virtual bool start(RunMode  runmode = NotifyOnExit,
  286.       Communication comm = NoCommunication);
  287.  
  288.   /**
  289.    * Stop the process (by sending it a signal).
  290.    *
  291.    * @param signo The signal to send. The default is SIGTERM.
  292.    * @return true if the signal was delivered successfully.
  293.   */
  294.   virtual bool kill(int signo = SIGTERM);
  295.  
  296.   /**
  297.    * Checks whether the process is running.
  298.    * @return true if the process is (still) considered to be running
  299.   */
  300.   bool isRunning() const;
  301.  
  302.   /** Returns the process id of the process.
  303.    *
  304.    * If it is called after
  305.    * the process has exited, it returns the process id of the last
  306.    *  child process that was created by this instance of KProcess.
  307.    *
  308.    *  Calling it before any child process has been started by this
  309.    *  KProcess instance causes pid() to return 0.
  310.    * @return the pid of the process or 0 if no process has been started yet.
  311.    **/
  312.   pid_t pid() const;
  313.  
  314.   /**
  315.    * @deprecated
  316.    * Use pid() instead.
  317.    */
  318.   KDE_DEPRECATED pid_t getPid() const { return pid(); }
  319.  
  320.   /**
  321.    * Suspend processing of data from stdout of the child process.
  322.    */
  323.   void suspend();
  324.  
  325.   /**
  326.    * Resume processing of data from stdout of the child process.
  327.    */
  328.   void resume();
  329.  
  330.   /**
  331.    * Suspend execution of the current thread until the child process dies
  332.    * or the timeout hits. This function is not recommended for programs
  333.    * with a GUI.
  334.    * @param timeout timeout in seconds. -1 means wait indefinitely.
  335.    * @return true if the process exited, false if the timeout hit.
  336.    * @since 3.2
  337.    */
  338.   bool wait(int timeout = -1);
  339.  
  340.   /**
  341.    * Checks whether the process exited cleanly.
  342.    *
  343.    * @return true if the process has already finished and has exited
  344.    *  "voluntarily", ie: it has not been killed by a signal.
  345.    */
  346.   bool normalExit() const;
  347.  
  348.   /**
  349.    * Checks whether the process was killed by a signal.
  350.    *
  351.    * @return true if the process has already finished and has not exited
  352.    * "voluntarily", ie: it has been killed by a signal.
  353.    *
  354.    * @since 3.2
  355.    */
  356.   bool signalled() const;
  357.  
  358.   /**
  359.    * Checks whether a killed process dumped core.
  360.    *
  361.    * @return true if signalled() returns true and the process
  362.    * dumped core. Note that on systems that don't define the
  363.    * WCOREDUMP macro, the return value is always false.
  364.    *
  365.    * @since 3.2
  366.    */
  367.   bool coreDumped() const;
  368.  
  369.   /**
  370.    * Returns the exit status of the process.
  371.    *
  372.    * @return the exit status of the process. Note that this value
  373.    * is not valid if normalExit() returns false.
  374.    */
  375.   int exitStatus() const;
  376.  
  377.   /**
  378.    * Returns the signal the process was killed by.
  379.    *
  380.    * @return the signal number that caused the process to exit.
  381.    * Note that this value is not valid if signalled() returns false.
  382.    *
  383.    * @since 3.2
  384.    */
  385.   int exitSignal() const;
  386.  
  387.   /**
  388.    *     Transmit data to the child process' stdin.
  389.    *
  390.    * This function may return false in the following cases:
  391.    *
  392.    *     @li The process is not currently running.
  393.    * This implies that you cannot use this function in Block mode.
  394.    *
  395.    *     @li Communication to stdin has not been requested in the start() call.
  396.    *
  397.    *     @li Transmission of data to the child process by a previous call to
  398.    * writeStdin() is still in progress.
  399.    *
  400.    * Please note that the data is sent to the client asynchronously,
  401.    * so when this function returns, the data might not have been
  402.    * processed by the child process.
  403.    * That means that you must not free @p buffer or call writeStdin()
  404.    * again until either a wroteStdin() signal indicates that the
  405.    * data has been sent or a processExited() signal shows that
  406.    * the child process is no longer alive.
  407.    *
  408.    * If all the data has been sent to the client, the signal
  409.    * wroteStdin() will be emitted.
  410.    *
  411.    * This function does not work when the process is start()ed in Block mode.
  412.    *
  413.    * @param buffer the buffer to write
  414.    * @param buflen the length of the buffer
  415.    * @return false if an error has occurred
  416.    **/
  417.   bool writeStdin(const char *buffer, int buflen);
  418.  
  419.   /**
  420.    * Shuts down the Stdin communication link. If no pty is used, this
  421.    * causes "EOF" to be indicated on the child's stdin file descriptor.
  422.    *
  423.    * @return false if no Stdin communication link exists (any more).
  424.    */
  425.   bool closeStdin();
  426.  
  427.   /**
  428.    * Shuts down the Stdout communication link. If no pty is used, any further
  429.    * attempts by the child to write to its stdout file descriptor will cause
  430.    * it to receive a SIGPIPE.
  431.    *
  432.    * @return false if no Stdout communication link exists (any more).
  433.    */
  434.   bool closeStdout();
  435.  
  436.   /**
  437.    * Shuts down the Stderr communication link. If no pty is used, any further
  438.    * attempts by the child to write to its stderr file descriptor will cause
  439.    * it to receive a SIGPIPE.
  440.    *
  441.    * @return false if no Stderr communication link exists (any more).
  442.    */
  443.   bool closeStderr();
  444.  
  445.   /**
  446.    * Deletes the optional utmp entry and closes the pty.
  447.    *
  448.    * Make sure to shut down any communication links that are using the pty
  449.    * before calling this function.
  450.    *
  451.    * @return false if the pty is not open (any more).
  452.    */
  453.   bool closePty();
  454.  
  455.   /**
  456.    * @brief Close stdin, stdout, stderr and the pty
  457.    * 
  458.    * This is the same that calling all close* functions in a row:
  459.    * @see closeStdin, @see closeStdout, @see closeStderr and @see closePty
  460.    */
  461.   void closeAll();
  462.  
  463.   /**
  464.    * Lets you see what your arguments are for debugging.
  465.    * @return the list of arguments
  466.    */
  467.   const QValueList<QCString> &args() /* const */ { return arguments; }
  468.  
  469.   /**
  470.    * Controls whether the started process should drop any
  471.    * setuid/setgid privileges or whether it should keep them.
  472.    * Note that this function is mostly a dummy, as the KDE libraries
  473.    * currently refuse to run with setuid/setgid privileges.
  474.    *
  475.    * The default is false: drop privileges
  476.    * @param keepPrivileges true to keep the privileges
  477.    */
  478.   void setRunPrivileged(bool keepPrivileges);
  479.  
  480.   /**
  481.    * Returns whether the started process will drop any
  482.    * setuid/setgid privileges or whether it will keep them.
  483.    * @return true if the process runs privileged
  484.    */
  485.   bool runPrivileged() const;
  486.  
  487.   /**
  488.    * Adds the variable @p name to the process' environment.
  489.    * This function must be called before starting the process.
  490.    * @param name the name of the environment variable
  491.    * @param value the new value for the environment variable
  492.    */
  493.   void setEnvironment(const QString &name, const QString &value);
  494.  
  495.   /**
  496.    * Changes the current working directory (CWD) of the process
  497.    * to be started.
  498.    * This function must be called before starting the process.
  499.    * @param dir the new directory
  500.    */
  501.   void setWorkingDirectory(const QString &dir);
  502.  
  503.   /**
  504.    * Specify whether to start the command via a shell or directly.
  505.    * The default is to start the command directly.
  506.    * If @p useShell is true @p shell will be used as shell, or
  507.    * if shell is empty, /bin/sh will be used.
  508.    *
  509.    * When using a shell, the caller should make sure that all filenames etc.
  510.    * are properly quoted when passed as argument.
  511.    * @see quote()
  512.    * @param useShell true if the command should be started via a shell
  513.    * @param shell the path to the shell that will execute the process, or
  514.    *              0 to use /bin/sh. Use getenv("SHELL") to use the user's
  515.    *              default shell, but note that doing so is usually a bad idea
  516.    *              for shell compatibility reasons.
  517.    * @since 3.1
  518.    */
  519.   void setUseShell(bool useShell, const char *shell = 0);
  520.  
  521.   /**
  522.    * This function can be used to quote an argument string such that
  523.    * the shell processes it properly. This is e. g. necessary for
  524.    * user-provided file names which may contain spaces or quotes.
  525.    * It also prevents expansion of wild cards and environment variables.
  526.    * @param arg the argument to quote
  527.    * @return the quoted argument
  528.    * @since 3.1
  529.    */
  530.   static QString quote(const QString &arg);
  531.  
  532.   /**
  533.    * Detaches KProcess from child process. All communication is closed.
  534.    * No exit notification is emitted any more for the child process.
  535.    * Deleting the KProcess will no longer kill the child process.
  536.    * Note that the current process remains the parent process of the
  537.    * child process.
  538.    */
  539.   void detach();
  540.  
  541. #ifdef Q_OS_UNIX
  542.   /**
  543.    * Specify whether to create a pty (pseudo-terminal) for running the
  544.    * command.
  545.    * This function should be called before starting the process.
  546.    *
  547.    * @param comm for which stdio handles to use a pty. Note that it is not
  548.    *  allowed to specify Stdout and Stderr at the same time both here and to
  549.    * start (there is only one pty, so they cannot be distinguished).
  550.    * @param addUtmp true if a utmp entry should be created for the pty
  551.    * @since 3.2
  552.    */
  553.   void setUsePty(Communication comm, bool addUtmp);
  554.  
  555.   /**
  556.    * Obtains the pty object used by this process. The return value is
  557.    * valid only after setUsePty() was used with a non-zero argument.
  558.    * The pty is open only while the process is running.
  559.    * @return a pointer to the pty object
  560.    * @since 3.2
  561.    */
  562.   KPty *pty() const;
  563. #endif
  564.  
  565.   /**
  566.    * More or less intuitive constants for use with setPriority().
  567.    */
  568.   enum { PrioLowest = 20, PrioLow = 10, PrioLower = 5, PrioNormal = 0,
  569.     PrioHigher = -5, PrioHigh = -10, PrioHighest = -19 };
  570.  
  571.   /**
  572.    * Sets the scheduling priority of the process.
  573.    * @param prio the new priority in the range -20 (high) to 19 (low).
  574.    * @return false on error; see setpriority(2) for possible reasons.
  575.    * @since 3.2
  576.    */
  577.   bool setPriority(int prio);
  578.  
  579. signals:
  580.   /**
  581.    * Emitted after the process has terminated when
  582.    * the process was run in the @p NotifyOnExit  (==default option to
  583.    * start() ) or the Block mode.
  584.    * @param proc a pointer to the process that has exited
  585.    **/
  586.   void processExited(KProcess *proc);
  587.  
  588.  
  589.   /**
  590.    * Emitted, when output from the child process has
  591.    * been received on stdout.
  592.    *
  593.    * To actually get this signal, the Stdout communication link
  594.    * has to be turned on in start().
  595.    *
  596.    * @param proc a pointer to the process that has received the output
  597.    * @param buffer The data received.
  598.    * @param buflen The number of bytes that are available.
  599.    *
  600.    * You should copy the information contained in @p buffer to your private
  601.    * data structures before returning from the slot.
  602.    * Example:
  603.    * \code
  604.    *     QString myBuf = QString::fromLatin1(buffer, buflen);
  605.    * \endcode
  606.    **/
  607.   void receivedStdout(KProcess *proc, char *buffer, int buflen);
  608.  
  609.   /**
  610.    * Emitted when output from the child process has
  611.    * been received on stdout.
  612.    *
  613.    * To actually get this signal, the Stdout communication link
  614.    * has to be turned on in start() and the
  615.    * NoRead flag must have been passed.
  616.    *
  617.    * You will need to explicitly call resume() after your call to start()
  618.    * to begin processing data from the child process' stdout.  This is
  619.    * to ensure that this signal is not emitted when no one is connected
  620.    * to it, otherwise this signal will not be emitted.
  621.    *
  622.    * The data still has to be read from file descriptor @p fd.
  623.    * @param fd the file descriptor that provides the data
  624.    * @param len the number of bytes that have been read from @p fd must
  625.    *  be written here
  626.    **/
  627.   void receivedStdout(int fd, int &len); // KDE4: change, broken API
  628.  
  629.  
  630.   /**
  631.    * Emitted, when output from the child process has
  632.    * been received on stderr.
  633.    *
  634.    * To actually get this signal, the Stderr communication link
  635.    * has to be turned on in start().
  636.    *
  637.    * You should copy the information contained in @p buffer to your private
  638.    * data structures before returning from the slot.
  639.    *
  640.    * @param proc a pointer to the process that has received the data
  641.    * @param buffer The data received.
  642.    * @param buflen The number of bytes that are available.
  643.    **/
  644.   void receivedStderr(KProcess *proc, char *buffer, int buflen);
  645.  
  646.   /**
  647.    * Emitted after all the data that has been
  648.    * specified by a prior call to writeStdin() has actually been
  649.    * written to the child process.
  650.    * @param proc a pointer to the process
  651.    **/
  652.   void wroteStdin(KProcess *proc);
  653.  
  654.  
  655. protected slots:
  656.  
  657.  /**
  658.   * This slot gets activated when data from the child's stdout arrives.
  659.   * It usually calls childOutput().
  660.   * @param fdno the file descriptor for the output
  661.   */
  662.   void slotChildOutput(int fdno);
  663.  
  664.  /**
  665.   * This slot gets activated when data from the child's stderr arrives.
  666.   * It usually calls childError().
  667.   * @param fdno the file descriptor for the output
  668.   */
  669.   void slotChildError(int fdno);
  670.  
  671.   /**
  672.    * Called when another bulk of data can be sent to the child's
  673.    * stdin. If there is no more data to be sent to stdin currently
  674.    * available, this function must disable the QSocketNotifier innot.
  675.    * @param dummy ignore this argument
  676.    */
  677.   void slotSendData(int dummy);    // KDE 4: remove dummy
  678.  
  679. protected:
  680.  
  681.   /**
  682.    * Sets up the environment according to the data passed via
  683.    * setEnvironment()
  684.    */
  685.   void setupEnvironment();
  686.  
  687.   /**
  688.    * The list of the process' command line arguments. The first entry
  689.    * in this list is the executable itself.
  690.    */
  691.   QValueList<QCString> arguments;
  692.   /**
  693.    * How to run the process (Block, NotifyOnExit, DontCare). You should
  694.    *  not modify this data member directly from derived classes.
  695.    */
  696.   RunMode run_mode;
  697.   /**
  698.    * true if the process is currently running. You should not
  699.    * modify this data member directly from derived classes. Please use
  700.    * isRunning() for reading the value of this data member since it
  701.    * will probably be made private in later versions of KProcess.
  702.    */
  703.   bool runs;
  704.  
  705.   /**
  706.    * The PID of the currently running process.
  707.    * You should not modify this data member in derived classes.
  708.    * Please use pid() instead of directly accessing this
  709.    * member since it will probably be made private in
  710.    * later versions of KProcess.
  711.    */
  712.   pid_t pid_;
  713.  
  714.   /**
  715.    * The process' exit status as returned by waitpid(). You should not
  716.    * modify the value of this data member from derived classes. You should
  717.    * rather use exitStatus() than accessing this data member directly
  718.    * since it will probably be made private in further versions of
  719.    * KProcess.
  720.    */
  721.   int status;
  722.  
  723.  
  724.   /**
  725.    * If false, the child process' effective uid & gid will be reset to the
  726.    * real values.
  727.    * @see setRunPrivileged()
  728.    */
  729.   bool keepPrivs;
  730.  
  731.   /**
  732.    * This function is called from start() right before a fork() takes
  733.    * place. According to the @p comm parameter this function has to initialize
  734.    * the in, out and err data members of KProcess.
  735.    *
  736.    * This function should return 1 if setting the needed communication channels
  737.    * was successful.
  738.    *
  739.    * The default implementation is to create UNIX STREAM sockets for the
  740.    * communication, but you could reimplement this function to establish a
  741.    * TCP/IP communication for network communication, for example.
  742.    */
  743.   virtual int setupCommunication(Communication comm);
  744.  
  745.   /**
  746.    * Called right after a (successful) fork() on the parent side. This function
  747.    * will usually do some communications cleanup, like closing in[0],
  748.    * out[1] and out[1].
  749.    *
  750.    * Furthermore, it must also create the QSocketNotifiers innot,
  751.    * outnot and errnot and connect their Qt signals to the respective
  752.    * KProcess slots.
  753.    *
  754.    * For a more detailed explanation, it is best to have a look at the default
  755.    * implementation in kprocess.cpp.
  756.    */
  757.   virtual int commSetupDoneP();
  758.  
  759.   /**
  760.    * Called right after a (successful) fork(), but before an exec() on the child
  761.    * process' side. It usually duplicates the in[0], out[1] and
  762.    * err[1] file handles to the respective standard I/O handles.
  763.    */
  764.   virtual int commSetupDoneC();
  765.  
  766.  
  767.   /**
  768.    * Immediately called after a successfully started process in NotifyOnExit
  769.    * mode has exited. This function normally calls commClose()
  770.    * and emits the processExited() signal.
  771.    * @param state the exit code of the process as returned by waitpid()
  772.    */
  773.   virtual void processHasExited(int state);
  774.  
  775.   /**
  776.    * Cleans up the communication links to the child after it has exited.
  777.    * This function should act upon the values of pid() and runs.
  778.    * See the kprocess.cpp source for details.
  779.    * @li If pid() returns zero, the communication links should be closed
  780.    *  only.
  781.    * @li if pid() returns non-zero and runs is false, all data
  782.    *  immediately available from the communication links should be processed
  783.    *  before closing them.
  784.    * @li if pid() returns non-zero and runs is true, the communication
  785.    *  links should be monitored for data until the file handle returned by
  786.    *  KProcessController::theKProcessController->notifierFd() becomes ready
  787.    *  for reading - when it triggers, runs should be reset to false, and
  788.    *  the function should be immediately left without closing anything.
  789.    *
  790.    * The previous semantics of this function are forward-compatible, but should
  791.    * be avoided, as they are prone to race conditions and can cause KProcess
  792.    * (and thus the whole program) to lock up under certain circumstances. At the
  793.    * end the function closes the communication links in any case. Additionally
  794.    * @li if runs is true, the communication links are monitored for data
  795.    *  until all of them have returned EOF. Note that if any system function is
  796.    *  interrupted (errno == EINTR) the polling loop should be aborted.
  797.    * @li if runs is false, all data immediately available from the
  798.    *  communication links is processed.
  799.    */
  800.   virtual void commClose();
  801.  
  802.   /* KDE 4 - commClose will be changed to perform cleanup only in all cases *
  803.    * If @p notfd is -1, all data immediately available from the
  804.    *  communication links should be processed.
  805.    * If @p notfd is not -1, the communication links should be monitored
  806.    *  for data until the file handle @p notfd becomes ready for reading.
  807.    */
  808. //  virtual void commDrain(int notfd);
  809.  
  810.   /**
  811.    * Specify the actual executable that should be started (first argument to execve)
  812.    * Normally the the first argument is the executable but you can
  813.    * override that with this function.
  814.    */
  815.   void setBinaryExecutable(const char *filename);
  816.  
  817.   /**
  818.    * The socket descriptors for stdout.
  819.    */
  820.   int out[2];
  821.   /**
  822.    * The socket descriptors for stdin.
  823.    */
  824.   int in[2];
  825.   /**
  826.    * The socket descriptors for stderr.
  827.    */
  828.   int err[2];
  829.  
  830.   /**
  831.    * The socket notifier for in[1].
  832.    */
  833.   QSocketNotifier *innot;
  834.   /**
  835.    * The socket notifier for out[0].
  836.    */
  837.   QSocketNotifier *outnot;
  838.   /**
  839.    * The socket notifier for err[0].
  840.    */
  841.   QSocketNotifier *errnot;
  842.  
  843.   /**
  844.    * Lists the communication links that are activated for the child
  845.    * process.  Should not be modified from derived classes.
  846.    */
  847.   Communication communication;
  848.  
  849.   /**
  850.    * Called by slotChildOutput() this function copies data arriving from
  851.    * the child process' stdout to the respective buffer and emits the signal
  852.    * receivedStdout().
  853.    */
  854.   int childOutput(int fdno);
  855.  
  856.   /**
  857.    * Called by slotChildError() this function copies data arriving from
  858.    * the child process' stderr to the respective buffer and emits the signal
  859.    * receivedStderr().
  860.    */
  861.   int childError(int fdno);
  862.  
  863.   /**
  864.    * The buffer holding the data that has to be sent to the child
  865.    */
  866.   const char *input_data;
  867.   /**
  868.    * The number of bytes already transmitted
  869.    */
  870.   int input_sent;
  871.   /**
  872.    * The total length of input_data
  873.    */
  874.   int input_total;
  875.  
  876.   /**
  877.    * KProcessController is a friend of KProcess because it has to have
  878.    * access to various data members.
  879.    */
  880.   friend class KProcessController;
  881.  
  882. protected:
  883.   virtual void virtual_hook( int id, void* data );
  884. private:
  885.   KProcessPrivate *d;
  886. };
  887.  
  888. class KShellProcessPrivate;
  889.  
  890. /**
  891. * @obsolete
  892. *
  893. * Use KProcess and KProcess::setUseShell(true) instead.
  894. *
  895. *   @short A class derived from KProcess to start child
  896. *       processes through a shell.
  897. *   @author Christian Czezatke <e9025461@student.tuwien.ac.at>
  898. */
  899. class KDECORE_EXPORT KShellProcess: public KProcess
  900. {
  901.   Q_OBJECT
  902.  
  903. public:
  904.  
  905.   /**
  906.    * Constructor
  907.    *
  908.    * If no shellname is specified, the user's default shell is used.
  909.    */
  910.   KShellProcess(const char *shellname=0);
  911.  
  912.   /**
  913.    * Destructor.
  914.    */
  915.   ~KShellProcess();
  916.  
  917.   virtual bool start(RunMode  runmode = NotifyOnExit,
  918.           Communication comm = NoCommunication);
  919.  
  920.   static QString quote(const QString &arg);
  921.  
  922. private:
  923.   QCString shell;
  924.  
  925. protected:
  926.   virtual void virtual_hook( int id, void* data );
  927. private:
  928.   KShellProcessPrivate *d;
  929. };
  930.  
  931.  
  932.  
  933. #endif
  934.  
  935.