private-main.cc 2.4 KB

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