private-main.cc 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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_PLANNER:
  35. case APT_CMD::APT_INTERNAL_SOLVER:
  36. case APT_CMD::APT_SORTPKG:
  37. textdomain("apt-utils");
  38. break;
  39. }
  40. }
  41. void InitLocale() {}
  42. /*}}}*/
  43. void InitSignals() /*{{{*/
  44. {
  45. signal(SIGPIPE,SIG_IGN);
  46. }
  47. /*}}}*/
  48. void CheckIfSimulateMode(CommandLine &CmdL) /*{{{*/
  49. {
  50. // disable locking in simulation, but show the message only for users
  51. // as root hasn't the same problems like unreadable files which can heavily
  52. // distort the simulation.
  53. if (_config->FindB("APT::Get::Simulate") == true &&
  54. (CmdL.FileSize() == 0 ||
  55. (strcmp(CmdL.FileList[0], "source") != 0 && strcmp(CmdL.FileList[0], "download") != 0 &&
  56. strcmp(CmdL.FileList[0], "changelog") != 0)))
  57. {
  58. if (getuid() != 0 && _config->FindB("APT::Get::Show-User-Simulation-Note",true) == true)
  59. // TRANSLATORS: placeholder is a binary name like apt or apt-get
  60. ioprintf(std::cout, _("NOTE: This is only a simulation!\n"
  61. " %s needs root privileges for real execution.\n"
  62. " Keep also in mind that locking is deactivated,\n"
  63. " so don't depend on the relevance to the real current situation!\n"),
  64. _config->Find("Binary").c_str());
  65. _config->Set("Debug::NoLocking",true);
  66. }
  67. }
  68. /*}}}*/
  69. void CheckIfCalledByScript(int argc, const char *argv[]) /*{{{*/
  70. {
  71. if (unlikely(argc < 1)) return;
  72. if(!isatty(STDOUT_FILENO) &&
  73. _config->FindB("Apt::Cmd::Disable-Script-Warning", false) == false)
  74. {
  75. std::cerr << std::endl
  76. << "WARNING: " << flNotDir(argv[0]) << " "
  77. << "does not have a stable CLI interface. "
  78. << "Use with caution in scripts."
  79. << std::endl
  80. << std::endl;
  81. }
  82. }
  83. /*}}}*/