00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
#ifndef __kprocess_h__
00021
#define __kprocess_h__
00022
00023
#include <sys/types.h>
00024
#include <sys/wait.h>
00025
#include <signal.h>
00026
#include <unistd.h>
00027
#include <qvaluelist.h>
00028
#include <qcstring.h>
00029
#include <qobject.h>
00030
#include "kdemacros.h"
00031
00032
class QSocketNotifier;
00033
class KProcessPrivate;
00034
class KPty;
00035
00124 class KProcess :
public QObject
00125 {
00126 Q_OBJECT
00127
00128
public:
00129
00142 enum Communication {
00143 NoCommunication = 0,
00144 Stdin = 1, Stdout = 2, Stderr = 4,
00145 AllOutput = 6, All = 7,
00146 NoRead
00147 };
00148
00152 enum RunMode {
00157
DontCare,
00161
NotifyOnExit,
00165
Block,
00170
OwnGroup
00171 };
00172
00177
KProcess(
QObject* parent,
const char *name = 0 );
00178
00182
KProcess();
00183
00192
virtual ~KProcess();
00193
00205
bool setExecutable(
const QString& proc) KDE_DEPRECATED;
00206
00207
00221
KProcess &
operator<<(
const QString& arg);
00225
KProcess &
operator<<(
const char * arg);
00231
KProcess &
operator<<(
const QCString & arg);
00232
00239
KProcess &
operator<<(
const QStringList& args);
00240
00245
void clearArguments();
00246
00273
virtual bool start(RunMode runmode = NotifyOnExit,
00274 Communication comm = NoCommunication);
00275
00282
virtual bool kill(
int signo = SIGTERM);
00283
00288
bool isRunning() const;
00289
00300 pid_t pid() const;
00301
00306 KDE_DEPRECATED pid_t getPid()
const {
return pid(); }
00307
00311
void suspend();
00312
00316
void resume();
00317
00326
bool wait(
int timeout = -1);
00327
00334
bool normalExit() const;
00335
00344
bool signalled() const;
00345
00355
bool coreDumped() const;
00356
00363
int exitStatus() const;
00364
00373
int exitSignal() const;
00374
00403
bool writeStdin(const
char *buffer,
int buflen);
00404
00411
bool closeStdin();
00412
00420
bool closeStdout();
00421
00429
bool closeStderr();
00430
00439
bool closePty();
00440
00444
void closeAll();
00445
00450 const
QValueList<
QCString> &args() {
return arguments; }
00451
00461
void setRunPrivileged(
bool keepPrivileges);
00462
00468
bool runPrivileged() const;
00469
00476
void setEnvironment(const
QString &name, const
QString &value);
00477
00484
void setWorkingDirectory(const
QString &dir);
00485
00502
void setUseShell(
bool useShell, const
char *shell = 0);
00503
00513 static
QString quote(const
QString &arg);
00514
00522
void detach();
00523
00535
void setUsePty(Communication comm,
bool addUtmp);
00536
00545
KPty *pty() const;
00546
00550 enum { PrioLowest = 20, PrioLow = 10, PrioLower = 5, PrioNormal = 0,
00551 PrioHigher = -5, PrioHigh = -10, PrioHighest = -19 };
00552
00559
bool setPriority(
int prio);
00560
00561 signals:
00568
void processExited(
KProcess *proc);
00569
00570
00589
void receivedStdout(
KProcess *proc,
char *buffer,
int buflen);
00590
00609
void receivedStdout(
int fd,
int &len);
00610
00611
00626
void receivedStderr(
KProcess *proc,
char *buffer,
int buflen);
00627
00634
void wroteStdin(
KProcess *proc);
00635
00636
00637
protected slots:
00638
00644
void slotChildOutput(
int fdno);
00645
00651
void slotChildError(
int fdno);
00652
00659
void slotSendData(
int dummy);
00660
00661
protected:
00662
00667
void setupEnvironment();
00668
00673 QValueList<QCString> arguments;
00678 RunMode run_mode;
00685 bool runs;
00686
00694 pid_t
pid_;
00695
00703 int status;
00704
00705
00711 bool keepPrivs;
00712
00725
virtual int setupCommunication(Communication comm);
00726
00739
virtual int commSetupDoneP();
00740
00746
virtual int commSetupDoneC();
00747
00748
00755
virtual void processHasExited(
int state);
00756
00782
virtual void commClose();
00783
00784
00785
00786
00787
00788
00789
00790
00791
00797
void setBinaryExecutable(
const char *filename);
00798
00802 int out[2];
00806 int in[2];
00810 int err[2];
00811
00815 QSocketNotifier *
innot;
00819 QSocketNotifier *
outnot;
00823 QSocketNotifier *
errnot;
00824
00829 Communication communication;
00830
00836
int childOutput(
int fdno);
00837
00843
int childError(
int fdno);
00844
00848 const char *
input_data;
00852 int input_sent;
00856 int input_total;
00857
00862
friend class KProcessController;
00863
00864
protected:
00865
virtual void virtual_hook(
int id,
void* data );
00866
private:
00867 KProcessPrivate *d;
00868 };
00869
00870
class KShellProcessPrivate;
00871
00882 class KShellProcess:
public KProcess
00883 {
00884 Q_OBJECT
00885
00886
public:
00887
00893
KShellProcess(
const char *shellname=0);
00894
00898
~KShellProcess();
00899
00900
virtual bool start(RunMode runmode = NotifyOnExit,
00901 Communication comm = NoCommunication);
00902
00903
static QString quote(
const QString &arg);
00904
00905
private:
00906
QCString shell;
00907
00908
protected:
00909
virtual void virtual_hook(
int id,
void* data );
00910
private:
00911 KShellProcessPrivate *d;
00912 };
00913
00914
00915
00916
#endif
00917