Commit | Line | Data |
---|---|---|
8befd5cc MG |
1 | /** |
2 | * Architecture Detector | |
3 | * | |
4 | * Copyright (c) 2013 Red Hat <pmoore@redhat.com> | |
5 | * Author: Paul Moore <paul@paul-moore.com> | |
6 | */ | |
7 | ||
8 | /* | |
9 | * This library is free software; you can redistribute it and/or modify it | |
10 | * under the terms of version 2.1 of the GNU Lesser General Public License as | |
11 | * published by the Free Software Foundation. | |
12 | * | |
13 | * This library is distributed in the hope that it will be useful, but WITHOUT | |
14 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License | |
16 | * for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU Lesser General Public License | |
19 | * along with this library; if not, see <http://www.gnu.org/licenses>. | |
20 | */ | |
21 | ||
22 | #include <errno.h> | |
23 | #include <stdlib.h> | |
24 | #include <stdio.h> | |
25 | #include <unistd.h> | |
26 | ||
27 | #include <seccomp.h> | |
28 | ||
29 | /** | |
30 | * Print the usage information to stderr and exit | |
31 | * @param program the name of the current program being invoked | |
32 | * | |
33 | * Print the usage information and exit with EINVAL. | |
34 | * | |
35 | */ | |
36 | static void exit_usage(const char *program) | |
37 | { | |
38 | fprintf(stderr, | |
39 | "usage: %s [-h] [-t]\n", | |
40 | program); | |
41 | exit(EINVAL); | |
42 | } | |
43 | ||
44 | /** | |
45 | * main | |
46 | */ | |
47 | int main(int argc, char *argv[]) | |
48 | { | |
49 | int opt; | |
50 | int token = 0; | |
51 | uint32_t arch; | |
52 | ||
53 | /* parse the command line */ | |
54 | while ((opt = getopt(argc, argv, "ht")) > 0) { | |
55 | switch (opt) { | |
56 | case 't': | |
57 | token = 1; | |
58 | break; | |
59 | case 'h': | |
60 | default: | |
61 | /* usage information */ | |
62 | exit_usage(argv[0]); | |
63 | } | |
64 | } | |
65 | ||
66 | arch = seccomp_arch_native(); | |
67 | if (token == 0) { | |
68 | switch (arch) { | |
69 | case SCMP_ARCH_X86: | |
70 | printf("x86\n"); | |
71 | break; | |
72 | case SCMP_ARCH_X86_64: | |
73 | printf("x86_64\n"); | |
74 | break; | |
75 | case SCMP_ARCH_X32: | |
76 | printf("x32\n"); | |
77 | break; | |
78 | case SCMP_ARCH_ARM: | |
79 | printf("arm\n"); | |
80 | break; | |
81 | case SCMP_ARCH_AARCH64: | |
82 | printf("aarch64\n"); | |
83 | break; | |
84 | case SCMP_ARCH_MIPS: | |
85 | printf("mips\n"); | |
86 | break; | |
87 | case SCMP_ARCH_MIPSEL: | |
88 | printf("mipsel\n"); | |
89 | break; | |
90 | case SCMP_ARCH_MIPS64: | |
91 | printf("mips64\n"); | |
92 | break; | |
93 | case SCMP_ARCH_MIPSEL64: | |
94 | printf("mipsel64\n"); | |
95 | break; | |
96 | case SCMP_ARCH_MIPS64N32: | |
97 | printf("mips64n32\n"); | |
98 | break; | |
99 | case SCMP_ARCH_MIPSEL64N32: | |
100 | printf("mipsel64n32\n"); | |
101 | break; | |
102 | case SCMP_ARCH_PPC: | |
103 | printf("ppc\n"); | |
104 | break; | |
105 | case SCMP_ARCH_PPC64: | |
106 | printf("ppc64\n"); | |
107 | break; | |
108 | case SCMP_ARCH_PPC64LE: | |
109 | printf("ppc64le\n"); | |
110 | break; | |
111 | case SCMP_ARCH_S390: | |
112 | printf("s390\n"); | |
113 | break; | |
114 | case SCMP_ARCH_S390X: | |
115 | printf("s390x\n"); | |
116 | break; | |
117 | default: | |
118 | printf("unknown\n"); | |
119 | } | |
120 | } else | |
121 | printf("%d\n", arch); | |
122 | ||
123 | return 0; | |
124 | } |