Skip to content

Commit 2ec6a9f

Browse files
jimmy-mcelwainDavid-LP99
authored andcommitted
Add RCUTILS_NO_PROCESS_SUPPORT option to build without fork/exec/wait (#50)
Signed-off-by: jimmy-mcelwain <jimmy.mcelwain@motoman.com>
1 parent e40185f commit 2ec6a9f

3 files changed

Lines changed: 32 additions & 11 deletions

File tree

‎CMakeLists.txt‎

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ project(rcutils)
44

55
option(RCUTILS_NO_THREAD_SUPPORT "Disable thread support." OFF)
66
option(RCUTILS_NO_FILESYSTEM "Disable filesystem usage." OFF)
7+
option(RCUTILS_NO_PROCESS_SUPPORT "Disable process support." OFF)
78
option(RCUTILS_AVOID_DYNAMIC_ALLOCATION "Disable dynamic allocations." OFF)
89
option(RCUTILS_NO_64_ATOMIC "Enable alternative support for 64 bits atomic operations in platforms with no native support." OFF)
910
option(RCUTILS_MICROROS "Flag for building micro-ROS." ON)
@@ -567,17 +568,19 @@ if(BUILD_TESTING)
567568
)
568569
endif()
569570

570-
ament_add_gtest(test_process
571-
test/test_process.cpp
572-
)
573-
if(TARGET test_process)
574-
target_link_libraries(test_process
575-
${PROJECT_NAME}
576-
ament_cmake_ros_core::ament_ros_defaults
571+
if(NOT RCUTILS_NO_PROCESS_SUPPORT)
572+
ament_add_gtest(test_process
573+
test/test_process.cpp
577574
)
578-
target_compile_definitions(test_process PRIVATE
579-
"CMAKE_COMMAND=${CMAKE_COMMAND}")
580-
file(TOUCH "${CMAKE_CURRENT_BINARY_DIR}/file with space.txt")
575+
if(TARGET test_process)
576+
target_link_libraries(test_process
577+
${PROJECT_NAME}
578+
ament_cmake_ros_core::ament_ros_defaults
579+
)
580+
target_compile_definitions(test_process PRIVATE
581+
"CMAKE_COMMAND=${CMAKE_COMMAND}")
582+
file(TOUCH "${CMAKE_CURRENT_BINARY_DIR}/file with space.txt")
583+
endif()
581584
endif()
582585

583586
ament_add_gtest(test_logging_custom_env test/test_logging_custom_env.cpp

‎include/rcutils/configuration_flags.h.in‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ extern "C"
88
#endif
99

1010
#cmakedefine RCUTILS_NO_FILESYSTEM
11+
#cmakedefine RCUTILS_NO_PROCESS_SUPPORT
1112
#cmakedefine RCUTILS_AVOID_DYNAMIC_ALLOCATION
1213
#cmakedefine RCUTILS_NO_THREAD_SUPPORT
1314
#cmakedefine RCUTILS_MICROROS

‎src/process.c‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ extern "C"
1717
{
1818
#endif
1919

20+
#include "rcutils/process.h"
21+
2022
#include <errno.h>
2123
#include <stdlib.h>
2224
#include <string.h>
@@ -36,14 +38,15 @@ extern "C"
3638
#pragma warning(pop)
3739
#else
3840
#include <libgen.h>
41+
#ifndef RCUTILS_NO_PROCESS_SUPPORT
3942
#include <sys/wait.h>
43+
#endif
4044
#include <unistd.h>
4145
#endif
4246

4347
#include "rcutils/allocator.h"
4448
#include "rcutils/error_handling.h"
4549
#include "rcutils/join.h"
46-
#include "rcutils/process.h"
4750
#include "rcutils/strdup.h"
4851

4952
int rcutils_get_pid(void)
@@ -234,6 +237,12 @@ rcutils_start_process(
234237
const rcutils_string_array_t * args,
235238
rcutils_allocator_t * allocator)
236239
{
240+
#ifdef RCUTILS_NO_PROCESS_SUPPORT
241+
(void)args;
242+
(void)allocator;
243+
RCUTILS_SET_ERROR_MSG("process support is disabled (RCUTILS_NO_PROCESS_SUPPORT)");
244+
return NULL;
245+
#else
237246
RCUTILS_CHECK_ARGUMENT_FOR_NULL(args, NULL);
238247
RCUTILS_CHECK_ARGUMENT_FOR_NULL(allocator, NULL);
239248
if (args->size < 1) {
@@ -319,6 +328,7 @@ rcutils_start_process(
319328
allocator->deallocate(argv, &allocator->state);
320329
exit(127);
321330
#endif
331+
#endif // RCUTILS_NO_PROCESS_SUPPORT
322332
}
323333

324334
void
@@ -342,6 +352,12 @@ rcutils_process_close(rcutils_process_t * process)
342352
rcutils_ret_t
343353
rcutils_process_wait(const rcutils_process_t * process, int * exit_code)
344354
{
355+
#ifdef RCUTILS_NO_PROCESS_SUPPORT
356+
(void)process;
357+
(void)exit_code;
358+
RCUTILS_SET_ERROR_MSG("process support is disabled (RCUTILS_NO_PROCESS_SUPPORT)");
359+
return RCUTILS_RET_ERROR;
360+
#else
345361
RCUTILS_CHECK_ARGUMENT_FOR_NULL(process, RCUTILS_RET_INVALID_ARGUMENT);
346362

347363
#if defined _WIN32 || defined __CYGWIN__
@@ -382,6 +398,7 @@ rcutils_process_wait(const rcutils_process_t * process, int * exit_code)
382398
#endif
383399

384400
return RCUTILS_RET_OK;
401+
#endif // RCUTILS_NO_PROCESS_SUPPORT
385402
}
386403

387404
#ifdef __cplusplus

0 commit comments

Comments
 (0)