1 /***************************************************************************
2 * copyright : (C) 2007 Shane King <kde@dontletsstart.com> *
3 **************************************************************************/
5 /***************************************************************************
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
12 ***************************************************************************/
21 #include <sys/resource.h>
24 Process::Process(QObject
*parent
)
25 : KProcess(parent
), lowPriority(false)
27 connect( this, SIGNAL( finished( int ) ), this, SLOT( finished() ) );
28 connect( this, SIGNAL( readyReadStandardOutput() ), this, SLOT( readyReadStandardOutput() ) );
29 connect( this, SIGNAL( readyReadStandardError() ), this, SLOT( readyReadStandardError() ) );
33 * Due to xine-lib, we have to make KProcess close all fds, otherwise we get "device is busy" messages
34 * exploiting setupChildProcess(), a virtual method that
35 * happens to be called in the forked process
36 * See bug #103750 for more information.
39 Process::setupChildProcess()
41 KProcess::setupChildProcess();
44 // can't get at the fds that QProcess needs to keep around to do its status
45 // tracking , but fortunately it sets them to close on exec anyway, so if
46 // we do likewise to everything then we should be ok.
47 for(int i
= sysconf(_SC_OPEN_MAX
) - 1; i
> 2; i
--)
48 fcntl(i
, F_SETFD
, FD_CLOEXEC
);
51 setpriority( PRIO_PROCESS
, 0, 19 );
62 SetPriorityClass( QProcess::pid()->hProcess
, IDLE_PRIORITY_CLASS
);
67 Process::finished() // SLOT
69 emit
processExited( this );
73 Process::readyReadStandardOutput() // SLOT
75 emit
receivedStdout( this );
79 Process::readyReadStandardError() // SLOT
81 emit
receivedStderr( this );
86 : codec(QTextCodec::codecForName( "UTF-8" ))
91 ProcIO::writeStdin (const QString
&line
)
93 return write( codec
->fromUnicode( line
+ "\n" ) ) > 0;
97 ProcIO::readln (QString
&line
)
99 QByteArray bytes
= readLine();
100 if (bytes
.length() == 0)
106 // convert and remove \n
107 line
= codec
->toUnicode( bytes
.data(), bytes
.length() - 1);
108 return line
.length();
115 connect (this, SIGNAL (readyReadStandardOutput()), this, SLOT (readyReadStandardOutput()));
121 ProcIO::readyReadStandardOutput()
124 emit
readReady( this );
128 ShellProcess::operator<<(const QString
& arg
)
130 if( program().isEmpty() )
131 setShellCommand( arg
);
133 Process::operator<<( arg
);
138 ShellProcess::operator<<(const QStringList
& args
)
140 foreach( QString arg
, args
)