]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
setarch: make verify_arch_domain extendable
authorAlexey Gladkov <gladkov.alexey@gmail.com>
Tue, 23 Jun 2020 14:56:19 +0000 (16:56 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 24 Jun 2020 13:05:53 +0000 (15:05 +0200)
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

index cb4b0815756531914f8af74911fb488282610259..b057b4df80e3214f483aa93d21127b3198e52fed 100644 (file)
@@ -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";