Skip to content

Commit 21a3041

Browse files
system/init: Handle trailing file '\0'
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 <[email protected]>
1 parent 48557d3 commit 21a3041

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

system/init/parser.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ int init_parse_config_file(FAR const struct parser_s *parser,
178178
*(nl++) = '\0';
179179
n -= nl - buf;
180180
init_debug("line %3d: '%s'", ++line, buf);
181+
if (*buf == '\0')
182+
{
183+
continue;
184+
}
181185

182186
for (ret = 0; parser[ret].key; ret++)
183187
{

0 commit comments

Comments
 (0)