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
commit 8ff98a6b51421d907908f8100544fc0aaf3f4b11 Author: wangjianyu3 <[email protected]> AuthorDate: Wed Oct 22 16:04:09 2025 +0800 system/nxinit: Parse default cpu-specific configs On the basis of init.rc, add default parsing of cpu-specific configs. - /etc/init.d/init.rc - /etc/init.d/init.cpu${CPUID}.rc Refactor function `init_parse_configs()` to parse files from the default path instead of identifying and parsing directories or files, as the functionality is unnecessary. Signed-off-by: wangjianyu3 <[email protected]> --- system/nxinit/init.c | 2 +- system/nxinit/parser.c | 60 ++++++++++++++++++-------------------------------- system/nxinit/parser.h | 3 +-- 3 files changed, 24 insertions(+), 41 deletions(-) diff --git a/system/nxinit/init.c b/system/nxinit/init.c index bd8164a46..e4b62f3d6 100644 --- a/system/nxinit/init.c +++ b/system/nxinit/init.c @@ -179,7 +179,7 @@ int main(int argc, FAR char *argv[]) } } - r = init_parse_config_file(parser, CONFIG_SYSTEM_NXINIT_RC_FILE_PATH); + r = init_parse_configs(parser); if (r < 0) { goto out; diff --git a/system/nxinit/parser.c b/system/nxinit/parser.c index 56e15935c..e4c209598 100644 --- a/system/nxinit/parser.c +++ b/system/nxinit/parser.c @@ -26,6 +26,7 @@ #include <ctype.h> #include <fcntl.h> +#include <sched.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -255,54 +256,37 @@ out: return ret; } -int init_parse_configs(FAR const struct parser_s *parser, - FAR const char *path) +int init_parse_configs(FAR const struct parser_s *parser) { - FAR struct dirent *entry; + FAR const char *path = CONFIG_SYSTEM_NXINIT_RC_FILE_PATH; + FAR const char *ext; char file[PATH_MAX]; - struct stat sb; - FAR DIR *dir; - int ret = 0; - size_t i; + int ret; - if (stat(path, &sb) < 0) + ret = init_parse_config_file(parser, path); + if (ret < 0) { - init_err("Stat %s", path); - return -errno; + return ret; } - if (S_ISDIR(sb.st_mode)) + /* Parse the optional cpu-specific config derived from the rc path, e.g. + * "/etc/init.d/init.rc" -> "/etc/init.d/init.cpu0.rc". + */ + + ext = strrchr(path, '.'); + if (ext == NULL) { - dir = opendir(path); - if (dir == NULL) - { - init_err("Opening directory %s", path); - return -errno; - } + return 0; + } - while ((entry = readdir(dir)) != NULL) - { - if (DIRENT_ISFILE(entry->d_type)) - { - i = strlen(entry->d_name); - if (i >= 3 && !strcmp(entry->d_name + i - 3, ".rc")) - { - snprintf(file, sizeof(file), "%s/%s", path, entry->d_name); - ret = init_parse_config_file(parser, file); - if (ret < 0) - { - break; - } - } - } - } + snprintf(file, sizeof(file), "%.*s.cpu%d%s", + (int)(ext - path), path, sched_getcpu(), ext); - closedir(dir); - } - else if (S_ISREG(sb.st_mode)) + if (access(file, F_OK) < 0) { - ret = init_parse_config_file(parser, path); + init_debug("skipping non-exist file %s", file); + return 0; } - return ret; + return init_parse_config_file(parser, file); } diff --git a/system/nxinit/parser.h b/system/nxinit/parser.h index 37ab10b3f..8229bbd76 100644 --- a/system/nxinit/parser.h +++ b/system/nxinit/parser.h @@ -53,8 +53,7 @@ struct parser_s ****************************************************************************/ int init_parse_arguments(FAR char *buf, bool dup, int argc, FAR char **argv); -int init_parse_configs(FAR const struct parser_s *parser, - FAR const char *path); +int init_parse_configs(FAR const struct parser_s *parser); int init_parse_config_file(FAR const struct parser_s *parser, FAR const char *file); #endif
