diff options
Diffstat (limited to 'cmdline')
-rw-r--r-- | cmdline/apt-dump-solver.cc | 15 | ||||
-rw-r--r-- | cmdline/apt-internal-solver.cc | 12 |
2 files changed, 18 insertions, 9 deletions
diff --git a/cmdline/apt-dump-solver.cc b/cmdline/apt-dump-solver.cc index 27592f22e..cb7233059 100644 --- a/cmdline/apt-dump-solver.cc +++ b/cmdline/apt-dump-solver.cc @@ -36,20 +36,25 @@ static bool ShowHelp() { /*}}}*/ int main(int argc,const char *argv[]) /*{{{*/ { + // we really don't need anything + DropPrivileges(); + if (argc > 1 && (strcmp(argv[1], "--help") == 0 || strcmp(argv[1],"-h") == 0 || strcmp(argv[1],"-v") == 0 || strcmp(argv[1],"--version") == 0)) { ShowHelp(); return 0; } - // we really don't need anything - DropPrivileges(); + FileFd stdoutfd; + if (stdoutfd.OpenDescriptor(STDOUT_FILENO, FileFd::WriteOnly | FileFd::BufferedWrite, true) == false) + return 1; + char const * const filename = getenv("APT_EDSP_DUMP_FILENAME"); if (filename == NULL || strlen(filename) == 0) { EDSP::WriteError("ERR_NO_FILENAME", "You have to set the environment variable APT_EDSP_DUMP_FILENAME\n" "to a valid filename to store the dump of EDSP solver input in.\n" - "For example with: export APT_EDSP_DUMP_FILENAME=/tmp/dump.edsp", stdout); + "For example with: export APT_EDSP_DUMP_FILENAME=/tmp/dump.edsp", stdoutfd); return 0; } @@ -62,10 +67,10 @@ int main(int argc,const char *argv[]) /*{{{*/ std::ostringstream out; out << "Writing EDSP solver input to file '" << filename << "' failed!\n"; _error->DumpErrors(out); - EDSP::WriteError("ERR_WRITE_ERROR", out.str(), stdout); + EDSP::WriteError("ERR_WRITE_ERROR", out.str(), stdoutfd); return 0; } - EDSP::WriteError("ERR_JUST_DUMPING", "I am too dumb, i can just dump!\nPlease use one of my friends instead!", stdout); + EDSP::WriteError("ERR_JUST_DUMPING", "I am too dumb, i can just dump!\nPlease use one of my friends instead!", stdoutfd); return 0; } diff --git a/cmdline/apt-internal-solver.cc b/cmdline/apt-internal-solver.cc index b88d745c4..2df1d3bef 100644 --- a/cmdline/apt-internal-solver.cc +++ b/cmdline/apt-internal-solver.cc @@ -82,12 +82,14 @@ int main(int argc,const char *argv[]) /*{{{*/ pkgCacheFile CacheFile; CacheFile.Open(NULL, false); APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(CacheFile, CmdL.FileList + 1); - FILE* output = stdout; + FileFd output; + if (output.OpenDescriptor(STDOUT_FILENO, FileFd::WriteOnly | FileFd::BufferedWrite, true) == false) + return 2; if (pkgset.empty() == true) EDSP::WriteScenario(CacheFile, output); else EDSP::WriteLimitedScenario(CacheFile, output, pkgset); - fclose(output); + output.Close(); _error->DumpErrors(std::cerr); return 0; } @@ -102,8 +104,10 @@ int main(int argc,const char *argv[]) /*{{{*/ _config->Set("APT::System", "Debian APT solver interface"); _config->Set("APT::Solver", "internal"); _config->Set("edsp::scenario", "/nonexistent/stdin"); - int input = STDIN_FILENO; - FILE* output = stdout; + FileFd output; + if (output.OpenDescriptor(STDOUT_FILENO, FileFd::WriteOnly | FileFd::BufferedWrite, true) == false) + DIE("stdout couldn't be opened"); + int const input = STDIN_FILENO; SetNonBlock(input, false); EDSP::WriteProgress(0, "Start up solver…", output); |