0003-setarch-fix-obscure-sparc32bash-use-case.patch 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. From 3fa06e049012218d883d0e1251df86bafbc446bf Mon Sep 17 00:00:00 2001
  2. From: Karel Zak <kzak@redhat.com>
  3. Date: Thu, 22 Nov 2018 11:03:35 +0100
  4. Subject: [PATCH] setarch: fix obscure sparc32bash use-case
  5. Reported-by: Carlos Santos <casantos@datacom.com.br>
  6. Signed-off-by: Karel Zak <kzak@redhat.com>
  7. Signed-off-by: Carlos Santos <casantos@datacom.com.br>
  8. ---
  9. sys-utils/setarch.c | 28 ++++++++++++++++++----------
  10. 1 file changed, 18 insertions(+), 10 deletions(-)
  11. diff --git a/sys-utils/setarch.c b/sys-utils/setarch.c
  12. index a733f7b3c..7c0a63fbb 100644
  13. --- a/sys-utils/setarch.c
  14. +++ b/sys-utils/setarch.c
  15. @@ -268,6 +268,7 @@ int main(int argc, char *argv[])
  16. int c;
  17. struct arch_domain *doms, *target;
  18. unsigned long pers_value = 0;
  19. + char *shell = NULL, *shell_arg = NULL;
  20. /* Options without equivalent short options */
  21. enum {
  22. @@ -310,14 +311,14 @@ int main(int argc, char *argv[])
  23. archwrapper = strcmp(program_invocation_short_name, "setarch") != 0;
  24. if (archwrapper) {
  25. arch = program_invocation_short_name; /* symlinks to setarch */
  26. -#if defined(__sparc64__) || defined(__sparc__)
  27. +
  28. + /* Don't use ifdef sparc here, we get "Unrecognized architecture"
  29. + * error message later if necessary */
  30. if (strcmp(arch, "sparc32bash") == 0) {
  31. - if (set_arch(arch, 0L, 0))
  32. - err(EXIT_FAILURE, _("Failed to set personality to %s"), arch);
  33. - execl("/bin/bash", "", NULL);
  34. - errexec("/bin/bash");
  35. + shell = "/bin/bash";
  36. + shell_arg = "";
  37. + goto set_arch;
  38. }
  39. -#endif
  40. } else {
  41. if (1 < argc && *argv[1] != '-') {
  42. arch = argv[1];
  43. @@ -391,6 +392,7 @@ int main(int argc, char *argv[])
  44. argc -= optind;
  45. argv += optind;
  46. +set_arch:
  47. /* get execution domain (architecture) */
  48. if (arch) {
  49. doms = init_arch_domains();
  50. @@ -422,17 +424,23 @@ int main(int argc, char *argv[])
  51. if (arch)
  52. verify_arch_domain(target, arch);
  53. + if (!argc) {
  54. + shell = "/bin/sh";
  55. + shell_arg = "-sh";
  56. + }
  57. if (verbose) {
  58. - printf(_("Execute command `%s'.\n"), argc ? argv[0] : "/bin/sh");
  59. + printf(_("Execute command `%s'.\n"), shell ? shell : argv[0]);
  60. /* flush all output streams before exec */
  61. fflush(NULL);
  62. }
  63. - if (!argc) {
  64. - execl("/bin/sh", "-sh", NULL);
  65. - errexec("/bin/sh");
  66. + /* Execute shell */
  67. + if (shell) {
  68. + execl(shell, shell_arg, NULL);
  69. + errexec(shell);
  70. }
  71. + /* Execute on command line specified command */
  72. execvp(argv[0], argv);
  73. errexec(argv[0]);
  74. }
  75. --
  76. 2.14.5