summaryrefslogtreecommitdiff
path: root/apt-private/private-json-hooks.cc
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@debian.org>2018-06-28 08:12:50 +0000
committerJulian Andres Klode <jak@debian.org>2018-06-28 08:12:50 +0000
commita7b4dd425c10730b886f3ea0b2e045ee5015cfe5 (patch)
treec945300df9e0360c00318b12f40fbac122e2ad1b /apt-private/private-json-hooks.cc
parent8c3cb66e65cddf1ac297daba5bb442b415577137 (diff)
parent1d53cffad22c92645090e0e6ddde31fe4f7c3b05 (diff)
Merge branch 'pu/lp1776218-allow-hooks-to-not-handshake' into 'master'
Handle JSON hooks that just close the file/exit and fix some other errors See merge request apt-team/apt!21
Diffstat (limited to 'apt-private/private-json-hooks.cc')
-rw-r--r--apt-private/private-json-hooks.cc10
1 files changed, 8 insertions, 2 deletions
diff --git a/apt-private/private-json-hooks.cc b/apt-private/private-json-hooks.cc
index 07c89ca23..0e4b4913b 100644
--- a/apt-private/private-json-hooks.cc
+++ b/apt-private/private-json-hooks.cc
@@ -387,21 +387,26 @@ bool RunJsonHook(std::string const &option, std::string const &method, const cha
if (size < 0)
{
- _error->Error("Could not read response to hello message from hook %s: %s", Opts->Value.c_str(), strerror(errno));
+ if (errno != ECONNRESET)
+ _error->Error("Could not read response to hello message from hook %s: %s", Opts->Value.c_str(), strerror(errno));
+ goto out;
}
else if (strstr(line, "error") != nullptr)
{
_error->Error("Hook %s reported an error during hello: %s", Opts->Value.c_str(), line);
+ goto out;
}
size = getline(&line, &linesize, F);
if (size < 0)
{
- _error->Error("Could not read message separator line after handshake from %s: %s", Opts->Value.c_str(), strerror(errno));
+ _error->Error("Could not read message separator line after handshake from %s: %s", Opts->Value.c_str(), feof(F) ? "end of file" : strerror(errno));
+ goto out;
}
else if (size == 0 || line[0] != '\n')
{
_error->Error("Expected empty line after handshake from %s, received %s", Opts->Value.c_str(), line);
+ goto out;
}
fwrite(TheData.data(), TheData.size(), 1, F);
@@ -409,6 +414,7 @@ bool RunJsonHook(std::string const &option, std::string const &method, const cha
fwrite(ByeData.data(), ByeData.size(), 1, F);
fwrite("\n\n", 2, 1, F);
+ out:
fclose(F);
// Clean up the sub process
if (ExecWait(Process, Opts->Value.c_str()) == false)