Do not overwrite detailed error message if process fails to launch

On Unix we get a detailed error message when a process fails to start,
but later on we overwrite it with a generic "Process fails to start".
Fix this by keeping the original error message (if one is available).

This fixes a regression introduced in commit 5147f73ac3.

Task-number: QTBUG-49286
Change-Id: Idd0f0fed9773d39f2947fc3e532b51e670952caf
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Kai Koehne 2015-11-09 12:53:54 +01:00
parent 4890c75d0d
commit 351853e04d
5 changed files with 9 additions and 8 deletions

View File

@ -1179,14 +1179,15 @@ bool QProcessPrivate::_q_startupNotification()
if (startupSocketNotifier) if (startupSocketNotifier)
startupSocketNotifier->setEnabled(false); startupSocketNotifier->setEnabled(false);
if (processStarted()) { QString errorMessage;
if (processStarted(&errorMessage)) {
q->setProcessState(QProcess::Running); q->setProcessState(QProcess::Running);
emit q->started(QProcess::QPrivateSignal()); emit q->started(QProcess::QPrivateSignal());
return true; return true;
} }
q->setProcessState(QProcess::NotRunning); q->setProcessState(QProcess::NotRunning);
setErrorAndEmit(QProcess::FailedToStart); setErrorAndEmit(QProcess::FailedToStart, errorMessage);
#ifdef Q_OS_UNIX #ifdef Q_OS_UNIX
// make sure the process manager removes this entry // make sure the process manager removes this entry
waitForDeadChild(); waitForDeadChild();

View File

@ -352,7 +352,7 @@ public:
#elif defined(QPROCESS_USE_SPAWN) #elif defined(QPROCESS_USE_SPAWN)
pid_t spawnChild(pid_t *ppid, const char *workingDirectory, char **argv, char **envp); pid_t spawnChild(pid_t *ppid, const char *workingDirectory, char **argv, char **envp);
#endif #endif
bool processStarted(); bool processStarted(QString *errorMessage = Q_NULLPTR);
void terminateProcess(); void terminateProcess();
void killProcess(); void killProcess();
void findExitCode(); void findExitCode();

View File

@ -714,7 +714,7 @@ report_errno:
} }
#endif #endif
bool QProcessPrivate::processStarted() bool QProcessPrivate::processStarted(QString *errorMessage)
{ {
ushort buf[errorBufferMax]; ushort buf[errorBufferMax];
int i = qt_safe_read(childStartedPipe[0], &buf, sizeof buf); int i = qt_safe_read(childStartedPipe[0], &buf, sizeof buf);
@ -731,8 +731,8 @@ bool QProcessPrivate::processStarted()
#endif #endif
// did we read an error message? // did we read an error message?
if (i > 0) if ((i > 0) && errorMessage)
q_func()->setErrorString(QString((const QChar *)buf, i / sizeof(QChar))); *errorMessage = QString((const QChar *)buf, i / sizeof(QChar));
return i <= 0; return i <= 0;
} }

View File

@ -543,7 +543,7 @@ void QProcessPrivate::startProcess()
_q_startupNotification(); _q_startupNotification();
} }
bool QProcessPrivate::processStarted() bool QProcessPrivate::processStarted(QString * /*errorMessage*/)
{ {
return processState == QProcess::Running; return processState == QProcess::Running;
} }

View File

@ -160,7 +160,7 @@ void QProcessPrivate::startProcess()
_q_startupNotification(); _q_startupNotification();
} }
bool QProcessPrivate::processStarted() bool QProcessPrivate::processStarted(QString * /*errorMessage*/)
{ {
return processState == QProcess::Running; return processState == QProcess::Running;
} }