}
if (how == DontWait) {
- // TODO delete process later
+ QProcess* released = d.releaseProcess();
+ (void) released; // TODO who deletes it?
return 0;
}
LYXERR0("error " << exit_code << ": " << d.errorMessage());
}
- d.flush();
- d.killProcess();
-
return exit_code;
}
void SystemcallPrivate::startProcess(const QString& cmd)
{
- state = SystemcallPrivate::Starting;
- proc_->start(cmd);
+ if (proc_) {
+ state = SystemcallPrivate::Starting;
+ proc_->start(cmd);
+ }
}
bool SystemcallPrivate::waitWhile(State waitwhile, bool processEvents, int timeout)
{
+ if (!proc_)
+ return false;
+
// Block GUI while waiting,
// relay on QProcess' wait functions
if (!processEvents) {
SystemcallPrivate::~SystemcallPrivate()
{
+ flush();
+
if (outindex_) {
outdata_[outindex_] = '\0';
outindex_ = 0;
cerr << errdata_;
}
cerr.flush();
+
+ killProcess();
}
void SystemcallPrivate::flush()
{
- // If the output has been redirected, we write it all at once.
- // Even if we are not running in a terminal, the output could go
- // to some log file, for example ~/.xsession-errors on *nix.
- if (!os::is_terminal(os::STDOUT) && outfile.empty())
- cout << fromqstr(QString::fromLocal8Bit(
- proc_->readAllStandardOutput().data()));
- if (!os::is_terminal(os::STDERR))
- cerr << fromqstr(QString::fromLocal8Bit(
- proc_->readAllStandardError().data()));
+ if (proc_) {
+ // If the output has been redirected, we write it all at once.
+ // Even if we are not running in a terminal, the output could go
+ // to some log file, for example ~/.xsession-errors on *nix.
+ if (!os::is_terminal(os::STDOUT) && outfile.empty())
+ cout << fromqstr(QString::fromLocal8Bit(
+ proc_->readAllStandardOutput().data()));
+ if (!os::is_terminal(os::STDERR))
+ cerr << fromqstr(QString::fromLocal8Bit(
+ proc_->readAllStandardError().data()));
+ }
}
void SystemcallPrivate::stdOut()
{
- if (showout_) {
+ if (proc_ && showout_) {
char c;
proc_->setReadChannel(QProcess::StandardOutput);
while (proc_->getChar(&c)) {
void SystemcallPrivate::stdErr()
{
- if (showerr_) {
+ if (proc_ && showerr_) {
char c;
proc_->setReadChannel(QProcess::StandardError);
while (proc_->getChar(&c)) {
QString SystemcallPrivate::errorMessage() const
{
+ if (!proc_)
+ return "No QProcess available";
+
QString message;
switch (proc_->error()) {
case QProcess::FailedToStart:
QString SystemcallPrivate::exitStatusMessage() const
{
+ if (!proc_)
+ return "No QProcess available";
+
QString message;
switch (proc_->exitStatus()) {
case QProcess::NormalExit:
int SystemcallPrivate::exitCode()
{
+ if (!proc_)
+ return -1;
+
return proc_->exitCode();
}
+QProcess* SystemcallPrivate::releaseProcess()
+{
+ QProcess* released = proc_;
+ proc_ = 0;
+ return released;
+}
+
+
void SystemcallPrivate::killProcess()
{
killProcess(proc_);
void SystemcallPrivate::killProcess(QProcess * p)
{
- p->disconnect();
- p->closeReadChannel(QProcess::StandardOutput);
- p->closeReadChannel(QProcess::StandardError);
- p->close();
- delete p;
+ if (p) {
+ p->disconnect();
+ p->closeReadChannel(QProcess::StandardOutput);
+ p->closeReadChannel(QProcess::StandardError);
+ p->close();
+ delete p;
+ }
}