private-main.cc 2.5 KB

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