apt-dump-solver.cc 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 <config.h>
  14. /*}}}*/
  15. // ShowHelp - Show a help screen /*{{{*/
  16. // ---------------------------------------------------------------------
  17. /* */
  18. static bool ShowHelp() {
  19. ioprintf(std::cout, "%s %s (%s)\n", PACKAGE, PACKAGE_VERSION, COMMON_ARCH);
  20. std::cout <<
  21. "Usage: apt-dump-resolver\n"
  22. "\n"
  23. "apt-dump-resolver is a dummy solver who just dumps its input to the\n"
  24. "file /tmp/dump.edsp and exists with a proper EDSP error.\n"
  25. "\n"
  26. " This dump has lost Super Cow Powers.\n";
  27. return true;
  28. }
  29. /*}}}*/
  30. int main(int argc,const char *argv[]) /*{{{*/
  31. {
  32. if (argc > 1 && (strcmp(argv[1], "--help") == 0 || strcmp(argv[1],"-h") == 0 ||
  33. strcmp(argv[1],"-v") == 0 || strcmp(argv[1],"--version") == 0)) {
  34. ShowHelp();
  35. return 0;
  36. }
  37. // we really don't need anything
  38. DropPrivileges();
  39. FILE* input = fdopen(STDIN_FILENO, "r");
  40. FILE* output = fopen("/tmp/dump.edsp", "w");
  41. char buffer[400];
  42. while (fgets(buffer, sizeof(buffer), input) != NULL)
  43. fputs(buffer, output);
  44. fclose(output);
  45. fclose(input);
  46. EDSP::WriteError("ERR_JUST_DUMPING", "I am too dumb, i can just dump!\nPlease use one of my friends instead!", stdout);
  47. }