From a096afb871262967dc124409efae6285e3babb3a Mon Sep 17 00:00:00 2001 From: Philip Oetinger Date: Tue, 7 Nov 2023 13:22:16 +0100 Subject: [PATCH] introduce ddsrt_exit --- src/ddsrt/include/dds/ddsrt/process.h | 9 +++++++++ src/ddsrt/src/process/posix/process.c | 6 ++++++ src/ddsrt/tests/thread.c | 5 +++-- src/tools/ddsperf/ddsperf.c | 12 ++++++------ 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/ddsrt/include/dds/ddsrt/process.h b/src/ddsrt/include/dds/ddsrt/process.h index 2869a8a370..a9d9be7391 100644 --- a/src/ddsrt/include/dds/ddsrt/process.h +++ b/src/ddsrt/include/dds/ddsrt/process.h @@ -78,6 +78,15 @@ ddsrt_getprocessname(void); DDS_EXPORT void ddsrt_abort(void); +/** + * @brief Performs a normal process termination. + * + * @param status + * @returns The least significant byte of `status` is returned to the parent. + */ +DDS_EXPORT void +ddsrt_exit(int status); + #if defined (__cplusplus) } #endif diff --git a/src/ddsrt/src/process/posix/process.c b/src/ddsrt/src/process/posix/process.c index a44d6f4e35..9455c21a8e 100644 --- a/src/ddsrt/src/process/posix/process.c +++ b/src/ddsrt/src/process/posix/process.c @@ -89,3 +89,9 @@ ddsrt_abort(void) { abort(); } + +void +ddsrt_exit(int status) +{ + exit(status); +} diff --git a/src/ddsrt/tests/thread.c b/src/ddsrt/tests/thread.c index b1df2dbc02..dcd55d125e 100644 --- a/src/ddsrt/tests/thread.c +++ b/src/ddsrt/tests/thread.c @@ -22,6 +22,7 @@ #include "dds/ddsrt/cdtors.h" #include "dds/ddsrt/retcode.h" #include "dds/ddsrt/sync.h" +#include "dds/ddsrt/process.h" #include "dds/ddsrt/threads.h" static int32_t min_fifo_prio = 250; @@ -81,7 +82,7 @@ static uint32_t thread_main(void *ptr) #elif _WIN32 int prio = GetThreadPriority(GetCurrentThread()); if (prio == THREAD_PRIORITY_ERROR_RETURN) - abort(); + ddsrt_abort(); if (prio == attr->schedPriority) { arg->res = 1; } @@ -92,7 +93,7 @@ static uint32_t thread_main(void *ptr) err = pthread_getschedparam(pthread_self(), &policy, &sched); if (err != 0) { - abort(); + ddsrt_abort(); } if (((policy == SCHED_OTHER && attr->schedClass == DDSRT_SCHED_TIMESHARE) || (policy == SCHED_FIFO && attr->schedClass == DDSRT_SCHED_REALTIME)) diff --git a/src/tools/ddsperf/ddsperf.c b/src/tools/ddsperf/ddsperf.c index 8df98517c4..07516a8e75 100644 --- a/src/tools/ddsperf/ddsperf.c +++ b/src/tools/ddsperf/ddsperf.c @@ -391,7 +391,7 @@ static void verrorx (int exitcode, const char *fmt, va_list ap) { vprintf (fmt, ap); fflush (stdout); - exit (exitcode); + ddsrt_exit (exitcode); } static void error2 (const char *fmt, ...) @@ -728,7 +728,7 @@ static uint32_t pubthread (void *varg) { printf ("dds_register_instance failed: %d\n", result); fflush (stdout); - exit (2); + ddsrt_exit (2); } } } @@ -751,7 +751,7 @@ static uint32_t pubthread (void *varg) { printf ("request loan error: %d\n", result); fflush (stdout); - exit (2); + ddsrt_exit (2); } else { @@ -765,7 +765,7 @@ static uint32_t pubthread (void *varg) printf ("write error: %d\n", result); fflush (stdout); if (result != DDS_RETCODE_TIMEOUT) - exit (2); + ddsrt_exit (2); /* retry with original timestamp, it really is just a way of reporting blocking for an exceedingly long time, but do force a fresh time stamp for the next sample */ @@ -976,7 +976,7 @@ static int check_eseq (struct eseq_admin *ea, uint32_t seq, uint32_t keyval, uin if (keyval >= ea->nkeys) { printf ("received key %"PRIu32" >= nkeys %u\n", keyval, ea->nkeys); - exit (3); + ddsrt_exit (3); } ddsrt_mutex_lock (&ea->lock); for (uint32_t i = 0; i < ea->nph; i++) @@ -1970,7 +1970,7 @@ EXAMPLES:\n\ running for 10s\n\ ", argv0, argv0, argv0); fflush (stdout); - exit (3); + ddsrt_exit (3); } struct string_int_map_elem {