All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexey Gladkov <gladkov.alexey@gmail.com>
To: util-linux@vger.kernel.org
Cc: Karel Zak <kzak@redhat.com>, "Dmitry V. Levin" <ldv@altlinux.org>,
	Gleb Fotengauer-Malinovskiy <glebfm@altlinux.org>
Subject: [PATCH 1/2] setarch: make verify_arch_domain extendable
Date: Tue, 23 Jun 2020 16:56:19 +0200	[thread overview]
Message-ID: <20200623145620.2669920-2-gladkov.alexey@gmail.com> (raw)
In-Reply-To: <20200623145620.2669920-1-gladkov.alexey@gmail.com>

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

Signed-off-by: Alexey Gladkov <gladkov.alexey@gmail.com>
---
 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


  reply	other threads:[~2020-06-23 14:56 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-23 14:56 [PATCH 0/2] setarch: add arm and aarch64 architectures to transition Alexey Gladkov
2020-06-23 14:56 ` Alexey Gladkov [this message]
2020-06-23 14:56 ` [PATCH 2/2] setarch: add arm and aarch64 architectures to transition rules Alexey Gladkov
2020-06-24 13:09 ` [PATCH 0/2] setarch: add arm and aarch64 architectures to transition Karel Zak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200623145620.2669920-2-gladkov.alexey@gmail.com \
    --to=gladkov.alexey@gmail.com \
    --cc=glebfm@altlinux.org \
    --cc=kzak@redhat.com \
    --cc=ldv@altlinux.org \
    --cc=util-linux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.