From 58a8cf2cc89f4d41d1a9d6f6a15ddb8087826090 Mon Sep 17 00:00:00 2001 From: jimmy-mcelwain Date: Tue, 30 Jun 2026 10:08:00 -0400 Subject: [PATCH] Add RCUTILS_NO_PROCESS_SUPPORT option to build without fork/exec/wait Signed-off-by: jimmy-mcelwain --- CMakeLists.txt | 19 +++++++++++-------- include/rcutils/configuration_flags.h.in | 1 + src/process.c | 19 ++++++++++++++++++- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8c32a3d9..25ac8531 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,7 @@ project(rcutils) option(RCUTILS_NO_THREAD_SUPPORT "Disable thread support." OFF) option(RCUTILS_NO_FILESYSTEM "Disable filesystem usage." OFF) +option(RCUTILS_NO_PROCESS_SUPPORT "Disable process support." OFF) option(RCUTILS_AVOID_DYNAMIC_ALLOCATION "Disable dynamic allocations." OFF) option(RCUTILS_NO_64_ATOMIC "Enable alternative support for 64 bits atomic operations in platforms with no native support." OFF) option(RCUTILS_MICROROS "Flag for building micro-ROS." ON) @@ -517,14 +518,16 @@ if(BUILD_TESTING) target_link_libraries(test_cmdline_parser ${PROJECT_NAME}) endif() - ament_add_gtest(test_process - test/test_process.cpp - ) - if(TARGET test_process) - target_link_libraries(test_process ${PROJECT_NAME}) - target_compile_definitions(test_process PRIVATE - "CMAKE_COMMAND=${CMAKE_COMMAND}") - file(TOUCH "${CMAKE_CURRENT_BINARY_DIR}/file with space.txt") + if(NOT RCUTILS_NO_PROCESS_SUPPORT) + ament_add_gtest(test_process + test/test_process.cpp + ) + if(TARGET test_process) + target_link_libraries(test_process ${PROJECT_NAME}) + target_compile_definitions(test_process PRIVATE + "CMAKE_COMMAND=${CMAKE_COMMAND}") + file(TOUCH "${CMAKE_CURRENT_BINARY_DIR}/file with space.txt") + endif() endif() ament_add_gtest(test_logging_custom_env test/test_logging_custom_env.cpp diff --git a/include/rcutils/configuration_flags.h.in b/include/rcutils/configuration_flags.h.in index ee58c1d3..a406eb12 100644 --- a/include/rcutils/configuration_flags.h.in +++ b/include/rcutils/configuration_flags.h.in @@ -8,6 +8,7 @@ extern "C" #endif #cmakedefine RCUTILS_NO_FILESYSTEM +#cmakedefine RCUTILS_NO_PROCESS_SUPPORT #cmakedefine RCUTILS_AVOID_DYNAMIC_ALLOCATION #cmakedefine RCUTILS_NO_THREAD_SUPPORT #cmakedefine RCUTILS_MICROROS diff --git a/src/process.c b/src/process.c index 509ef656..2d8717ae 100644 --- a/src/process.c +++ b/src/process.c @@ -17,6 +17,8 @@ extern "C" { #endif +#include "rcutils/process.h" + #include #include #include @@ -36,14 +38,15 @@ extern "C" #pragma warning(pop) #else #include +#ifndef RCUTILS_NO_PROCESS_SUPPORT #include +#endif #include #endif #include "rcutils/allocator.h" #include "rcutils/error_handling.h" #include "rcutils/join.h" -#include "rcutils/process.h" #include "rcutils/strdup.h" int rcutils_get_pid(void) @@ -233,6 +236,12 @@ rcutils_start_process( const rcutils_string_array_t * args, rcutils_allocator_t * allocator) { +#ifdef RCUTILS_NO_PROCESS_SUPPORT + (void)args; + (void)allocator; + RCUTILS_SET_ERROR_MSG("process support is disabled (RCUTILS_NO_PROCESS_SUPPORT)"); + return NULL; +#else RCUTILS_CHECK_ARGUMENT_FOR_NULL(args, NULL); RCUTILS_CHECK_ARGUMENT_FOR_NULL(allocator, NULL); if (args->size < 1) { @@ -318,6 +327,7 @@ rcutils_start_process( allocator->deallocate(argv, &allocator->state); exit(127); #endif +#endif // RCUTILS_NO_PROCESS_SUPPORT } void @@ -341,6 +351,12 @@ rcutils_process_close(rcutils_process_t * process) rcutils_ret_t rcutils_process_wait(const rcutils_process_t * process, int * exit_code) { +#ifdef RCUTILS_NO_PROCESS_SUPPORT + (void)process; + (void)exit_code; + RCUTILS_SET_ERROR_MSG("process support is disabled (RCUTILS_NO_PROCESS_SUPPORT)"); + return RCUTILS_RET_ERROR; +#else RCUTILS_CHECK_ARGUMENT_FOR_NULL(process, RCUTILS_RET_INVALID_ARGUMENT); #if defined _WIN32 || defined __CYGWIN__ @@ -381,6 +397,7 @@ rcutils_process_wait(const rcutils_process_t * process, int * exit_code) #endif return RCUTILS_RET_OK; +#endif // RCUTILS_NO_PROCESS_SUPPORT } #ifdef __cplusplus