From c7da50ef8cf30558537425918cf03f5e72c680c1 Mon Sep 17 00:00:00 2001 From: Girish Ramakrishnan Date: Wed, 11 Apr 2012 17:35:47 -0700 Subject: Suppress warnings caused by ignoring chdir retval MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Using g++ 4.6.1, we get warnings like below: qprocess_unix.cpp:1376:69: warning: ignoring return value of ‘int chdir(const char*)’, declared with attribute warn_unused_result [-Wunused-result] g++ is pretty adamant and prints the warning even if you explicitly ignore using (void). So, just check for error and print a warning. Change-Id: Ifd6f3b6bb9e17d44aa235815b06a762131ca8751 Reviewed-by: Thiago Macieira --- src/corelib/io/qprocess_unix.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/corelib/io/qprocess_unix.cpp b/src/corelib/io/qprocess_unix.cpp index 2da2913c6f..bfa132f353 100644 --- a/src/corelib/io/qprocess_unix.cpp +++ b/src/corelib/io/qprocess_unix.cpp @@ -772,7 +772,8 @@ static pid_t doSpawn(int fd_count, int fd_map[], char **argv, char **envp, qWarning("ThreadCtl(): cannot hold threads: %s", qPrintable(qt_error_string(errno))); oldWorkingDir = QT_GETCWD(buff, PATH_MAX + 1); - QT_CHDIR(workingDir); + if (QT_CHDIR(workingDir) == -1) + qWarning("ThreadCtl(): failed to chdir to %s", workingDir); } pid_t childPid; @@ -783,7 +784,8 @@ static pid_t doSpawn(int fd_count, int fd_map[], char **argv, char **envp, } if (oldWorkingDir) { - QT_CHDIR(oldWorkingDir); + if (QT_CHDIR(oldWorkingDir) == -1) + qWarning("ThreadCtl(): failed to chdir to %s", oldWorkingDir); if (ThreadCtl(_NTO_TCTL_THREADS_CONT, 0) == -1) qFatal("ThreadCtl(): cannot resume threads: %s", qPrintable(qt_error_string(errno))); @@ -853,8 +855,10 @@ void QProcessPrivate::execChild(const char *workingDir, char **path, char **argv qt_safe_close(childStartedPipe[0]); // enter the working directory - if (workingDir) - QT_CHDIR(workingDir); + if (workingDir) { + if (QT_CHDIR(workingDir) == -1) + qWarning("QProcessPrivate::execChild() failed to chdir to %s", workingDir); + } // this is a virtual call, and it base behavior is to do nothing. q->setupChildProcess(); @@ -1372,8 +1376,10 @@ bool QProcessPrivate::startDetached(const QString &program, const QStringList &a if (doubleForkPid == 0) { qt_safe_close(pidPipe[1]); - if (!encodedWorkingDirectory.isEmpty()) - QT_CHDIR(encodedWorkingDirectory.constData()); + 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]; for (int i = 0; i < arguments.size(); ++i) { @@ -1426,7 +1432,8 @@ bool QProcessPrivate::startDetached(const QString &program, const QStringList &a qt_safe_close(startedPipe[1]); qt_safe_write(pidPipe[1], (const char *)&doubleForkPid, sizeof(pid_t)); - QT_CHDIR("/"); + if (QT_CHDIR("/") == -1) + qWarning("QProcessPrivate::startDetached: failed to chdir to /"); ::_exit(1); } -- cgit v1.2.3