From abba628268308c7c23f168f01966a88fe208885e Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 26 Jun 2020 23:42:29 +0200 Subject: Reorder config check before checking systemd for non-interactive http If this option is disabled (which it is by default in Debian), we don't have to make the call and the checks around it. Not that it really matters that much as if it would we would be better checking only once. --- methods/http.cc | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'methods') diff --git a/methods/http.cc b/methods/http.cc index 7036b743c..1d2c41337 100644 --- a/methods/http.cc +++ b/methods/http.cc @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -979,15 +980,18 @@ void HttpMethod::SendReq(FetchItem *Itm) "Debian APT-HTTP/1.3 (" PACKAGE_VERSION ")"); #ifdef HAVE_SYSTEMD - char *unit = nullptr; - sd_pid_get_unit(getpid(), &unit); - if (unit != nullptr && *unit != '\0' && not APT::String::Startswith(unit, "user@") // user@ _is_ interactive - && unit != "packagekit.service"s // packagekit likely is interactive - && unit != "dbus.service"s // aptdaemon and qapt don't have systemd services - && ConfigFindB("User-Agent-Non-Interactive", false)) - Req << " non-interactive"; - - free(unit); + if (ConfigFindB("User-Agent-Non-Interactive", false)) + { + using APT::operator""_sv; + char *unit = nullptr; + sd_pid_get_unit(getpid(), &unit); + if (unit != nullptr && *unit != '\0' && not APT::String::Startswith(unit, "user@") // user@ _is_ interactive + && "packagekit.service"_sv != unit // packagekit likely is interactive + && "dbus.service"_sv != unit) // aptdaemon and qapt don't have systemd services + Req << " non-interactive"; + + free(unit); + } #endif Req << "\r\n"; -- cgit v1.2.3