From 70eebc40e2cb3718e02b8543e5f2a1624b3eda69 Mon Sep 17 00:00:00 2001
From: Ben Hutchings <ben@decadent.org.uk>
Date: Tue, 23 Aug 2011 07:00:01 +0100
Subject: [PATCH] setarch: add --uname-2.6 option for personality flag UNAME26

[kzak@redhat.com: - minor change in usage()]

Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Signed-off-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
---
 configure.ac        |    1 +
 sys-utils/setarch.8 |    3 +++
 sys-utils/setarch.c |   18 +++++++++++++++---
 3 files changed, 19 insertions(+), 3 deletions(-)

Index: util-linux-2.19.1/configure.ac
===================================================================
--- util-linux-2.19.1.orig/configure.ac
+++ util-linux-2.19.1/configure.ac
@@ -785,6 +785,7 @@ AC_CHECK_MEMBERS([struct stat.st_mtim.tv
 	[#include <sys/stat.h>])
 
 AC_CHECK_DECLS([
+ UNAME26,
  ADDR_NO_RANDOMIZE,
  FDPIC_FUNCPTRS,
  MMAP_PAGE_ZERO,
Index: util-linux-2.19.1/sys-utils/setarch.8
===================================================================
--- util-linux-2.19.1.orig/sys-utils/setarch.8
+++ util-linux-2.19.1/sys-utils/setarch.8
@@ -12,6 +12,11 @@ setarch \- change reported architecture
 .RI [ options ]
 .RI [ program
 .RI [ arguments ]]
+.br
+.I uname26
+.RI [ options ]
+.RI [ program
+.RI [ arguments ]]
 .SH DESCRIPTION
 .B setarch
 This utility currently only affects the output of uname -m. For example, on an AMD64 system, running 'setarch i386 program' will cause 'program' to see
@@ -29,6 +34,9 @@ Be verbose.
 .I "\-h," "\-\-help"
 Display help (it is also displayed when setarch takes no arguments).
 .TP
+.I "\-\-uname\-2.6"
+Causes the program to see a kernel version number beginning with 2.6.
+.TP
 .I "\-3," "\-\-3gb"
 Specifies that processes should use a maximum of 3GB of address space on systems where it is supported (ADDR_LIMIT_3GB).
 .TP
Index: util-linux-2.19.1/sys-utils/setarch.c
===================================================================
--- util-linux-2.19.1.orig/sys-utils/setarch.c
+++ util-linux-2.19.1/sys-utils/setarch.c
@@ -39,9 +39,11 @@
 
 #define set_pers(pers) ((long)syscall(SYS_personality, pers))
 
-/* Option --4gb has no equivalent short option, use a non-character as a
-   pseudo short option. */
-#define OPT_4GB (CHAR_MAX+1)
+/* Options without equivalent short options */
+enum {
+	OPT_4GB		= CHAR_MAX + 1,
+	OPT_UNAME26
+};
 
 #define turn_on(_flag, _opts) \
 	do { \
@@ -51,6 +53,9 @@
 	} while(0)
 
 
+#if !HAVE_DECL_UNAME26
+# define UNAME26                 0x0020000
+#endif
 #if !HAVE_DECL_ADDR_NO_RANDOMIZE
 # define ADDR_NO_RANDOMIZE       0x0040000
 #endif
@@ -99,6 +104,7 @@ struct option longopts[] =
     { "sticky-timeouts",    0, 0, 'T' },
     { "3gb",                0, 0, '3' },
     { "4gb",                0, 0, OPT_4GB },
+    { "uname-2.6",          0, 0, OPT_UNAME26 },
     { NULL,                 0, 0, 0 }
 };
 
@@ -128,6 +134,9 @@ show_help(void)
    " -3, --3gb                limits the used address space to a maximum of 3 GB\n"
    "     --4gb                ignored (for backward compatibility only)\n"));
 
+   printf(_(
+   "     --uname-2.6          turns on UNAME26\n"));
+
   printf(_("\nFor more information see setarch(8).\n"));
   exit(EXIT_SUCCESS);
 }
@@ -308,12 +317,22 @@ int main(int argc, char *argv[])
 	break;
     case OPT_4GB:          /* just ignore this one */
       break;
+    case OPT_UNAME26:
+	turn_on(UNAME26, options);
+	break;
     }
   }
 
   argc -= optind;
   argv += optind;
 
+  struct utsname un;
+  if (!strcmp(p, "uname26")) {
+    uname(&un);
+    turn_on(UNAME26, options);
+    p = un.machine;
+  }
+
   if (set_arch(p, options))
     error(EXIT_FAILURE, errno, _("Failed to set personality to %s"), p);
 
Index: util-linux-2.19.1/sys-utils/Makefile.am
===================================================================
--- util-linux-2.19.1.orig/sys-utils/Makefile.am
+++ util-linux-2.19.1/sys-utils/Makefile.am
@@ -57,7 +57,7 @@ bin_PROGRAMS += arch
 dist_man_MANS += arch.1
 endif
 
-SETARCH_LINKS = linux32 linux64
+SETARCH_LINKS = linux32 linux64 uname26
 
 if ARCH_S390
 SETARCH_LINKS += s390 s390x
