]> git.saurik.com Git - apt.git/blobdiff - cmdline/apt-dump-solver.cc
remove duplicated 'the' from guides doc-base abstract
[apt.git] / cmdline / apt-dump-solver.cc
index 47b515be5cb70abbd6c8ad63e7495bb8c1e94211..0de248e75861f1a5a5aa3996e0448d135af5ff46 100644 (file)
@@ -36,37 +36,41 @@ 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;
        }
 
-       if (strcmp(filename, "/dev/null") != 0)
-          unlink(filename);
+       RemoveFile(argv[0], filename);
        FileFd input, output;
        if (input.OpenDescriptor(STDIN_FILENO, FileFd::ReadOnly) == false ||
-             output.Open(filename, FileFd::WriteOnly | FileFd::Create | FileFd::Exclusive, 0600) == false ||
+             output.Open(filename, FileFd::WriteOnly | FileFd::Create | FileFd::Exclusive, FileFd::Extension, 0600) == false ||
              CopyFile(input, output) == false || input.Close() == false || output.Close() == false)
        {
           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;
 }