setarch.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 <stdlib.h>
  10. #include <unistd.h>
  11. #include <string.h>
  12. #include <errno.h>
  13. #include <stdio.h>
  14. #include <sys/personality.h>
  15. #include "busybox.h"
  16. int setarch_main(int ATTRIBUTE_UNUSED argc, char **argv)
  17. {
  18. int pers = -1;
  19. /* Figure out what personality we are supposed to switch to ...
  20. * we can be invoked as either:
  21. * argv[0],argv[1] -> "setarch","personality"
  22. * argv[0] -> "personality"
  23. */
  24. retry:
  25. if (argv[0][5] == '6') /* linux64 */
  26. pers = PER_LINUX;
  27. else if (argv[0][5] == '3') /* linux32 */
  28. pers = PER_LINUX32;
  29. else if (pers == -1 && argv[1] != NULL) {
  30. pers = PER_LINUX32;
  31. ++argv;
  32. goto retry;
  33. }
  34. /* make user actually gave us something to do */
  35. ++argv;
  36. if (argv[0] == NULL)
  37. bb_show_usage();
  38. /* Try to set personality */
  39. if (personality(pers) >= 0) {
  40. /* Try to execute the program */
  41. execvp(argv[0], argv);
  42. }
  43. bb_perror_msg_and_die("%s", argv[0]);
  44. }