]>
Commit | Line | Data |
---|---|---|
7f471354 DK |
1 | // -*- mode: cpp; mode: fold -*- |
2 | // Description /*{{{*/ | |
3 | /* ##################################################################### | |
4 | ||
5 | dummy solver to get quickly a scenario file out of APT | |
6 | ||
7 | ##################################################################### */ | |
8 | /*}}}*/ | |
9 | // Include Files /*{{{*/ | |
10 | #include <apt-pkg/edsp.h> | |
11 | ||
453b82a3 DK |
12 | #include <string.h> |
13 | #include <unistd.h> | |
7f471354 | 14 | #include <cstdio> |
472ff00e | 15 | #include <iostream> |
92b2e38d | 16 | #include <sstream> |
453b82a3 DK |
17 | |
18 | #include <config.h> | |
7f471354 DK |
19 | /*}}}*/ |
20 | ||
21 | // ShowHelp - Show a help screen /*{{{*/ | |
22 | // --------------------------------------------------------------------- | |
23 | /* */ | |
c3ccac92 | 24 | static bool ShowHelp() { |
249aec3b | 25 | ioprintf(std::cout, "%s %s (%s)\n", PACKAGE, PACKAGE_VERSION, COMMON_ARCH); |
7f471354 | 26 | std::cout << |
92b2e38d | 27 | "Usage: apt-dump-solver\n" |
7f471354 | 28 | "\n" |
92b2e38d DK |
29 | "apt-dump-solver is a dummy solver who just dumps its input to the\n" |
30 | "file specified in the environment variable APT_EDSP_DUMP_FILENAME and\n" | |
31 | "exists with a proper EDSP error.\n" | |
7f471354 DK |
32 | "\n" |
33 | " This dump has lost Super Cow Powers.\n"; | |
34 | return true; | |
35 | } | |
36 | /*}}}*/ | |
37 | int main(int argc,const char *argv[]) /*{{{*/ | |
38 | { | |
ef00bd7a DK |
39 | // we really don't need anything |
40 | DropPrivileges(); | |
41 | ||
7f471354 DK |
42 | if (argc > 1 && (strcmp(argv[1], "--help") == 0 || strcmp(argv[1],"-h") == 0 || |
43 | strcmp(argv[1],"-v") == 0 || strcmp(argv[1],"--version") == 0)) { | |
44 | ShowHelp(); | |
45 | return 0; | |
46 | } | |
47 | ||
ef00bd7a DK |
48 | FileFd stdoutfd; |
49 | if (stdoutfd.OpenDescriptor(STDOUT_FILENO, FileFd::WriteOnly | FileFd::BufferedWrite, true) == false) | |
50 | return 1; | |
51 | ||
92b2e38d DK |
52 | char const * const filename = getenv("APT_EDSP_DUMP_FILENAME"); |
53 | if (filename == NULL || strlen(filename) == 0) | |
54 | { | |
55 | EDSP::WriteError("ERR_NO_FILENAME", "You have to set the environment variable APT_EDSP_DUMP_FILENAME\n" | |
56 | "to a valid filename to store the dump of EDSP solver input in.\n" | |
ef00bd7a | 57 | "For example with: export APT_EDSP_DUMP_FILENAME=/tmp/dump.edsp", stdoutfd); |
92b2e38d DK |
58 | return 0; |
59 | } | |
60 | ||
ce1f3a2c | 61 | RemoveFile(argv[0], filename); |
92b2e38d DK |
62 | FileFd input, output; |
63 | if (input.OpenDescriptor(STDIN_FILENO, FileFd::ReadOnly) == false || | |
af859f09 | 64 | output.Open(filename, FileFd::WriteOnly | FileFd::Create | FileFd::Exclusive, FileFd::Extension, 0600) == false || |
92b2e38d DK |
65 | CopyFile(input, output) == false || input.Close() == false || output.Close() == false) |
66 | { | |
67 | std::ostringstream out; | |
68 | out << "Writing EDSP solver input to file '" << filename << "' failed!\n"; | |
69 | _error->DumpErrors(out); | |
ef00bd7a | 70 | EDSP::WriteError("ERR_WRITE_ERROR", out.str(), stdoutfd); |
92b2e38d DK |
71 | return 0; |
72 | } | |
7f471354 | 73 | |
ef00bd7a | 74 | EDSP::WriteError("ERR_JUST_DUMPING", "I am too dumb, i can just dump!\nPlease use one of my friends instead!", stdoutfd); |
92b2e38d | 75 | return 0; |
7f471354 | 76 | } |