diff options
Diffstat (limited to 'src/corelib/io/qprocess_win.cpp')
-rw-r--r-- | src/corelib/io/qprocess_win.cpp | 42 |
1 files changed, 31 insertions, 11 deletions
diff --git a/src/corelib/io/qprocess_win.cpp b/src/corelib/io/qprocess_win.cpp index 04c67b4070..e64b133815 100644 --- a/src/corelib/io/qprocess_win.cpp +++ b/src/corelib/io/qprocess_win.cpp @@ -28,6 +28,8 @@ QT_BEGIN_NAMESPACE +constexpr UINT KillProcessExitCode = 0xf291; + using namespace Qt::StringLiterals; QProcessEnvironment QProcessEnvironment::systemEnvironment() @@ -138,6 +140,7 @@ static bool qt_create_pipe(Q_PIPE *pipe, bool isInputPipe, BOOL defInheritFlag) DWORD dwError = GetLastError(); if (dwError != ERROR_PIPE_BUSY || !--attempts) { qErrnoWarning(dwError, "QProcess: CreateNamedPipe failed."); + SetLastError(dwError); return false; } } @@ -152,8 +155,10 @@ static bool qt_create_pipe(Q_PIPE *pipe, bool isInputPipe, BOOL defInheritFlag) FILE_FLAG_OVERLAPPED, NULL); if (hClient == INVALID_HANDLE_VALUE) { + DWORD dwError = GetLastError(); qErrnoWarning("QProcess: CreateFile failed."); CloseHandle(hServer); + SetLastError(dwError); return false; } @@ -170,10 +175,12 @@ static bool qt_create_pipe(Q_PIPE *pipe, bool isInputPipe, BOOL defInheritFlag) WaitForSingleObject(overlapped.hEvent, INFINITE); break; default: + dwError = GetLastError(); qErrnoWarning(dwError, "QProcess: ConnectNamedPipe failed."); CloseHandle(overlapped.hEvent); CloseHandle(hClient); CloseHandle(hServer); + SetLastError(dwError); return false; } } @@ -199,8 +206,13 @@ bool QProcessPrivate::openChannel(Channel &channel) switch (channel.type) { case Channel::Normal: { // we're piping this channel to our own process - if (&channel == &stdinChannel) - return qt_create_pipe(channel.pipe, true, FALSE); + if (&channel == &stdinChannel) { + if (!qt_create_pipe(channel.pipe, true, FALSE)) { + setErrorAndEmit(QProcess::FailedToStart, "pipe: "_L1 + qt_error_string(errno)); + return false; + } + return true; + } if (&channel == &stdoutChannel) { if (!stdoutChannel.reader) { @@ -213,8 +225,10 @@ bool QProcessPrivate::openChannel(Channel &channel) q->connect(stderrChannel.reader, SIGNAL(readyRead()), SLOT(_q_canReadStandardError())); } } - if (!qt_create_pipe(channel.pipe, false, FALSE)) + if (!qt_create_pipe(channel.pipe, false, FALSE)) { + setErrorAndEmit(QProcess::FailedToStart, "pipe: "_L1 + qt_error_string(errno)); return false; + } channel.reader->setHandle(channel.pipe[0]); channel.reader->startAsyncRead(); @@ -263,7 +277,6 @@ bool QProcessPrivate::openChannel(Channel &channel) setErrorAndEmit(QProcess::FailedToStart, QProcess::tr("Could not open output redirection for writing")); } - cleanup(); return false; } case Channel::PipeSource: { @@ -280,8 +293,10 @@ bool QProcessPrivate::openChannel(Channel &channel) Q_ASSERT(source == &stdoutChannel); Q_ASSERT(sink->process == this && sink->type == Channel::PipeSink); - if (!qt_create_pipe(source->pipe, /* in = */ false, TRUE)) // source is stdout + if (!qt_create_pipe(source->pipe, /* in = */ false, TRUE)) { // source is stdout + setErrorAndEmit(QProcess::FailedToStart, "pipe: "_L1 + qt_error_string(errno)); return false; + } sink->pipe[0] = source->pipe[0]; source->pipe[0] = INVALID_Q_PIPE; @@ -300,8 +315,10 @@ bool QProcessPrivate::openChannel(Channel &channel) Q_ASSERT(sink == &stdinChannel); Q_ASSERT(source->process == this && source->type == Channel::PipeSource); - if (!qt_create_pipe(sink->pipe, /* in = */ true, TRUE)) // sink is stdin + if (!qt_create_pipe(sink->pipe, /* in = */ true, TRUE)) { // sink is stdin + setErrorAndEmit(QProcess::FailedToStart, "pipe: "_L1 + qt_error_string(errno)); return false; + } source->pipe[1] = sink->pipe[1]; sink->pipe[1] = INVALID_Q_PIPE; @@ -521,9 +538,9 @@ void QProcessPrivate::startProcess() q->setProcessState(QProcess::Starting); if (!openChannels()) { - QString errorString = QProcess::tr("Process failed to start: %1").arg(qt_error_string()); + // openChannel sets the error string + Q_ASSERT(!errorString.isEmpty()); cleanup(); - setErrorAndEmit(QProcess::FailedToStart, errorString); return; } @@ -632,7 +649,7 @@ void QProcessPrivate::terminateProcess() void QProcessPrivate::killProcess() { if (pid) - TerminateProcess(pid->hProcess, 0xf291); + TerminateProcess(pid->hProcess, KillProcessExitCode); } bool QProcessPrivate::waitForStarted(const QDeadlineTimer &) @@ -782,8 +799,11 @@ void QProcessPrivate::findExitCode() Q_ASSERT(pid); if (GetExitCodeProcess(pid->hProcess, &theExitCode)) { exitCode = theExitCode; - crashed = (exitCode == 0xf291 // our magic number, see killProcess - || (theExitCode >= 0x80000000 && theExitCode < 0xD0000000)); + if (exitCode == KillProcessExitCode + || (theExitCode >= 0x80000000 && theExitCode < 0xD0000000)) + exitStatus = QProcess::CrashExit; + else + exitStatus = QProcess::NormalExit; } } |