From 300f87e1b02e979da8cec444249f09ea0ef167a0 Mon Sep 17 00:00:00 2001 From: John Levon Date: Fri, 21 May 2021 10:57:02 +0100 Subject: gpio-pci-idio-16: default to keep running (#470) Default the gpio device server sample such that it stays running, so that we can do basic sanity testing of client re-connect. Signed-off-by: John Levon Reviewed-by: Swapnil Ingle --- samples/gpio-pci-idio-16.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'samples') diff --git a/samples/gpio-pci-idio-16.c b/samples/gpio-pci-idio-16.c index 138a861..f9caa04 100644 --- a/samples/gpio-pci-idio-16.c +++ b/samples/gpio-pci-idio-16.c @@ -141,6 +141,7 @@ main(int argc, char *argv[]) { int ret; bool verbose = false; + bool restart = true; int opt; struct sigaction act = { .sa_handler = _sa_handler }; vfu_ctx_t *vfu_ctx; @@ -157,13 +158,16 @@ main(int argc, char *argv[]) .write_data = &migration_write_data }; - while ((opt = getopt(argc, argv, "v")) != -1) { + while ((opt = getopt(argc, argv, "Rv")) != -1) { switch (opt) { + case 'R': + restart = false; + break; case 'v': verbose = true; break; default: /* '?' */ - fprintf(stderr, "Usage: %s [-v] \n", argv[0]); + fprintf(stderr, "Usage: %s [-Rv] \n", argv[0]); exit(EXIT_FAILURE); } } @@ -237,12 +241,19 @@ main(int argc, char *argv[]) err(EXIT_FAILURE, "failed to attach device"); } - ret = vfu_run_ctx(vfu_ctx); - if (ret != 0) { - if (errno != ENOTCONN && errno != EINTR) { - err(EXIT_FAILURE, "failed to realize device emulation"); + do { + ret = vfu_run_ctx(vfu_ctx); + if (ret != 0) { + if (errno == ENOTCONN) { + ret = vfu_attach_ctx(vfu_ctx); + if (ret < 0) { + err(EXIT_FAILURE, "failed to re-attach device"); + } + } else if (errno != EINTR) { + err(EXIT_FAILURE, "vfu_run_ctx() failed"); + } } - } + } while (restart); vfu_destroy_ctx(vfu_ctx); return EXIT_SUCCESS; -- cgit v1.1