[PATCH 1/2] setarch: make verify_arch_domain extendable

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When other compatible architectures are introduced, they will also have
to be added to the verifier.

Signed-off-by: Alexey Gladkov <gladkov.alexey@xxxxxxxxx>
---
 sys-utils/setarch.c | 29 ++++++++++++++++++-----------
 1 file changed, 18 insertions(+), 11 deletions(-)

diff --git a/sys-utils/setarch.c b/sys-utils/setarch.c
index cb4b08157..b057b4df8 100644
--- a/sys-utils/setarch.c
+++ b/sys-utils/setarch.c
@@ -254,22 +254,29 @@ static struct arch_domain *get_arch_domain(struct arch_domain *doms, const char
 	return !d || d->perval < 0 ? NULL : d;
 }
 
-static void verify_arch_domain(struct arch_domain *dom, const char *wanted)
+static void verify_arch_domain(struct arch_domain *doms, struct arch_domain *target, const char *wanted)
 {
 	struct utsname un;
 
-	if (!dom || !dom->result_arch)
+	if (!doms || !target || !target->result_arch)
 		return;
 
 	uname(&un);
-	if (strcmp(un.machine, dom->result_arch) != 0) {
-		if (strcmp(dom->result_arch, "i386") != 0
-		    || (strcmp(un.machine, "i486") != 0
-			&& strcmp(un.machine, "i586")
-			&& strcmp(un.machine, "i686") != 0
-			&& strcmp(un.machine, "athlon") != 0))
-			errx(EXIT_FAILURE, _("Kernel cannot set architecture to %s"), wanted);
+
+	if (!strcmp(un.machine, target->result_arch))
+		return;
+
+	if (!strcmp(target->result_arch, "i386")) {
+		struct arch_domain *dom;
+		for (dom = doms; dom->target_arch != NULL; dom++) {
+			if (!dom->result_arch || strcmp(dom->result_arch, target->result_arch))
+				continue;
+			if (!strcmp(dom->target_arch, un.machine))
+				return;
+		}
 	}
+
+	errx(EXIT_FAILURE, _("Kernel cannot set architecture to %s"), wanted);
 }
 
 int main(int argc, char *argv[])
@@ -279,7 +286,7 @@ int main(int argc, char *argv[])
 	int verbose = 0;
 	int archwrapper;
 	int c;
-	struct arch_domain *doms, *target = NULL;
+	struct arch_domain *doms = NULL, *target = NULL;
 	unsigned long pers_value = 0;
 	char *shell = NULL, *shell_arg = NULL;
 
@@ -434,7 +441,7 @@ set_arch:
 
 	/* make sure architecture is set as expected */
 	if (arch)
-		verify_arch_domain(target, arch);
+		verify_arch_domain(doms, target, arch);
 
 	if (!argc) {
 		shell = "/bin/sh";
-- 
2.25.4




[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux