diff options
-rw-r--r-- | src/corelib/io/qprocess_unix.cpp | 7 | ||||
-rw-r--r-- | tests/auto/corelib/io/qprocess/tst_qprocess.cpp | 32 |
2 files changed, 31 insertions, 8 deletions
diff --git a/src/corelib/io/qprocess_unix.cpp b/src/corelib/io/qprocess_unix.cpp index 4c3432d6b6..63480dfc6b 100644 --- a/src/corelib/io/qprocess_unix.cpp +++ b/src/corelib/io/qprocess_unix.cpp @@ -672,9 +672,9 @@ void QProcessPrivate::execChild(const char *workingDir, char **path, char **argv qt_safe_close(childStartedPipe[0]); // enter the working directory - if (workingDir) { - if (QT_CHDIR(workingDir) == -1) - qWarning("QProcessPrivate::execChild() failed to chdir to %s", workingDir); + if (workingDir && QT_CHDIR(workingDir) == -1) { + // failed, stop the process + goto report_errno; } // this is a virtual call, and it base behavior is to do nothing. @@ -703,6 +703,7 @@ void QProcessPrivate::execChild(const char *workingDir, char **path, char **argv } // notify failure +report_errno: QString error = qt_error_string(errno); #if defined (QPROCESS_DEBUG) fprintf(stderr, "QProcessPrivate::execChild() failed (%s), notifying parent process\n", qPrintable(error)); diff --git a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp index 4a166c540e..02501ca9d9 100644 --- a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp +++ b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp @@ -122,9 +122,8 @@ private slots: void removeFileWhileProcessIsRunning(); void fileWriterProcess(); void switchReadChannels(); -#ifdef Q_OS_WIN void setWorkingDirectory(); -#endif // Q_OS_WIN + void setNonExistentWorkingDirectory(); #endif // not Q_OS_WINCE void exitStatus_data(); @@ -2192,15 +2191,19 @@ void tst_QProcess::switchReadChannels() #endif //----------------------------------------------------------------------------- -#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) +#ifndef Q_OS_WINCE // Q_OS_WIN - setWorkingDirectory will chdir before starting the process on unices // Windows CE does not support working directory logic void tst_QProcess::setWorkingDirectory() { process = new QProcess; process->setWorkingDirectory("test"); - process->start("testSetWorkingDirectory/testSetWorkingDirectory"); - QVERIFY(process->waitForFinished()); + + // use absolute path because on Windows, the executable is relative to the parent's CWD + // while on Unix with fork it's relative to the child's (with posix_spawn, it could be either). + process->start(QFileInfo("testSetWorkingDirectory/testSetWorkingDirectory").absoluteFilePath()); + + QVERIFY2(process->waitForFinished(), process->errorString().toLocal8Bit()); QByteArray workingDir = process->readAllStandardOutput(); QCOMPARE(QDir("test").canonicalPath(), QDir(workingDir.constData()).canonicalPath()); @@ -2208,6 +2211,25 @@ void tst_QProcess::setWorkingDirectory() delete process; process = 0; } + +//----------------------------------------------------------------------------- +void tst_QProcess::setNonExistentWorkingDirectory() +{ + process = new QProcess; + process->setWorkingDirectory("this/directory/should/not/exist/for/sure"); + + // use absolute path because on Windows, the executable is relative to the parent's CWD + // while on Unix with fork it's relative to the child's (with posix_spawn, it could be either). + process->start(QFileInfo("testSetWorkingDirectory/testSetWorkingDirectory").absoluteFilePath()); + QVERIFY(!process->waitForFinished()); +#ifdef QPROCESS_USE_SPAWN + QEXPECT_FAIL("", "QProcess cannot detect failure to start when using posix_spawn()", Continue); +#endif + QCOMPARE(int(process->error()), int(QProcess::FailedToStart)); + + delete process; + process = 0; +} #endif //----------------------------------------------------------------------------- |