setarch.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * Linux32/linux64 allows for changing uname emulation.
  4. *
  5. * Copyright 2002 Andi Kleen, SuSE Labs.
  6. *
  7. * Licensed under GPL v2 or later, see file License for details.
  8. */
  9. #include <sys/personality.h>
  10. #include "libbb.h"
  11. int setarch_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  12. int setarch_main(int argc ATTRIBUTE_UNUSED, char **argv)
  13. {
  14. int pers = -1;
  15. /* Figure out what personality we are supposed to switch to ...
  16. * we can be invoked as either:
  17. * argv[0],argv[1] -> "setarch","personality"
  18. * argv[0] -> "personality"
  19. */
  20. retry:
  21. if (argv[0][5] == '6') /* linux64 */
  22. pers = PER_LINUX;
  23. else if (argv[0][5] == '3') /* linux32 */
  24. pers = PER_LINUX32;
  25. else if (pers == -1 && argv[1] != NULL) {
  26. pers = PER_LINUX32;
  27. ++argv;
  28. goto retry;
  29. }
  30. /* make user actually gave us something to do */
  31. ++argv;
  32. if (argv[0] == NULL)
  33. bb_show_usage();
  34. /* Try to set personality */
  35. if (personality(pers) >= 0) {
  36. /* Try to execute the program */
  37. BB_EXECVP(argv[0], argv);
  38. }
  39. bb_simple_perror_msg_and_die(argv[0]);
  40. }