reap_process() referenced an undeclared identifier 'wtatus' on
the WIFSIGNALED branch (typo of 'wstatus'). Some toolchains then
flagged a -Wmaybe-uninitialized on the surrounding wstatus use.
Correct the typo so WIFSIGNALED/WTERMSIG operate on the actual
wstatus value returned by waitpid().
Signed-off-by: fangpeina <fangpeina@xiaomi.com>
action.c uses clock_gettime(CLOCK_MONOTONIC, ...) but did not
pull in <nuttx/clock.h> directly, which fails to build on
configurations where the header is not transitively included.
Add the missing #include.
Signed-off-by: fangpeina <fangpeina@xiaomi.com>
When ETC_ROMFS is disabled to reduce the bin size, we can provide the init.rc
file via a pseudo-file in the boards/vendor directory. For example:
- CONFIG_ETC_ROMFS=n
- CONFIG_PSEUDOFS_FILE=y
- CONFIG_DISABLE_PSEUDOFS_OPERATIONS=n
```C
FAR const char *init_rc =
"on init\n"
" start console\n";
"service console sh\n"
" restart_period 100\n";
int fd = open("/etc/init.d/init.rc", O_WRONLY | O_CREAT);
/* ... */
ssize_t n = write(fd, init_rc, strlen(init_rc) + 1);
/* ... */
close(fd);
```
The last character '\0' in the file content will be treated as a new line,
and the number of parsed parameters will be zero (abnormal, there should be
at least one keyword).
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
Empty lines in init.rc caused parsing to fail with -EINVAL because init_parse_arguments() returns 0 for empty strings, triggering the 'argc < 1' error path in init_action_parse() and accessing uninitialized argv[0] in init_service_parse().
Fix by skipping empty lines and lines containing only whitespace before attempting to match section keywords or calling parser callbacks.
Fixesapache/nuttx-apps#3513
Signed-off-by: hanzj <hanzhijian@zepp.com>
Add a Rust make helper that collects crate input files, and use it for
the Rust hello and slint examples.
This makes the generated Rust static libraries depend on the crate
sources, manifests, build scripts. Hook the libraries into both context
and all, so re-running make after editing Rust inputs rebuilds the crate.
Signed-off-by: Shoji Tokunaga <toku@mac.com>
Mirror of microros_pub for the receive direction. Creates a node,
subscribes to /nuttx_sub with std_msgs/Int32, drives an rclc_executor
spin loop, and prints each received value. Exercises the new
rclc_executor + subscription callback path on top of the
microros_transport library shipped in apps/system/microros.
Validates the NuttX-native transport in the agent->client direction
end-to-end against a micro-ROS agent + ros2 topic pub on the host.
Signed-off-by: Arjav Patel <arjav1528@gmail.com>
Add tests for popen()/pclose() and dpopen()/dpclose() that work in
both shell (NSH) and no-shell (direct posix_spawnp) modes. The test
binary doubles as its own target via the --echo sub-command.
Tests:
1-4: popen - basic read, multi-arg, pclose, invalid mode
5-7: dpopen - basic read, multi-arg, dpclose
Signed-off-by: cuiziwei <cuiziwei@xiaomi.com>
When NSH_LIBRARY is not available, dpopen()/popen() can still execute
commands by splitting the command string by whitespace and calling
posix_spawnp() directly. Shell syntax (pipes, redirects, globbing)
is not supported in this mode.
Add CONFIG_SYSTEM_POPEN_MAXARGUMENTS (default 7) to control the
argv array size for the no-shell path.
Remove the hard dependency on NSH_LIBRARY from SYSTEM_POPEN so the
feature can be used in minimal configurations without a shell.
Signed-off-by: cuiziwei <cuiziwei@xiaomi.com>
Add dpopen()/dpclose() as the descriptor-based counterpart of
popen()/pclose(), analogous to how dprintf() relates to fprintf().
dpopen() returns a raw file descriptor instead of a FILE stream,
avoiding the stdio.h dependency for callers that only need an fd.
Refactor popen() as a thin wrapper: dpopen() + fdopen() + FILE
container. All pipe creation and process spawning logic now lives
in dpopen.c.
Also remove the hard dependency on NSH_LIBRARY from SYSTEM_POPEN.
When NSH is available, commands are executed through sh -c with full
shell syntax support. When NSH is not available, commands are split
by whitespace and executed directly via posix_spawnp().
Add CONFIG_SYSTEM_POPEN_MAXARGUMENTS (default 7) to control the
argv array size for the no-shell path.
Signed-off-by: cuiziwei <cuiziwei@xiaomi.com>
Add aarch64 Rust target specs for NuttX, including a Mach-O variant
for macOS sim builds. Use the NuttX custom targets instead of
aarch64-apple-darwin so Rust std is built with target_os=nuttx while
still producing link-compatible objects for sim.
Signed-off-by: Shoji Tokunaga <toku@mac.com>
End-to-end exercise of the micro-ROS stack on NuttX: calls
microros_transport_init() to register the configured backend,
brings up rclc_support / node / publisher, publishes 30
std_msgs/Int32 messages on /nuttx_pub at 1 Hz, then tears the
stack down cleanly.
The example's Make.defs adds $(APPDIR)/system/microros/transport
to its own CFLAGS rather than the system/microros Make.defs, so
the transport-glue header path is not pushed into the global
search path for unrelated apps.
Serves as the smoke test for the transport layer and as a template
for downstream publisher apps.
Signed-off-by: Arjav Patel <arjav1528@gmail.com>
Micro XRCE-DDS expects the application to supply open/close/write/read
callbacks for the wire transport. Add a single dispatcher that
registers the selected backend via rmw_uros_set_custom_transport(),
plus two backends:
transport/microros_transport_udp.c
BSD-socket UDP backend. Opens an AF_INET/SOCK_DGRAM socket,
resolves CONFIG_MICROROS_AGENT_IP/PORT, connect()s it, and uses
send/recv. The socket fd is stashed in uxrCustomTransport->args
so no module-level state is needed.
transport/microros_transport_serial.c
termios serial backend. Opens CONFIG_MICROROS_SERIAL_DEVICE with
O_RDWR|O_NOCTTY|O_CLOEXEC, switches to raw 8N1 at
CONFIG_MICROROS_SERIAL_BAUD, and uses poll/read/write. Fd is
again stashed in uxrCustomTransport->args.
Both backends are mutually exclusive at compile time via Kconfig;
the dispatcher selects which set of callbacks to register. Wired
into both the legacy Make build (CSRCS in system/microros/Makefile)
and the CMake build (separate microros_transport static library
with the transport directory only exposed to its INTERFACE).
Signed-off-by: Arjav Patel <arjav1528@gmail.com>
libmicroros is installed by colcon under include/<pkg>/<pkg>/file.h
for ament-packaged headers (e.g. rcl, rmw, rosidl) and the flat
include/<pkg>/file.h for a few others (e.g. rclc). A single
-I include/ therefore resolves <rclc/rclc.h> but not <rcl/rcl.h>.
Enumerate every immediate subdirectory of include/ in addition to
include/ itself so both layouts resolve.
Switch the library hand-off from LDLIBS to EXTRA_LIBS. The sim
target's final link pulls EXTRA_LIBS, not LDLIBS, so the previous
form left rcl/rclc/rcutils symbols unresolved.
Signed-off-by: Arjav Patel <arjav1528@gmail.com>
micro_ros_lib/toolchain.cmake.in initialised C and CXX flags with
-D'__attribute__(x)=' to silence GCC attributes the upstream ament
build is not aware of. The strip also removed __gnu_inline__ and
__always_inline__ from NuttX's libc string.h inlines, so each
micro-ROS translation unit emitted external definitions of strcmp,
strcpy, strlen and friends. Sim final link then failed with ~50
multiple-definition errors.
Drop the define from both flag init lines so the attributes survive
and the inlines collapse as intended.
Signed-off-by: Arjav Patel <arjav1528@gmail.com>
Add SHA224 hash test using results generated from sha224sum.
Modify "huge block" testing since allocating 600KB to hash all
at once fails on most microcontrollers. Instead allocate a
smaller block and pass into syshash_update() enough times to
hash 600KB of data.
Signed-off-by: Peter Barada <peter.barada@gmail.com>
Fix a missing space in the Kconfig help text for SYSTEM_LZF:
'Enable theLZF' → 'Enable the LZF'.
Signed-off-by: Zepp-Hanzj <Zepp-Hanzj@users.noreply.github.com>
Signed-off-by: hanzj <hanzjian@zepp.com>
Use configured key, value, and filename limits while loading and saving settings storage data.
The text backend now builds backup filenames with a sized buffer and bounded formatting, and both text and binary loading reject keys or string values that are not terminated within their configured field sizes. This completes #3109 without changing the storage formats.
Signed-off-by: Nightt <87569709+nightt5879@users.noreply.github.com>
Use strnlen() for public key, value, and storage path length checks so user-provided settings strings are validated against the configured maximum sizes before they are scanned.
Use bounded key comparisons and strlcpy() for fixed-size settings fields. This addresses part of #3109 without changing the settings API or storage formats.
Signed-off-by: Nightt <87569709+nightt5879@users.noreply.github.com>
Fix spelling errors in QuickJS Kconfig and nettest source:
* "distable" -> "disable" in INTERPRETERS_QUICKJS_NONE description
* "destory" -> "destroy" in INTERPRETERS_QUICKJS_EXT_HOOK option
and help text (2 occurrences)
* "err_destory" -> "err_destroy" label in nettest_tcpserver.c
(3 occurrences: 2 goto targets and 1 label definition)
These are cosmetic fixes with no functional change.
Signed-off-by: hanzj <hanzjian@zepp.com>
Without debug enabled, the code would not compile due to checking
`WIFEXITED(wstatus)` when `wstatus` was uninitialized.
Signed-off-by: Matteo Golin <matteo.golin@gmail.com>
The init.rc file path is now configurable to allow users to choose where
to put the startup script. This is useful for devices that mount
external media to a special directory like `/sd`.
Signed-off-by: Matteo Golin <matteo.golin@gmail.com>
Would not compile due to typo in macro describing service name length.
Change ensures that:
* We do not malloc an extra `len` bytes since this is already allocated
as part of the struct
* The name string always has a null terminating byte
Signed-off-by: Matteo Golin <matteo.golin@gmail.com>
FIx
Add support for the reboot_on_failure option to the service.
When the execution of a command within a certain action fails (returning
a non-zero status code), NxInit will continue to execute subsequent commands or
actions and will not proactively terminate the startup process. To implement
the functionality of "terminating the startup process after a command
execution fails", there are two methods:
a. Execute conditional statements (if/then/else/fi) via exec command,
but this depends on sh:
```
on init
exec -- set +e; \
mount -t fatfs /dev/data /data ; \
if [ $? -ne 0 ] ; \
then \
echo "failed" ; \
reboot ; \
else \
echo "succeed" ; \
fi;
```
b. Via service's oneshot + reboot_on_failure:
/* Although the example uses sh, it does not depend on it and can be
* replaced with any other Builtin Apps.
*/
```
on init
exec_start mkdir_tmp
ls /tmp
service mkdir_tmp sh -c "mkdir /tmp"
reboot_on_failure 0
oneshot
```
Test
- RC
service console sh
class core
override
> reboot_on_failure 0
restart_period 10000
- Runtime
[ 0.150000] [ 3] [ 0] init_main: == Dump Services ==
...
[ 0.170000] [ 3] [ 0] init_main: Service 0x40486ea0 name 'console' path 'sh'
[ 0.170000] [ 3] [ 0] init_main: pid: 0
[ 0.170000] [ 3] [ 0] init_main: arguments:
[ 0.170000] [ 3] [ 0] init_main: [0] 'service'
[ 0.170000] [ 3] [ 0] init_main: [1] 'console'
[ 0.170000] [ 3] [ 0] init_main: [2] 'sh'
[ 0.170000] [ 3] [ 0] init_main: classes:
[ 0.170000] [ 3] [ 0] init_main: 'core'
[ 0.170000] [ 3] [ 0] init_main: restart_period: 10000
> [ 0.170000] [ 3] [ 0] init_main: reboot_on_failure: 0
[ 0.170000] [ 3] [ 0] init_main: flags:
[ 0.170000] [ 3] [ 0] init_main: 'override'
...
[ 0.380000] [ 3] [ 0] init_main: started service 'console' pid 4
...
nsh> kill -9 4
[ 8.060000] [ 3] [ 0] init_main: service 'console' flag 0x20000004 add 0x4
[ 8.060000] [ 3] [ 0] init_main: -flag 'running'
[ 8.060000] [ 3] [ 0] init_main: service 'console' flag 0x20000000 add 0x8
[ 8.060000] [ 3] [ 0] init_main: +flag 'restarting'
> [ 8.060000] [ 3] [ 0] init_main: Error reboot on failure of service 'console' reason 0
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
Format: exec_start <service>
Start the specified service and pause the processing of any additional
initialization commands until the service completes its execution. This
command operates similarly to the `exec` command; the key difference is
that it utilizes an existing service definition rather than requiring
the `exec` argument vector.
This feature is particularly intended for use with the `reboot_on_failure`
built-in command to perform all types of essential checks during system boot.
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
This component (abbreviated as "NxInit") is specifically developed
for NuttX and intended for system initialization. While we have
adopted the Android Init Language among various syntax options,
this is a brand-new implementation—it is not a port or variant of
Android Init.
Refer to the implementation of Android Init Language, consists of five broad
classes of statements: Actions, Commands, Services, Options, and Imports.
Actions support two types of triggers: event and action. Action triggers also
support runtime triggering. Services support lifecycle management, including
automatic restart (at specified intervals), and starting/stopping
individually or by class. Import supports files or directories, and we may
add a static method in the future. The following are some differences:
1. The Android Init Language treats lines starting with `#` as comments,
while we use a preprocessor to handle comments.
2. For action commands, we can omit "exec" and directly execute
built-in apps or nsh builtins.
3. Regarding the property service, users can either adapt it by self or
directly use the preset NVS-based properties.
4. Only part of standard action commands and service options are
implemented currlently.
To enable system/nxinit:
```diff
-CONFIG_INIT_ENTRYPOINT="nsh_main"
+CONFIG_INIT_ENTRYPOINT="init_main"
+CONFIG_SYSTEM_NXINIT=y
```
For format and additional details, refer to:
https://android.googlesource.com/platform/system/core/+/
master/init/README.md
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
When stdout is broken (e.g. PTY master closed), nsh_catfile could spin
forever: write() fails, error logging generates syslog output to
/dev/log, next read() picks it up, write() fails again, ad infinitum.
Two fixes:
- nsh_console: drop the _err() in nsh_consolewrite entirely. The risk
is errno-agnostic (EPIPE / EIO / ENOSPC / ...): any failure logged
here can be re-injected by the syslog backend when OUTFD is bound to
/dev/log. Callers already see the failure via the negative return
value and errno, so on-failure logging at this layer is redundant.
- nsh_fsutils: jump straight from the inner write-failure path to a
single errout: cleanup label instead of using a two-level break +
flag check, so a failed write cannot fall through to another read().
Assisted-by: GitHubCopilot:claude-4.7-opus
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
POSIX specifies strcasecmp/strncasecmp in <strings.h>, not <string.h>.
On NuttX (and other strict POSIX environments) rcutils/src/strcasecmp.c
only includes <string.h>, causing an implicit-declaration error for
strcasecmp when cross-compiling.
Patch 0003 adds #include <strings.h> guarded by !_WIN32, matching the
existing Windows/POSIX split in the file.
Signed-off-by: Arjav Patel <arjav1528@gmail.com>
Add -D__NuttX__ to CMAKE_C_FLAGS_INIT and CMAKE_CXX_FLAGS_INIT in
toolchain.cmake.in so that all cross-compiled micro-ROS packages see the
NuttX target macro. Without this, rcutils/src/process.c follows the
__linux__ branch and references program_invocation_name, a glibc-only
extension absent from the NuttX C library.
Pair with 0002-rcutils-process-nuttx-compat.patch which additionally
guards the linux branch with !defined(__NuttX__), ensuring the embedded
fallback path is taken on NuttX even if the host compiler defines any
linux-flavoured macros.
Signed-off-by: Arjav Patel <arjav1528@gmail.com>
Mirror the Makefile build pipeline into CMakeLists.txt using
ExternalProject_Add so that CMake-based NuttX builds (cmake --build)
can also produce libmicroros.a. The external project delegates to the
existing Makefile targets, then exposes the result via an IMPORTED
STATIC library target with correct INTERFACE_INCLUDE_DIRECTORIES.
Signed-off-by: Arjav Patel <arjav1528@gmail.com>
NuttX defines DIR as a struct type in dirent.h. The rcutils filesystem
source has a bare typedef int DIR that triggers a redefinition error when
NuttX system headers are on the include path. Guard it with #ifndef DIR
so the typedef is skipped when the type is already defined.
Applied automatically during the micro_ros_src/src fetch step with
patch -p1 --forward --ignore-whitespace ... || true
so the build is idempotent if the upstream ever merges a fix.
Signed-off-by: Arjav Patel <arjav1528@gmail.com>
When CONFIG_SYSTEM_MICROROS=y, add the prebuilt libmicroros.a to LDLIBS
and the colcon-installed include/ tree to CFLAGS/CXXFLAGS so that any
application in nuttx-apps can include micro-ROS headers and link against
the library without extra flags.
Signed-off-by: Arjav Patel <arjav1528@gmail.com>
Add toolchain.cmake.in and include_override/assert.h for the colcon
cross-build. Key differences from the old robertobucher port:
- Drop -DCLOCK_MONOTONIC=0: NuttX defines CLOCK_MONOTONIC=1 and
the override broke nanosleep() on newer kernels.
- CMAKE_SYSTEM_PROCESSOR is a placeholder substituted per-arch.
- include_override/assert.h works around the rosidl NDEBUG issue
(https://github.com/ros2/rosidl/pull/739).
Signed-off-by: Arjav Patel <arjav1528@gmail.com>