From: Bartosz Golaszewski Date: Tue, 16 May 2017 09:14:45 +0000 (+0200) Subject: tests: only cleanup the gpio-mockup module from the main process X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=2c846b8d88fc142cbe02b769444b1d30d82865a7;p=qemu-gpiodev%2Flibgpiod.git tests: only cleanup the gpio-mockup module from the main process In preparation for adding support for subprocesses: store the pid of the main process and use it such that we don't try to unload the mockup module twice leading to a splat from libkmod. Signed-off-by: Bartosz Golaszewski --- diff --git a/tests/gpiod-test.c b/tests/gpiod-test.c index 11330c4..bccf02f 100644 --- a/tests/gpiod-test.c +++ b/tests/gpiod-test.c @@ -61,6 +61,7 @@ static struct { struct kmod_ctx *module_ctx; struct kmod_module *module; struct test_context test_ctx; + pid_t main_pid; } globals; enum { @@ -232,6 +233,10 @@ static bool mockup_loaded(void) static void module_cleanup(void) { + /* Don't cleanup from child processes. */ + if (globals.main_pid != getpid()) + return; + msg("cleaning up"); if (mockup_loaded()) @@ -566,6 +571,7 @@ int main(int argc TEST_UNUSED, char **argv TEST_UNUSED) { struct _test_case *test; + globals.main_pid = getpid(); atexit(module_cleanup); msg("libgpiod test suite");