- int Pipes[2] = {-1,-1};
- if (pipe(Pipes) != 0)
- return _error->Errno("pipe", "Failed to create Pipe");
-
- pid_t Process = ExecFork();
- if (Process == 0)
+ std::string const urlstring = URL;
+ std::vector<const char *> Args;
+ Args.push_back(AutoDetectProxyCmd.c_str());
+ Args.push_back(urlstring.c_str());
+ Args.push_back(nullptr);
+ FileFd PipeFd;
+ pid_t Child;
+ if(Popen(&Args[0], PipeFd, Child, FileFd::ReadOnly) == false)
+ return _error->Error("ProxyAutoDetect command '%s' failed!", AutoDetectProxyCmd.c_str());
+ char buf[512];
+ bool const goodread = PipeFd.ReadLine(buf, sizeof(buf)) != nullptr;
+ PipeFd.Close();
+ if (ExecWait(Child, "ProxyAutoDetect") == false)
+ return false;
+ // no output means the detector has no idea which proxy to use
+ // and apt will use the generic proxy settings
+ if (goodread == false)
+ return true;
+ auto const cleanedbuf = _strstrip(buf);
+ // We warn about this as the implementor probably meant to use DIRECT instead
+ if (cleanedbuf[0] == '\0')