From 1fa1a2319a047d3525c9c510df538cb327035ce1 Mon Sep 17 00:00:00 2001 From: Erik Boasson Date: Tue, 19 Sep 2023 14:14:38 +0200 Subject: [PATCH] Fix unreachable code warning in variouspub ... by adding SIGINT handler that terminates the process cleanly. Signed-off-by: Erik Boasson --- examples/dynsub/variouspub.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/examples/dynsub/variouspub.c b/examples/dynsub/variouspub.c index c75d80505b..d5398d6b5e 100644 --- a/examples/dynsub/variouspub.c +++ b/examples/dynsub/variouspub.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include "dds/dds.h" @@ -109,6 +110,14 @@ static void usage (const char *argv0) exit (2); } +static volatile sig_atomic_t interrupted; + +static void sigint (int sig) +{ + (void) sig; + interrupted = 1; +} + int main (int argc, char **argv) { if (argc != 2) @@ -131,7 +140,8 @@ int main (int argc, char **argv) const dds_entity_t writer = dds_create_writer (participant, topic, NULL, NULL); uint32_t sample_idx = 0; uint32_t count = 0; - while (1) + signal (SIGINT, sigint); + while (!interrupted) { dds_return_t ret = 0; void *sample = tpentry->samples[sample_idx];