QProcess::startDetached/Unix: move up the chdir() and remove qWarning
That qWarning cannot be in the child process (we don't know if a user logger is fork-no-exec-safe) and the failure to chdir() should be reported as a failure in QProcess::startDetached() instead. Change-Id: Ic90d8429a0eb4837971dfffd1664e7577c81610b Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de> Reviewed-by: David Llewellyn-Jones <david.llewellyn-jones@jolla.com> (cherry picked from commit 31bb141aed52549fae52f2156ac66bd2647cad16)
This commit is contained in:
parent
ef1a0231e0
commit
68b329d733
@ -916,18 +916,18 @@ bool QProcessPrivate::startDetached(qint64 *pid)
|
|||||||
qt_safe_close(startedPipe[0]);
|
qt_safe_close(startedPipe[0]);
|
||||||
qt_safe_close(pidPipe[0]);
|
qt_safe_close(pidPipe[0]);
|
||||||
|
|
||||||
pid_t doubleForkPid = fork();
|
pid_t doubleForkPid = 0;
|
||||||
|
if (!encodedWorkingDirectory.isEmpty())
|
||||||
|
doubleForkPid = QT_CHDIR(encodedWorkingDirectory.constData());
|
||||||
|
|
||||||
|
if (doubleForkPid == 0)
|
||||||
|
doubleForkPid = fork();
|
||||||
if (doubleForkPid == 0) {
|
if (doubleForkPid == 0) {
|
||||||
qt_safe_close(pidPipe[1]);
|
qt_safe_close(pidPipe[1]);
|
||||||
|
|
||||||
// Render channels configuration.
|
// Render channels configuration.
|
||||||
commitChannels();
|
commitChannels();
|
||||||
|
|
||||||
if (!encodedWorkingDirectory.isEmpty()) {
|
|
||||||
if (QT_CHDIR(encodedWorkingDirectory.constData()) == -1)
|
|
||||||
qWarning("QProcessPrivate::startDetached: failed to chdir to %s", encodedWorkingDirectory.constData());
|
|
||||||
}
|
|
||||||
|
|
||||||
char **argv = new char *[arguments.size() + 2];
|
char **argv = new char *[arguments.size() + 2];
|
||||||
for (int i = 0; i < arguments.size(); ++i)
|
for (int i = 0; i < arguments.size(); ++i)
|
||||||
argv[i + 1] = ::strdup(QFile::encodeName(arguments.at(i)).constData());
|
argv[i + 1] = ::strdup(QFile::encodeName(arguments.at(i)).constData());
|
||||||
|
@ -118,6 +118,7 @@ private slots:
|
|||||||
void discardUnwantedOutput();
|
void discardUnwantedOutput();
|
||||||
void setWorkingDirectory();
|
void setWorkingDirectory();
|
||||||
void setNonExistentWorkingDirectory();
|
void setNonExistentWorkingDirectory();
|
||||||
|
void detachedSetNonExistentWorkingDirectory();
|
||||||
|
|
||||||
void exitStatus_data();
|
void exitStatus_data();
|
||||||
void exitStatus();
|
void exitStatus();
|
||||||
@ -2266,6 +2267,20 @@ void tst_QProcess::setNonExistentWorkingDirectory()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_QProcess::detachedSetNonExistentWorkingDirectory()
|
||||||
|
{
|
||||||
|
QProcess process;
|
||||||
|
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.setProgram(QFileInfo("testSetWorkingDirectory/testSetWorkingDirectory").absoluteFilePath());
|
||||||
|
|
||||||
|
qint64 pid = -1;
|
||||||
|
QVERIFY(!process.startDetached(&pid));
|
||||||
|
QCOMPARE(pid, -1);
|
||||||
|
}
|
||||||
|
|
||||||
void tst_QProcess::startFinishStartFinish()
|
void tst_QProcess::startFinishStartFinish()
|
||||||
{
|
{
|
||||||
QProcess process;
|
QProcess process;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user