diff options
Diffstat (limited to 'src/corelib/io/qprocess.cpp')
-rw-r--r-- | src/corelib/io/qprocess.cpp | 45 |
1 files changed, 29 insertions, 16 deletions
diff --git a/src/corelib/io/qprocess.cpp b/src/corelib/io/qprocess.cpp index baba9a0f9e..7d7cdef203 100644 --- a/src/corelib/io/qprocess.cpp +++ b/src/corelib/io/qprocess.cpp @@ -1,8 +1,8 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2015 The Qt Company Ltd. ** Copyright (C) 2014 Intel Corporation -** Contact: http://www.qt-project.org/legal +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtCore module of the Qt Toolkit. ** @@ -11,9 +11,9 @@ ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -24,8 +24,8 @@ ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** $QT_END_LICENSE$ @@ -89,6 +89,8 @@ QT_END_NAMESPACE #ifdef Q_OS_WIN #include <qwineventnotifier.h> +#else +#include <private/qcore_unix_p.h> #endif #ifndef QT_NO_PROCESS @@ -810,8 +812,7 @@ QProcessPrivate::QProcessPrivate() deathNotifier = 0; childStartedPipe[0] = INVALID_Q_PIPE; childStartedPipe[1] = INVALID_Q_PIPE; - deathPipe[0] = INVALID_Q_PIPE; - deathPipe[1] = INVALID_Q_PIPE; + forkfd = -1; exitCode = 0; crashed = false; dying = false; @@ -821,9 +822,6 @@ QProcessPrivate::QProcessPrivate() notifier = 0; processFinishedNotifier = 0; #endif // Q_OS_WIN -#ifdef Q_OS_UNIX - serial = 0; -#endif } /*! @@ -890,9 +888,10 @@ void QProcessPrivate::cleanup() closeChannel(&stderrChannel); closeChannel(&stdinChannel); destroyPipe(childStartedPipe); - destroyPipe(deathPipe); #ifdef Q_OS_UNIX - serial = 0; + if (forkfd != -1) + qt_safe_close(forkfd); + forkfd = -1; #endif } @@ -1079,6 +1078,17 @@ bool QProcessPrivate::_q_processDied() processError = QProcess::Crashed; q->setErrorString(QProcess::tr("Process crashed")); emit q->error(processError); + } else { +#ifdef QPROCESS_USE_SPAWN + // if we're using posix_spawn, waitForStarted always succeeds. + // POSIX documents that the sub-process launched by posix_spawn will exit with code + // 127 if anything prevents the target program from starting. + // http://pubs.opengroup.org/onlinepubs/009695399/functions/posix_spawn.html + if (exitStatus == QProcess::NormalExit && exitCode == 127) { + processError = QProcess::FailedToStart; + q->setErrorString(QProcess::tr("Process failed to start (spawned process exited with code 127)")); + } +#endif } bool wasRunning = (processState == QProcess::Running); @@ -1754,6 +1764,9 @@ QProcessEnvironment QProcess::processEnvironment() const If msecs is -1, this function will not time out. + \note On some UNIX operating systems, this function may return true but + the process may later report a QProcess::FailedToStart error. + \sa started(), waitForReadyRead(), waitForBytesWritten(), waitForFinished() */ bool QProcess::waitForStarted(int msecs) @@ -2346,7 +2359,7 @@ int QProcess::execute(const QString &program, const QStringList &arguments) QProcess process; process.setReadChannelMode(ForwardedChannels); process.start(program, arguments); - if (!process.waitForFinished(-1)) + if (!process.waitForFinished(-1) || process.error() == FailedToStart) return -2; return process.exitStatus() == QProcess::NormalExit ? process.exitCode() : -1; } @@ -2369,7 +2382,7 @@ int QProcess::execute(const QString &command) QProcess process; process.setReadChannelMode(ForwardedChannels); process.start(command); - if (!process.waitForFinished(-1)) + if (!process.waitForFinished(-1) || process.error() == FailedToStart) return -2; return process.exitStatus() == QProcess::NormalExit ? process.exitCode() : -1; } |