setarch.c 1.1 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 UNUSED_PARAM, char **argv)
  13. {
  14. int pers;
  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. if (ENABLE_SETARCH && applet_name[0] == 's'
  21. && argv[1] && strncpy(argv[1], "linux", 5)
  22. ) {
  23. applet_name = argv[1];
  24. argv++;
  25. }
  26. if (applet_name[5] == '6') /* linux64 */
  27. pers = PER_LINUX;
  28. else if (applet_name[5] == '3') /* linux32 */
  29. pers = PER_LINUX32;
  30. else
  31. bb_show_usage();
  32. argv++;
  33. if (argv[0] == NULL)
  34. bb_show_usage();
  35. /* Try to set personality */
  36. if (personality(pers) >= 0) {
  37. /* Try to execute the program */
  38. BB_EXECVP(argv[0], argv);
  39. }
  40. bb_simple_perror_msg_and_die(argv[0]);
  41. }