diff options
author | John Levon <john.levon@nutanix.com> | 2020-11-19 09:37:28 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-19 09:37:28 +0000 |
commit | f54581b9d4837e92cf644b48505e5419d8df72cb (patch) | |
tree | 6bef3a27f37ecc7422e291028f085e61740644aa /samples | |
parent | 58b89f9e0f7cd7847606fb22d2c0b9a38735cd62 (diff) | |
download | libvfio-user-f54581b9d4837e92cf644b48505e5419d8df72cb.zip libvfio-user-f54581b9d4837e92cf644b48505e5419d8df72cb.tar.gz libvfio-user-f54581b9d4837e92cf644b48505e5419d8df72cb.tar.bz2 |
enable assert() in release builds (#98)
Diffstat (limited to 'samples')
-rw-r--r-- | samples/gpio-pci-idio-16.c | 18 | ||||
-rw-r--r-- | samples/server.c | 9 |
2 files changed, 18 insertions, 9 deletions
diff --git a/samples/gpio-pci-idio-16.c b/samples/gpio-pci-idio-16.c index 3e9b1ed..c8d5454 100644 --- a/samples/gpio-pci-idio-16.c +++ b/samples/gpio-pci-idio-16.c @@ -67,7 +67,8 @@ static void _sa_handler(UNUSED int signum) { } -int main(int argc, char *argv[]) +int +main(int argc, char *argv[]) { int ret; bool verbose = false; @@ -107,23 +108,28 @@ int main(int argc, char *argv[]) sigemptyset(&act.sa_mask); if (sigaction(SIGINT, &act, NULL) == -1) { - fprintf(stderr, "warning: failed to register signal handler: %m\n"); + err(EXIT_FAILURE, "failed to register signal handler"); } lm_ctx = lm_ctx_create(&dev_info); if (lm_ctx == NULL) { - fprintf(stderr, "failed to initialize device emulation: %m\n"); - return -1; + if (errno == EINTR) { + printf("interrupted\n"); + exit(EXIT_SUCCESS); + } + err(EXIT_FAILURE, "failed to initialize device emulation"); } + ret = lm_ctx_drive(lm_ctx); + if (ret != 0) { if (ret != -ENOTCONN && ret != -EINTR) { - fprintf(stderr, "failed to realize device emulation: %m\n"); + err(EXIT_FAILURE, "failed to realize device emulation"); } } lm_ctx_destroy(lm_ctx); - return ret; + return EXIT_SUCCESS; } /* ex: set tabstop=4 shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/samples/server.c b/samples/server.c index ac00bb6..7020821 100644 --- a/samples/server.c +++ b/samples/server.c @@ -366,7 +366,8 @@ migration_data_written(void *pvt, __u64 count, __u64 offset) return 0; } -int main(int argc, char *argv[]){ +int main(int argc, char *argv[]) +{ int ret; bool verbose = false; char opt; @@ -404,7 +405,7 @@ int main(int argc, char *argv[]){ sparse_areas = calloc(1, sizeof(*sparse_areas) + (nr_sparse_areas * sizeof(struct lm_mmap_area))); if (sparse_areas == NULL) { - err(EXIT_FAILURE, "MMAP sparse areas ENOMEM\n"); + err(EXIT_FAILURE, "MMAP sparse areas ENOMEM"); } sparse_areas->nr_mmap_areas = nr_sparse_areas; for (i = 0; i < nr_sparse_areas; i++) { @@ -489,14 +490,16 @@ int main(int argc, char *argv[]){ } } } while (ret == 0); + if (ret != -ENOTCONN && ret != -EINTR && ret != -ESHUTDOWN) { errx(EXIT_FAILURE, "failed to realize device emulation: %s\n", strerror(-ret)); } + lm_ctx_destroy(lm_ctx); free(server_data.bar1); free(sparse_areas); - return ret; + return EXIT_SUCCESS; } /* ex: set tabstop=4 shiftwidth=4 softtabstop=4 expandtab: */ |