Skip to content

Commit

Permalink
Fix unreachable code warning in variouspub
Browse files Browse the repository at this point in the history
... by adding SIGINT handler that terminates the process cleanly.

Signed-off-by: Erik Boasson <[email protected]>
  • Loading branch information
eboasson authored and dpotman committed Sep 19, 2023
1 parent 116241d commit 1fa1a23
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion examples/dynsub/variouspub.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <signal.h>
#include <assert.h>

#include "dds/dds.h"
Expand Down Expand Up @@ -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)
Expand All @@ -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];
Expand Down

0 comments on commit 1fa1a23

Please sign in to comment.