You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

73 lines
2.4 KiB

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