Skip to content

Commit 51cdbe2

Browse files
Add RCUTILS_NO_PROCESS_SUPPORT option to build without fork/exec/wait (#50)
Signed-off-by: jimmy-mcelwain <jimmy.mcelwain@motoman.com>
1 parent 8f32223 commit 51cdbe2

3 files changed

Lines changed: 30 additions & 9 deletions

File tree

CMakeLists.txt

Lines changed: 11 additions & 8 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)
@@ -517,14 +518,16 @@ if(BUILD_TESTING)
517518
target_link_libraries(test_cmdline_parser ${PROJECT_NAME})
518519
endif()
519520

520-
ament_add_gtest(test_process
521-
test/test_process.cpp
522-
)
523-
if(TARGET test_process)
524-
target_link_libraries(test_process ${PROJECT_NAME})
525-
target_compile_definitions(test_process PRIVATE
526-
"CMAKE_COMMAND=${CMAKE_COMMAND}")
527-
file(TOUCH "${CMAKE_CURRENT_BINARY_DIR}/file with space.txt")
521+
if(NOT RCUTILS_NO_PROCESS_SUPPORT)
522+
ament_add_gtest(test_process
523+
test/test_process.cpp
524+
)
525+
if(TARGET test_process)
526+
target_link_libraries(test_process ${PROJECT_NAME})
527+
target_compile_definitions(test_process PRIVATE
528+
"CMAKE_COMMAND=${CMAKE_COMMAND}")
529+
file(TOUCH "${CMAKE_CURRENT_BINARY_DIR}/file with space.txt")
530+
endif()
528531
endif()
529532

530533
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)
@@ -233,6 +236,12 @@ rcutils_start_process(
233236
const rcutils_string_array_t * args,
234237
rcutils_allocator_t * allocator)
235238
{
239+
#ifdef RCUTILS_NO_PROCESS_SUPPORT
240+
(void)args;
241+
(void)allocator;
242+
RCUTILS_SET_ERROR_MSG("process support is disabled (RCUTILS_NO_PROCESS_SUPPORT)");
243+
return NULL;
244+
#else
236245
RCUTILS_CHECK_ARGUMENT_FOR_NULL(args, NULL);
237246
RCUTILS_CHECK_ARGUMENT_FOR_NULL(allocator, NULL);
238247
if (args->size < 1) {
@@ -318,6 +327,7 @@ rcutils_start_process(
318327
allocator->deallocate(argv, &allocator->state);
319328
exit(127);
320329
#endif
330+
#endif // RCUTILS_NO_PROCESS_SUPPORT
321331
}
322332

323333
void
@@ -341,6 +351,12 @@ rcutils_process_close(rcutils_process_t * process)
341351
rcutils_ret_t
342352
rcutils_process_wait(const rcutils_process_t * process, int * exit_code)
343353
{
354+
#ifdef RCUTILS_NO_PROCESS_SUPPORT
355+
(void)process;
356+
(void)exit_code;
357+
RCUTILS_SET_ERROR_MSG("process support is disabled (RCUTILS_NO_PROCESS_SUPPORT)");
358+
return RCUTILS_RET_ERROR;
359+
#else
344360
RCUTILS_CHECK_ARGUMENT_FOR_NULL(process, RCUTILS_RET_INVALID_ARGUMENT);
345361

346362
#if defined _WIN32 || defined __CYGWIN__
@@ -381,6 +397,7 @@ rcutils_process_wait(const rcutils_process_t * process, int * exit_code)
381397
#endif
382398

383399
return RCUTILS_RET_OK;
400+
#endif // RCUTILS_NO_PROCESS_SUPPORT
384401
}
385402

386403
#ifdef __cplusplus

0 commit comments

Comments
 (0)