diff --git a/Makefile b/Makefile index a1165fa..587363a 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ include Make.Rules # flags # -all install clean kdebug: %: %-here +all install clean: %: %-here $(MAKE) -C libcap $@ ifneq ($(PAM_CAP),no) $(MAKE) -C pam_cap $@ @@ -52,6 +52,9 @@ ifeq ($(GOLANG),yes) endif $(MAKE) -C progs $@ +ktest: all + $(MAKE) -C kdebug test + sudotest: all $(MAKE) -C tests $@ ifneq ($(PAM_CAP),no) diff --git a/kdebug/Makefile b/kdebug/Makefile index c710050..0e8c11f 100644 --- a/kdebug/Makefile +++ b/kdebug/Makefile @@ -1,9 +1,17 @@ topdir=$(shell pwd)/.. include ../Make.Rules -test: +test: exit + rm -f interactive ./test-kernel.sh +shell: exit + touch interactive + ./test-kernel.sh + +exit: exit.c + $(CC) -O2 $< -o $@ --static + all: @echo cd to kdebug to test a kernel build @@ -11,4 +19,4 @@ install: clean: $(LOCALCLEAN) - rm -f fs.conf initramfs.img + rm -f fs.conf initramfs.img exit interactive diff --git a/kdebug/exit.c b/kdebug/exit.c new file mode 100644 index 0000000..a83232d --- /dev/null +++ b/kdebug/exit.c @@ -0,0 +1,36 @@ +/* + * See https://stackoverflow.com/questions/42208228/how-to-automatically-close-the-execution-of-the-qemu-after-end-of-process + */ +#include +#include +#include +#include + +#define SHUTDOWN_PORT 0x604 +#define EXIT_PORT 0x501 + +static void clean_exit(void) { + ioperm(SHUTDOWN_PORT, 16, 1); + outw(0x2000, SHUTDOWN_PORT); +} + +int main(int argc, char **argv) { + int status; + if (argc != 2) { + clean_exit(); + } + status = atoi(argv[1]); + printf("exiting with status %d (in three seconds)\n", status); + sleep(3); + if (!status) { + clean_exit(); + } + ioperm(EXIT_PORT, 8, 1); + /* + * status returned is 1+(2*orig_status) + */ + outb(status-1, EXIT_PORT); + printf("didn't exit.. did you include '-device isa-debug-exit'" + " in qemu command?\n"); + exit(1); +} diff --git a/kdebug/test-init.sh b/kdebug/test-init.sh index 4b55b51..849d9c7 100644 --- a/kdebug/test-init.sh +++ b/kdebug/test-init.sh @@ -10,5 +10,10 @@ echo done echo Hello, World cd /root -./quicktest.sh -sh -i +if [ -f ./interactive ]; then + ./quicktest.sh + sh -i +else + ./quicktest.sh || ./exit 1 +fi +./exit diff --git a/kdebug/test-kernel.sh b/kdebug/test-kernel.sh index 1326cd7..8ef7b15 100755 --- a/kdebug/test-kernel.sh +++ b/kdebug/test-kernel.sh @@ -47,6 +47,7 @@ file /root/getcap $HERE/../progs/getcap 0755 0 0 file /root/capsh $HERE/../progs/capsh 0755 0 0 file /root/getpcaps $HERE/../progs/getpcaps 0755 0 0 file /root/tcapsh-static $HERE/../progs/tcapsh-static 0755 0 0 +file /root/exit $HERE/exit 0755 0 0 EOF # convenience for some local experiments @@ -55,6 +56,10 @@ if [ -f "$HERE/extras.sh" ]; then . "$HERE/extras.sh" fi +if [ -f "$HERE/interactive" ]; then + echo "file /root/interactive $HERE/interactive 0755 0 0" >> fs.conf +fi + COMMANDS="awk cat chmod cp dmesg fgrep id less ln ls mkdir mount pwd rm rmdir sh sort umount uniq vi" for f in $COMMANDS; do echo slink /bin/$f /sbin/busybox 0755 0 0 >> fs.conf @@ -73,4 +78,5 @@ qemu-system-$(uname -m) -m 1024 \ -kernel $KERNEL \ -initrd initramfs.img \ -append "$APPEND" \ - -smp sockets=2,dies=1,cores=4 + -smp sockets=2,dies=1,cores=4 \ + -device isa-debug-exit