- FILE* input = fdopen(STDIN_FILENO, "r");
- FILE* output = fopen("/tmp/dump.edsp", "w");
- char buffer[400];
- while (fgets(buffer, sizeof(buffer), input) != NULL)
- fputs(buffer, output);
- fclose(output);
- fclose(input);
+ // we really don't need anything
+ DropPrivileges();
+ 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);
+ return 0;
+ }
+
+ if (strcmp(filename, "/dev/null") != 0)
+ unlink(filename);
+ FileFd input, output;
+ if (input.OpenDescriptor(STDIN_FILENO, FileFd::ReadOnly) == false ||
+ output.Open(filename, FileFd::WriteOnly | FileFd::Create | FileFd::Exclusive, 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);
+ return 0;
+ }