private-main.cc 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #include <config.h>
  2. #include <apt-pkg/cmndline.h>
  3. #include <apt-pkg/configuration.h>
  4. #include <apt-pkg/fileutl.h>
  5. #include <apt-private/private-main.h>
  6. #include <iostream>
  7. #include <locale>
  8. #include <string.h>
  9. #include <unistd.h>
  10. #include <signal.h>
  11. #include <apti18n.h>
  12. void InitLocale(APT_CMD const binary) /*{{{*/
  13. {
  14. std::locale::global(std::locale(""));
  15. switch(binary)
  16. {
  17. case APT_CMD::APT:
  18. case APT_CMD::APT_CACHE:
  19. case APT_CMD::APT_CDROM:
  20. case APT_CMD::APT_CONFIG:
  21. case APT_CMD::APT_HELPER:
  22. case APT_CMD::APT_GET:
  23. case APT_CMD::APT_MARK:
  24. textdomain("apt");
  25. break;
  26. case APT_CMD::APT_EXTRACTTEMPLATES:
  27. case APT_CMD::APT_FTPARCHIVE:
  28. case APT_CMD::APT_INTERNAL_SOLVER:
  29. case APT_CMD::APT_SORTPKG:
  30. textdomain("apt-utils");
  31. break;
  32. }
  33. }
  34. void InitLocale() {}
  35. /*}}}*/
  36. void InitSignals() /*{{{*/
  37. {
  38. signal(SIGPIPE,SIG_IGN);
  39. }
  40. /*}}}*/
  41. void CheckIfSimulateMode(CommandLine &CmdL) /*{{{*/
  42. {
  43. // disable locking in simulation, but show the message only for users
  44. // as root hasn't the same problems like unreadable files which can heavily
  45. // distort the simulation.
  46. if (_config->FindB("APT::Get::Simulate") == true &&
  47. (CmdL.FileSize() == 0 ||
  48. (strcmp(CmdL.FileList[0], "source") != 0 && strcmp(CmdL.FileList[0], "download") != 0 &&
  49. strcmp(CmdL.FileList[0], "changelog") != 0)))
  50. {
  51. if (getuid() != 0 && _config->FindB("APT::Get::Show-User-Simulation-Note",true) == true)
  52. std::cout << _("NOTE: This is only a simulation!\n"
  53. " apt-get needs root privileges for real execution.\n"
  54. " Keep also in mind that locking is deactivated,\n"
  55. " so don't depend on the relevance to the real current situation!"
  56. ) << std::endl;
  57. _config->Set("Debug::NoLocking",true);
  58. }
  59. }
  60. /*}}}*/
  61. void CheckIfCalledByScript(int argc, const char *argv[]) /*{{{*/
  62. {
  63. if (unlikely(argc < 1)) return;
  64. if(!isatty(STDOUT_FILENO) &&
  65. _config->FindB("Apt::Cmd::Disable-Script-Warning", false) == false)
  66. {
  67. std::cerr << std::endl
  68. << "WARNING: " << flNotDir(argv[0]) << " "
  69. << "does not have a stable CLI interface. "
  70. << "Use with caution in scripts."
  71. << std::endl
  72. << std::endl;
  73. }
  74. }
  75. /*}}}*/