diff options
author | Frerich Raabe <raabe@froglogic.com> | 2015-11-11 15:32:27 +0100 |
---|---|---|
committer | Karsten Heimrich <karsten.heimrich@theqtcompany.com> | 2015-12-09 08:33:17 +0000 |
commit | 610f7e3ce241b92f6fad5ad783fbbeb9dd3f3be4 (patch) | |
tree | 766b49ac4e651a7c4bd8a1d734b7aacfefc0d2ec /src/libs/installer/adminauthorization_x11.cpp | |
parent | d10e1605fb9f5e5fde452a148a7a89521f738571 (diff) |
When running sudo'ed process, make reading from child non-blocking
For some reason, using a blocking read would sometimes(!) not cause the
sudo process to finish. In fact, it didn't even seem to start running,
even though it showed up in the process list. Maybe a deadlock? Using
non-blocking reads fixes this.
Change-Id: Ic8a94b38e4be426abcc08bbd0dd887a3cffda5d5
Task-number: QTIFW-771
Reviewed-by: Katja Marttila <katja.marttila@theqtcompany.com>
Diffstat (limited to 'src/libs/installer/adminauthorization_x11.cpp')
-rw-r--r-- | src/libs/installer/adminauthorization_x11.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/libs/installer/adminauthorization_x11.cpp b/src/libs/installer/adminauthorization_x11.cpp index eadb7438e..e8221be34 100644 --- a/src/libs/installer/adminauthorization_x11.cpp +++ b/src/libs/installer/adminauthorization_x11.cpp @@ -56,6 +56,7 @@ #include <sys/ioctl.h> #include <sys/types.h> #include <sys/wait.h> +#include <errno.h> #include <iostream> @@ -135,6 +136,10 @@ bool AdminAuthorization::execute(QWidget *parent, const QString &program, const if (flags != -1) ::fcntl(pipedData[0], F_SETFL, flags | O_NONBLOCK); + flags = ::fcntl(masterFD, F_GETFL); + if (flags != -1) + ::fcntl(masterFD, F_SETFL, flags | O_NONBLOCK); + pid_t child = fork(); if (child < -1) { @@ -152,6 +157,7 @@ bool AdminAuthorization::execute(QWidget *parent, const QString &program, const ::close(pipedData[1]); QRegExp re(QLatin1String("[Pp]assword.*:")); + QByteArray data; QByteArray errData; int bytes = 0; int errBytes = 0; @@ -162,6 +168,10 @@ bool AdminAuthorization::execute(QWidget *parent, const QString &program, const if (::waitpid(child, &state, WNOHANG) == -1) break; bytes = ::read(masterFD, buf, 1023); + if (bytes == -1 && errno == EAGAIN) + bytes = 0; + else if (bytes > 0) + data.append(buf, bytes); errBytes = ::read(pipedData[0], errBuf, 1023); if (errBytes > 0) { @@ -169,7 +179,7 @@ bool AdminAuthorization::execute(QWidget *parent, const QString &program, const errBytes=0; } if (bytes > 0) { - const QString line = QString::fromLatin1(buf, bytes); + const QString line = QString::fromLatin1(data); if (re.indexIn(line) != -1) { const QString password = getPassword(parent); if (password.isEmpty()) { |