private-main.cc 2.4 KB

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