Signed-off-by: Paul Moore <[email protected]>
---
 tools/.gitignore    |    1 +
 tools/Makefile      |    3 +-
 tools/arch_detect.c |   88 +++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 91 insertions(+), 1 deletion(-)
 create mode 100644 tools/arch_detect.c

diff --git a/tools/.gitignore b/tools/.gitignore
index 8e972bf..0822833 100644
--- a/tools/.gitignore
+++ b/tools/.gitignore
@@ -1,3 +1,4 @@
 bpf_disasm
 bpf_sim
 sys_resolver
+arch_detect
diff --git a/tools/Makefile b/tools/Makefile
index 74f2caa..db6b609 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -35,7 +35,8 @@ LDFLAGS := ../src/libseccomp.a
 
 TOOLS = bpf_disasm \
        bpf_sim \
-       sys_resolver
+       sys_resolver \
+       arch_detect
 
 DEPS = $(TOOLS:%=%.d)
 
diff --git a/tools/arch_detect.c b/tools/arch_detect.c
new file mode 100644
index 0000000..0aca5a8
--- /dev/null
+++ b/tools/arch_detect.c
@@ -0,0 +1,88 @@
+/**
+ * Architecture Detector
+ *
+ * Copyright (c) 2013 Red Hat <[email protected]>
+ * Author: Paul Moore <[email protected]>
+ */
+
+/*
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of version 2.1 of the GNU Lesser General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, see <http://www.gnu.org/licenses>.
+ */
+
+#include <errno.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include <seccomp.h>
+
+/**
+ * Print the usage information to stderr and exit
+ * @param program the name of the current program being invoked
+ *
+ * Print the usage information and exit with EINVAL.
+ *
+ */
+static void exit_usage(const char *program)
+{
+       fprintf(stderr,
+               "usage: %s [-h] [-t]\n",
+               program);
+       exit(EINVAL);
+}
+
+/**
+ * main
+ */
+int main(int argc, char *argv[])
+{
+       int opt;
+       int token = 0;
+       uint32_t arch;
+
+       /* parse the command line */
+       while ((opt = getopt(argc, argv, "ht"))> 0) {
+               switch (opt) {
+               case 't':
+                       token = 1;
+                       break;
+               case 'h':
+               default:
+                       /* usage information */
+                       exit_usage(argv[0]);
+               }
+       }
+
+       arch = seccomp_arch_native();
+       if (token == 0) {
+               switch (arch) {
+               case SCMP_ARCH_X86:
+                       printf("x86\n");
+                       break;
+               case SCMP_ARCH_X86_64:
+                       printf("x86_64\n");
+                       break;
+               case SCMP_ARCH_X32:
+                       printf("x32\n");
+                       break;
+               case SCMP_ARCH_ARM:
+                       printf("arm\n");
+                       break;
+               default:
+                       printf("unknown\n");
+               }
+       } else
+               printf("%d\n", arch);
+
+       return 0;
+}


------------------------------------------------------------------------------
Own the Future-Intel&reg; Level Up Game Demo Contest 2013
Rise to greatness in Intel's independent game demo contest.
Compete for recognition, cash, and the chance to get your game 
on Steam. $5K grand prize plus 10 genre and skill prizes. 
Submit your demo by 6/6/13. http://p.sf.net/sfu/intel_levelupd2d
_______________________________________________
libseccomp-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libseccomp-discuss

Reply via email to