private-main.cc 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 <string.h>
  8. #include <unistd.h>
  9. #include <signal.h>
  10. #include <apti18n.h>
  11. void InitLocale() /*{{{*/
  12. {
  13. setlocale(LC_ALL,"");
  14. textdomain(PACKAGE);
  15. }
  16. /*}}}*/
  17. void InitSignals() /*{{{*/
  18. {
  19. signal(SIGPIPE,SIG_IGN);
  20. }
  21. /*}}}*/
  22. void CheckIfSimulateMode(CommandLine &CmdL) /*{{{*/
  23. {
  24. // disable locking in simulation, but show the message only for users
  25. // as root hasn't the same problems like unreadable files which can heavily
  26. // distort the simulation.
  27. if (_config->FindB("APT::Get::Simulate") == true &&
  28. (CmdL.FileSize() == 0 ||
  29. (strcmp(CmdL.FileList[0], "source") != 0 && strcmp(CmdL.FileList[0], "download") != 0 &&
  30. strcmp(CmdL.FileList[0], "changelog") != 0)))
  31. {
  32. if (getuid() != 0 && _config->FindB("APT::Get::Show-User-Simulation-Note",true) == true)
  33. std::cout << _("NOTE: This is only a simulation!\n"
  34. " apt-get needs root privileges for real execution.\n"
  35. " Keep also in mind that locking is deactivated,\n"
  36. " so don't depend on the relevance to the real current situation!"
  37. ) << std::endl;
  38. _config->Set("Debug::NoLocking",true);
  39. }
  40. }
  41. /*}}}*/
  42. void CheckIfCalledByScript(int argc, const char *argv[]) /*{{{*/
  43. {
  44. if (unlikely(argc < 1)) return;
  45. if(!isatty(STDOUT_FILENO) &&
  46. _config->FindB("Apt::Cmd::Disable-Script-Warning", false) == false)
  47. {
  48. std::cerr << std::endl
  49. << "WARNING: " << flNotDir(argv[0]) << " "
  50. << "does not have a stable CLI interface. "
  51. << "Use with caution in scripts."
  52. << std::endl
  53. << std::endl;
  54. }
  55. }
  56. /*}}}*/