summaryrefslogtreecommitdiff
path: root/nix
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2021-04-06 12:10:29 +0200
committerLudovic Courtès <ludo@gnu.org>2021-04-09 17:46:38 +0200
commit2d73086262e1fb33cd0f0f16f74a495fe06b38aa (patch)
tree4811dc7447842b834517ac1bf42127f897197428 /nix
parentccff3380867b588f0c68e9daedd5728392a91a3f (diff)
daemon: 'guix substitute' replies on FD 4.
This avoids the situation where error messages would unintentionally go to stderr and be wrongfully interpreted as a reply by the daemon. Fixes <https://bugs.gnu.org/46362>. This is a followup to ee3226e9d54891c7e696912245e4904435be191c. * guix/scripts/substitute.scm (display-narinfo-data): Add 'port' parameter and honor it. (process-query): Likewise. (process-substitution): Likewise. (%error-to-file-descriptor-4?, with-redirected-error-port): Remove. (%reply-file-descriptor): New variable. (guix-substitute): Remove use of 'with-redirected-error-port'. Define 'reply-port' and pass it to 'process-query' and 'process-substitution'. * nix/libstore/build.cc (SubstitutionGoal::handleChildOutput): Swap 'builderOut' and 'fromAgent'. * nix/libstore/local-store.cc (LocalStore::getLineFromSubstituter): Likewise. * tests/substitute.scm <top level>: Set '%reply-file-descriptor' rather than '%error-to-file-descriptor-4?'.
Diffstat (limited to 'nix')
-rw-r--r--nix/libstore/build.cc4
-rw-r--r--nix/libstore/local-store.cc12
2 files changed, 8 insertions, 8 deletions
diff --git a/nix/libstore/build.cc b/nix/libstore/build.cc
index 4f486f08220..5697ae5a436 100644
--- a/nix/libstore/build.cc
+++ b/nix/libstore/build.cc
@@ -3158,13 +3158,13 @@ void SubstitutionGoal::finished()
3158void SubstitutionGoal::handleChildOutput(int fd, const string & data) 3158void SubstitutionGoal::handleChildOutput(int fd, const string & data)
3159{ 3159{
3160 if (verbosity >= settings.buildVerbosity 3160 if (verbosity >= settings.buildVerbosity
3161 && fd == substituter->builderOut.readSide) { 3161 && fd == substituter->fromAgent.readSide) {
3162 writeToStderr(data); 3162 writeToStderr(data);
3163 /* Don't write substitution output to a log file for now. We 3163 /* Don't write substitution output to a log file for now. We
3164 probably should, though. */ 3164 probably should, though. */
3165 } 3165 }
3166 3166
3167 if (fd == substituter->fromAgent.readSide) { 3167 if (fd == substituter->builderOut.readSide) {
3168 /* DATA may consist of several lines. Process them one by one. */ 3168 /* DATA may consist of several lines. Process them one by one. */
3169 string input = data; 3169 string input = data;
3170 while (!input.empty()) { 3170 while (!input.empty()) {
diff --git a/nix/libstore/local-store.cc b/nix/libstore/local-store.cc
index c304e2ddd16..675d1ba66f7 100644
--- a/nix/libstore/local-store.cc
+++ b/nix/libstore/local-store.cc
@@ -780,8 +780,8 @@ Path LocalStore::queryPathFromHashPart(const string & hashPart)
780 }); 780 });
781} 781}
782 782
783/* Read a line from the substituter's stdout, while also processing 783/* Read a line from the substituter's reply file descriptor, while also
784 its stderr. */ 784 processing its stderr. */
785string LocalStore::getLineFromSubstituter(Agent & run) 785string LocalStore::getLineFromSubstituter(Agent & run)
786{ 786{
787 string res, err; 787 string res, err;
@@ -802,9 +802,9 @@ string LocalStore::getLineFromSubstituter(Agent & run)
802 } 802 }
803 803
804 /* Completely drain stderr before dealing with stdout. */ 804 /* Completely drain stderr before dealing with stdout. */
805 if (FD_ISSET(run.builderOut.readSide, &fds)) { 805 if (FD_ISSET(run.fromAgent.readSide, &fds)) {
806 char buf[4096]; 806 char buf[4096];
807 ssize_t n = read(run.builderOut.readSide, (unsigned char *) buf, sizeof(buf)); 807 ssize_t n = read(run.fromAgent.readSide, (unsigned char *) buf, sizeof(buf));
808 if (n == -1) { 808 if (n == -1) {
809 if (errno == EINTR) continue; 809 if (errno == EINTR) continue;
810 throw SysError("reading from substituter's stderr"); 810 throw SysError("reading from substituter's stderr");
@@ -822,9 +822,9 @@ string LocalStore::getLineFromSubstituter(Agent & run)
822 } 822 }
823 823
824 /* Read from stdout until we get a newline or the buffer is empty. */ 824 /* Read from stdout until we get a newline or the buffer is empty. */
825 else if (FD_ISSET(run.fromAgent.readSide, &fds)) { 825 else if (FD_ISSET(run.builderOut.readSide, &fds)) {
826 unsigned char c; 826 unsigned char c;
827 readFull(run.fromAgent.readSide, (unsigned char *) &c, 1); 827 readFull(run.builderOut.readSide, (unsigned char *) &c, 1);
828 if (c == '\n') { 828 if (c == '\n') {
829 if (!err.empty()) printMsg(lvlError, "substitute: " + err); 829 if (!err.empty()) printMsg(lvlError, "substitute: " + err);
830 return res; 830 return res;