diff options
author | Eamon Walsh <ewalsh@tycho.nsa.gov> | 2011-02-16 19:30:41 -0500 |
---|---|---|
committer | Eamon Walsh <ewalsh@tycho.nsa.gov> | 2011-02-16 19:38:19 -0500 |
commit | 2224456b9642522b2ffa1fc53a211f81468d8491 (patch) | |
tree | 08175897564d4e18af0d6fa21cdbb2226c605ca1 | |
parent | 9877aab7bd458a82e96605fc39d12549ca6daa6a (diff) |
Add some more utility programs to util/.
-rw-r--r-- | util/.gitignore | 5 | ||||
-rw-r--r-- | util/Makefile | 11 | ||||
-rw-r--r-- | util/gnttest.c | 58 | ||||
-rw-r--r-- | util/pipe2.c | 84 |
4 files changed, 158 insertions, 0 deletions
diff --git a/util/.gitignore b/util/.gitignore new file mode 100644 index 0000000..abd841a --- /dev/null +++ b/util/.gitignore @@ -0,0 +1,5 @@ +evdump +gnttest +pipe2 +xsdump +!Makefile diff --git a/util/Makefile b/util/Makefile new file mode 100644 index 0000000..4429a43 --- /dev/null +++ b/util/Makefile @@ -0,0 +1,11 @@ +TARGETS = pipe2 gnttest evdump xsdump + +CFLAGS = -Wall -I../src +LDLIBS := -lxenctrl -lxenstore -ludev + +.PHONY: all clean + +all: $(TARGETS) + +clean: + $(RM) $(TARGETS) *.o diff --git a/util/gnttest.c b/util/gnttest.c new file mode 100644 index 0000000..b8dea2f --- /dev/null +++ b/util/gnttest.c @@ -0,0 +1,58 @@ +#include <stdarg.h> +#include <stdlib.h> +#include <sys/types.h> +#include <fcntl.h> +#include <unistd.h> +#include <stdbool.h> +#include <sys/mman.h> +#include <errno.h> +#include <stdio.h> +#include <string.h> +#include <time.h> + +#include <xs.h> +#include <xenctrl.h> +#include <xen/event_channel.h> +#include <xen/io/xenbus.h> +#include <xen/io/fbif.h> +#include <xen/io/kbdif.h> +#include <xen/io/protocols.h> + +static void +bail(const char *msg) +{ + fprintf(stderr, "%s\n", msg); + exit(1); +} + +int +main(int argc, char **argv) +{ + xc_interface *xc; + xc_gnttab *gntdev; + int dom; + grant_ref_t ref; + unsigned char *page; + + if (argc != 3) + bail("Usage: gnttest <domid> <grant-ref>"); + + dom = atoi(argv[1]); + ref = atoi(argv[2]); + + xc = xc_interface_open(0,0,0); + if (!xc) + bail("Failed to open xc"); + + gntdev = xc_gnttab_open(NULL, 0); + if (gntdev < 0) + bail("Failed to open gntdev"); + + page = xc_gnttab_map_grant_ref(gntdev, dom, ref, PROT_READ); + write(1, page, 4096); + + xc_gnttab_munmap(gntdev, page, 1); + xc_gnttab_close(gntdev); + xc_interface_close(xc); + return 0; +} diff --git a/util/pipe2.c b/util/pipe2.c new file mode 100644 index 0000000..26d145d --- /dev/null +++ b/util/pipe2.c @@ -0,0 +1,84 @@ +#include <sys/types.h> +#include <sys/wait.h> +#include <unistd.h> +#include <fcntl.h> +#include <stdio.h> +#include <stdlib.h> + +static void +bail(const char *msg) +{ + fprintf(stderr, "%s\n", msg); + exit(1); +} + +int +main(int argc, char *const argv[], char *const envp[]) +{ + int p1[2], p2[2]; + char *a1[4], *a2[4]; + char prog[] = "/usr/lib64/xen/bin/xenconsole"; + pid_t pid, c1, c2; + int status; + + if (argc != 3) + bail("Usage: pipe2 <guest1> <guest2>"); + + a1[0] = prog; + //a1[1] = "console"; + a1[1] = argv[1]; + a1[2] = NULL; + + a2[0] = prog; + //a2[1] = "console"; + a2[1] = argv[2]; + a2[2] = NULL; + + if (pipe(p1) < 0) + bail("pipe() call failed!"); + if (pipe(p2) < 0) + bail("pipe() call failed!"); + + c1 = fork(); + if (c1 == 0) { + close(0); + close(1); + close(2); + close(p1[1]); + close(p2[0]); + + dup2(p1[0], 0); + dup2(p2[1], 1); + dup2(p2[1], 2); + + close(p2[1]); + close(p1[0]); + + execve(prog, a1, envp); + } + + c2 = fork(); + if (c2 == 0) { + close(0); + close(1); + close(2); + close(p2[1]); + close(p1[0]); + + dup2(p2[0], 0); + dup2(p1[1], 1); + dup2(p1[1], 2); + + close(p1[1]); + close(p2[0]); + + execve(prog, a2, envp); + } + + pid = waitpid(-1, &status, 0); + fprintf(stderr, "%d exit %d\n", pid, status); + pid = waitpid(-1, &status, 0); + fprintf(stderr, "%d exit %d\n", pid, status); + + return 0; +} |