This is an automated email from the ASF dual-hosted git repository.
xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
The following commit(s) were added to refs/heads/master by this push:
new e2d9f5cf1 system/nxinit: Skip comment lines in init.rc.
e2d9f5cf1 is described below
commit e2d9f5cf1d07e1a8b5458b5aab67cf652b0de2cc
Author: Marco Casaroli <[email protected]>
AuthorDate: Wed Oct 21 00:39:01 2026 +0200
system/nxinit: Skip comment lines in init.rc.
In the Android init language a line that starts with "#" (after
optional whitespace) is a comment. NXInit did not know comments: a
comment line before the first section stopped the parse with -EINVAL,
so init ran no action and no service, and a comment line inside an
action became a command named "#". Only board init.rc files that go
through the C preprocessor at build time could hold comments.
Skip a line when its first character that is not whitespace is "#",
in the same place where empty lines are skipped. Add a unit test.
Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Marco Casaroli <[email protected]>
---
system/nxinit/parser.c | 6 ++++--
system/nxinit/test/test_nxinit.c | 1 +
system/nxinit/test/test_nxinit.h | 1 +
system/nxinit/test/test_nxinit_parser.c | 36 +++++++++++++++++++++++++++++++++
4 files changed, 42 insertions(+), 2 deletions(-)
diff --git a/system/nxinit/parser.c b/system/nxinit/parser.c
index e91e51e0d..8f2177cf8 100644
--- a/system/nxinit/parser.c
+++ b/system/nxinit/parser.c
@@ -58,11 +58,13 @@ static int init_parse_config_lines(FAR const struct
parser_s *parser,
*len -= nl - buf;
init_debug("Line %-3zu '%s'", ++*line, buf);
- /* Skip empty lines and lines containing only whitespace */
+ /* Skip empty lines, lines containing only whitespace and comment
+ * lines (the first character that is not whitespace is '#').
+ */
for (ret = 0; buf[ret] && isblank(buf[ret]); ret++);
- if (buf[ret] == '\0')
+ if (buf[ret] == '\0' || buf[ret] == '#')
{
memmove(buf, nl, *len);
continue;
diff --git a/system/nxinit/test/test_nxinit.c b/system/nxinit/test/test_nxinit.c
index cc76ef504..c38cbf3d0 100644
--- a/system/nxinit/test/test_nxinit.c
+++ b/system/nxinit/test/test_nxinit.c
@@ -47,6 +47,7 @@ int main(int argc, FAR char *argv[])
cmocka_unit_test(test_nxinit_parser_arguments_truncate),
cmocka_unit_test(test_nxinit_parser_config_sections),
cmocka_unit_test(test_nxinit_parser_config_skip_blank_lines),
+ cmocka_unit_test(test_nxinit_parser_config_skip_comments),
cmocka_unit_test(test_nxinit_parser_config_unknown_section),
cmocka_unit_test(test_nxinit_parser_config_line_too_long),
cmocka_unit_test(test_nxinit_parser_config_line_crosses_boundary),
diff --git a/system/nxinit/test/test_nxinit.h b/system/nxinit/test/test_nxinit.h
index 2d53e5ae6..c8aa70522 100644
--- a/system/nxinit/test/test_nxinit.h
+++ b/system/nxinit/test/test_nxinit.h
@@ -56,6 +56,7 @@ void test_nxinit_parser_arguments_long_option(FAR void
**state);
void test_nxinit_parser_arguments_truncate(FAR void **state);
void test_nxinit_parser_config_sections(FAR void **state);
void test_nxinit_parser_config_skip_blank_lines(FAR void **state);
+void test_nxinit_parser_config_skip_comments(FAR void **state);
void test_nxinit_parser_config_unknown_section(FAR void **state);
void test_nxinit_parser_config_line_too_long(FAR void **state);
void test_nxinit_parser_config_line_crosses_boundary(FAR void **state);
diff --git a/system/nxinit/test/test_nxinit_parser.c
b/system/nxinit/test/test_nxinit_parser.c
index eda506c4b..8a762f573 100644
--- a/system/nxinit/test/test_nxinit_parser.c
+++ b/system/nxinit/test/test_nxinit_parser.c
@@ -312,6 +312,42 @@ void test_nxinit_parser_config_skip_blank_lines(FAR void
**state)
assert_int_equal(ctx.line_count, 1);
}
+/****************************************************************************
+ * Name: test_nxinit_parser_config_skip_comments
+ *
+ * Description:
+ * Lines whose first character that is not whitespace is '#' are
+ * comments: before the first section, inside a section and at the end.
+ * They do not reach the section's parse callback.
+ ****************************************************************************/
+
+void test_nxinit_parser_config_skip_comments(FAR void **state)
+{
+ struct mock_parser_ctx_s ctx =
+ {
+ 0
+ };
+
+ struct parser_s table[] =
+ {
+ {"secA", mock_parse, mock_check, &ctx},
+ {NULL},
+ };
+
+ int ret;
+
+ ret = parse_content(table,
+ "# first line\n"
+ "secA one\n"
+ " # inside the section\n"
+ " line-a1\n"
+ "#last line\n");
+
+ assert_int_equal(ret, 0);
+ assert_int_equal(ctx.section_count, 1);
+ assert_int_equal(ctx.line_count, 1);
+}
+
/****************************************************************************
* Name: test_nxinit_parser_config_unknown_section
*