setarch.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 GPLv2 or later, see file LICENSE in this source tree.
  8. */
  9. //usage:#define setarch_trivial_usage
  10. //usage: "personality PROG ARGS"
  11. //usage:#define setarch_full_usage "\n\n"
  12. //usage: "Personality may be:\n"
  13. //usage: " linux32 Set 32bit uname emulation\n"
  14. //usage: " linux64 Set 64bit uname emulation"
  15. //usage:
  16. //usage:#define linux32_trivial_usage NOUSAGE_STR
  17. //usage:#define linux32_full_usage ""
  18. //usage:
  19. //usage:#define linux64_trivial_usage NOUSAGE_STR
  20. //usage:#define linux64_full_usage ""
  21. #include <sys/personality.h>
  22. #include "libbb.h"
  23. int setarch_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  24. int setarch_main(int argc UNUSED_PARAM, char **argv)
  25. {
  26. int pers;
  27. /* Figure out what personality we are supposed to switch to ...
  28. * we can be invoked as either:
  29. * argv[0],argv[1] == "setarch","personality"
  30. * argv[0] == "personality"
  31. */
  32. if (ENABLE_SETARCH && applet_name[0] == 's'
  33. && argv[1] && strncpy(argv[1], "linux", 5)
  34. ) {
  35. applet_name = argv[1];
  36. argv++;
  37. }
  38. if (applet_name[5] == '6') /* linux64 */
  39. pers = PER_LINUX;
  40. else if (applet_name[5] == '3') /* linux32 */
  41. pers = PER_LINUX32;
  42. else
  43. bb_show_usage();
  44. argv++;
  45. if (argv[0] == NULL)
  46. bb_show_usage();
  47. /* Try to set personality */
  48. if (personality(pers) >= 0) {
  49. /* Try to execute the program */
  50. BB_EXECVP(argv[0], argv);
  51. }
  52. bb_simple_perror_msg_and_die(argv[0]);
  53. }