QProcess/Win: Properly report the reason of a fail-to-start
We were losing the GetLastError() by calling CloseHandle(), QProcess::tr() or just not adding it. Change-Id: Ic16faa6d68a32d42d620fffd1a8e72be718bf19d Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
This commit is contained in:
parent
3d007ff2e9
commit
23e67332a0
@ -513,6 +513,12 @@ bool QProcessPrivate::callCreateProcess(QProcess::CreateProcessArguments *cpargs
|
|||||||
cpargs->inheritHandles, cpargs->flags, cpargs->environment,
|
cpargs->inheritHandles, cpargs->flags, cpargs->environment,
|
||||||
cpargs->currentDirectory, cpargs->startupInfo,
|
cpargs->currentDirectory, cpargs->startupInfo,
|
||||||
cpargs->processInformation);
|
cpargs->processInformation);
|
||||||
|
if (!success) {
|
||||||
|
// don't CloseHandle here (we'll do that in cleanup()) so GetLastError()
|
||||||
|
// remains unmodified
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (stdinChannel.pipe[0] != INVALID_Q_PIPE) {
|
if (stdinChannel.pipe[0] != INVALID_Q_PIPE) {
|
||||||
CloseHandle(stdinChannel.pipe[0]);
|
CloseHandle(stdinChannel.pipe[0]);
|
||||||
stdinChannel.pipe[0] = INVALID_Q_PIPE;
|
stdinChannel.pipe[0] = INVALID_Q_PIPE;
|
||||||
@ -576,9 +582,10 @@ void QProcessPrivate::startProcess()
|
|||||||
|
|
||||||
if (!callCreateProcess(&cpargs)) {
|
if (!callCreateProcess(&cpargs)) {
|
||||||
// Capture the error string before we do CloseHandle below
|
// Capture the error string before we do CloseHandle below
|
||||||
QString errorString = QProcess::tr("Process failed to start: %1").arg(qt_error_string());
|
QString errorString = qt_error_string();
|
||||||
cleanup();
|
cleanup();
|
||||||
setErrorAndEmit(QProcess::FailedToStart, errorString);
|
setErrorAndEmit(QProcess::FailedToStart,
|
||||||
|
QProcess::tr("Process failed to start: %1").arg(errorString));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -946,7 +953,9 @@ bool QProcessPrivate::startDetached(qint64 *pid)
|
|||||||
if (!success) {
|
if (!success) {
|
||||||
if (pid)
|
if (pid)
|
||||||
*pid = -1;
|
*pid = -1;
|
||||||
setErrorAndEmit(QProcess::FailedToStart);
|
QString errorString = qt_error_string();
|
||||||
|
setErrorAndEmit(QProcess::FailedToStart,
|
||||||
|
QProcess::tr("Process failed to start: %1").arg(errorString));
|
||||||
}
|
}
|
||||||
|
|
||||||
closeChannels();
|
closeChannels();
|
||||||
|
@ -25,6 +25,9 @@
|
|||||||
# include <sys/resource.h>
|
# include <sys/resource.h>
|
||||||
# include <sys/wait.h>
|
# include <sys/wait.h>
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef Q_OS_WIN
|
||||||
|
# include <winerror.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <QtTest/private/qemulationdetector_p.h>
|
#include <QtTest/private/qemulationdetector_p.h>
|
||||||
|
|
||||||
@ -424,8 +427,13 @@ void tst_QProcess::simpleStartFail()
|
|||||||
|
|
||||||
#ifdef Q_OS_UNIX
|
#ifdef Q_OS_UNIX
|
||||||
QVERIFY2(process.errorString().contains(": execve: "), process.errorString().toLocal8Bit());
|
QVERIFY2(process.errorString().contains(": execve: "), process.errorString().toLocal8Bit());
|
||||||
QVERIFY2(process.errorString().contains(qt_error_string(ENOENT)), process.errorString().toLocal8Bit());
|
int errorcode = ENOENT;
|
||||||
|
#else
|
||||||
|
// value happens to match ENOENT, but that's a coincidence
|
||||||
|
int errorcode = ERROR_FILE_NOT_FOUND;
|
||||||
#endif
|
#endif
|
||||||
|
QVERIFY2(process.errorString().contains(qt_error_string(errorcode)),
|
||||||
|
process.errorString().toLocal8Bit());
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_QProcess::readFromProcess()
|
void tst_QProcess::readFromProcess()
|
||||||
@ -2940,8 +2948,12 @@ void tst_QProcess::setNonExistentWorkingDirectory()
|
|||||||
|
|
||||||
#ifdef Q_OS_UNIX
|
#ifdef Q_OS_UNIX
|
||||||
QVERIFY2(process.errorString().contains(": chdir: "), process.errorString().toLocal8Bit());
|
QVERIFY2(process.errorString().contains(": chdir: "), process.errorString().toLocal8Bit());
|
||||||
QVERIFY2(process.errorString().contains(qt_error_string(ENOENT)), process.errorString().toLocal8Bit());
|
int errorcode = ENOENT;
|
||||||
|
#else
|
||||||
|
int errorcode = ERROR_DIRECTORY;
|
||||||
#endif
|
#endif
|
||||||
|
QVERIFY2(process.errorString().contains(qt_error_string(errorcode)),
|
||||||
|
process.errorString().toLocal8Bit());
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_QProcess::startFinishStartFinish()
|
void tst_QProcess::startFinishStartFinish()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user