|
@@ -631,7 +631,7 @@ static int shell_ini__load_entities_list(sp_dir_t* dir, sp_cfg_shell_ini_t* shel
|
|
|
return rc;
|
|
|
}
|
|
|
|
|
|
-static int shell_ini__load_mod_entity(sp_dir_t* dir, sp_cfg_shell_ini_t* shell, const const char* shell_ini_path, const sp_cfg_start_args_t* args, const CVersionInfo* ver)
|
|
|
+static int shell_ini__load_mod_entity(sp_dir_t* dir, sp_cfg_shell_ini_t* shell, const char* shell_ini_path, const sp_cfg_start_args_t* args, const CVersionInfo* ver)
|
|
|
{
|
|
|
shell->arr_entity = shm_array_make(0, sizeof(sp_cfg_shell_entity_t*));
|
|
|
// BugFix: replace char* with sp_cfg_shell_module_t* [Gifur@2020422]
|
|
@@ -706,12 +706,96 @@ static int shell_ini__load_sysevent(sp_cfg_shell_ini_t* shell, const char* shell
|
|
|
return rc;
|
|
|
}
|
|
|
|
|
|
-static int shell_init__load_startup_list(sp_cfg_shell_ini_t* shell, const char* shell_ini_path)
|
|
|
+
|
|
|
+static int shell_ini__load_entity_list(sp_cfg_shell_ini_t* shell, array_header_t** arr, const char* shell_ini_path, int test_mode)
|
|
|
{
|
|
|
int i;
|
|
|
int rc = 0;
|
|
|
+ char section_name[128] = { "Startup" };
|
|
|
+ if (test_mode) {
|
|
|
+ sp_dbg_debug("test mode: override startup list");
|
|
|
+ strcpy(section_name, "Test");
|
|
|
+ }
|
|
|
+ assert(arr);
|
|
|
+ assert(*arr == NULL);
|
|
|
|
|
|
- i = inifile_read_int(shell_ini_path, "Startup", "Number", 0);
|
|
|
+ i = inifile_read_int(shell_ini_path, section_name, "Number", 0);
|
|
|
+ if (i >= 0) {
|
|
|
+ int n = i;
|
|
|
+ *arr = shm_array_make(i, sizeof(char*));
|
|
|
+ assert(*arr);
|
|
|
+ for (i = 1; i <= n; ++i) {
|
|
|
+ char key[512];
|
|
|
+ char* s;
|
|
|
+ _itoa(i, key, 10);
|
|
|
+ s = inifile_read_str(shell_ini_path, section_name, key, "");
|
|
|
+ if (s) {
|
|
|
+ if (strlen(s)) {
|
|
|
+ int numargs, numchars;
|
|
|
+ char** argv = NULL;
|
|
|
+ char* p;
|
|
|
+ sp_cfg_shell_entity_t* ent;
|
|
|
+ char* cmdline = strchr(s, ' ');
|
|
|
+ if (cmdline) {
|
|
|
+ *cmdline = 0;
|
|
|
+ cmdline++;
|
|
|
+ str_parse_cmdline(cmdline, NULL, NULL, &numargs, &numchars);
|
|
|
+ p = (char*)shm_malloc(numargs * sizeof(char*) + numchars);
|
|
|
+ argv = (char**)p;
|
|
|
+ str_parse_cmdline(cmdline, (char**)p, p + numargs * sizeof(char*), &numargs, &numchars);
|
|
|
+ }
|
|
|
+ ent = find_entity(shell, s);
|
|
|
+ if (ent) {
|
|
|
+ if (cmdline) {
|
|
|
+ //TODO: detect only use entity::cmdline, never seem use of argc and argv [Gifur@2020426]
|
|
|
+ ent->argc = numargs;
|
|
|
+ ent->argv = argv;
|
|
|
+ if (numargs) {
|
|
|
+ ent->cmdline = shm_strdup(cmdline);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ SHM_ARRAY_PUSH(*arr, sp_cfg_shell_entity_t*) = ent;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ sp_dbg_warn("read %s failed! find startup list [%s] defined entity [%s] fail!", section_name, key, s);
|
|
|
+ rc = Error_Param;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ sp_dbg_warn("read %s failed! startup list [%s] define invalid!", section_name, key);
|
|
|
+ rc = Error_Param;
|
|
|
+ }
|
|
|
+ toolkit_free(s);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ sp_dbg_warn("read %s failed! startup list [%s] define invalid!", section_name, key);
|
|
|
+ rc = Error_Param;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (rc != 0)
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ sp_dbg_warn("read %s failed! startup number invalid!", section_name);
|
|
|
+ rc = Error_Param;
|
|
|
+ }
|
|
|
+
|
|
|
+ return rc;
|
|
|
+}
|
|
|
+
|
|
|
+/*
|
|
|
+static int shell_ini__load_bootup_entities(sp_cfg_shell_ini_t* shell, const char* shell_ini_path, int test_mode)
|
|
|
+{
|
|
|
+ int i;
|
|
|
+ int rc = 0;
|
|
|
+ char section_name[128] = { "Startup" };
|
|
|
+ if (test_mode) {
|
|
|
+ sp_dbg_debug("test mode: override startup list");
|
|
|
+ strcpy(section_name, "Test");
|
|
|
+ }
|
|
|
+
|
|
|
+ i = inifile_read_int(shell_ini_path, section_name, "Number", 0);
|
|
|
if (i >= 0) {
|
|
|
int n = i;
|
|
|
shell->arr_startlist = shm_array_make(i, sizeof(char*));
|
|
@@ -719,7 +803,7 @@ static int shell_init__load_startup_list(sp_cfg_shell_ini_t* shell, const char*
|
|
|
char key[512];
|
|
|
char* s;
|
|
|
_itoa(i, key, 10);
|
|
|
- s = inifile_read_str(shell_ini_path, "Startup", key, "");
|
|
|
+ s = inifile_read_str(shell_ini_path, section_name, key, "");
|
|
|
if (s) {
|
|
|
if (strlen(s)) {
|
|
|
int numargs, numchars;
|
|
@@ -748,18 +832,18 @@ static int shell_init__load_startup_list(sp_cfg_shell_ini_t* shell, const char*
|
|
|
SHM_ARRAY_PUSH(shell->arr_startlist, sp_cfg_shell_entity_t*) = ent;
|
|
|
}
|
|
|
else {
|
|
|
- sp_dbg_warn("read Startup failed! find startup list [%s] defined entity [%s] fail!", key, s);
|
|
|
+ sp_dbg_warn("read %s failed! find startup list [%s] defined entity [%s] fail!", section_name, key, s);
|
|
|
rc = Error_Param;
|
|
|
}
|
|
|
}
|
|
|
else {
|
|
|
- sp_dbg_warn("read Startup failed! startup list [%s] define invalid!", key);
|
|
|
+ sp_dbg_warn("read %s failed! startup list [%s] define invalid!", section_name, key);
|
|
|
rc = Error_Param;
|
|
|
}
|
|
|
toolkit_free(s);
|
|
|
}
|
|
|
else {
|
|
|
- sp_dbg_warn("read Startup failed! startup list [%s] define invalid!", key);
|
|
|
+ sp_dbg_warn("read %s failed! startup list [%s] define invalid!", section_name, key);
|
|
|
rc = Error_Param;
|
|
|
}
|
|
|
|
|
@@ -768,12 +852,18 @@ static int shell_init__load_startup_list(sp_cfg_shell_ini_t* shell, const char*
|
|
|
}
|
|
|
}
|
|
|
else {
|
|
|
- sp_dbg_warn("read Startup failed! startup number invalid!");
|
|
|
+ sp_dbg_warn("read %s failed! startup number invalid!", section_name);
|
|
|
rc = Error_Param;
|
|
|
}
|
|
|
|
|
|
return rc;
|
|
|
}
|
|
|
+*/
|
|
|
+
|
|
|
+static int shell_init__load_startup_list(sp_cfg_shell_ini_t* shell, const char* shell_ini_path)
|
|
|
+{
|
|
|
+ return shell_ini__load_entity_list(shell, &shell->arr_startlist, shell_ini_path, 0);
|
|
|
+}
|
|
|
|
|
|
static inline int shell_ini__load_software_version(sp_cfg_shell_ini_t* shell, const char* shell_ini_path, const char* shell_runinfo_file)
|
|
|
{
|
|
@@ -888,8 +978,20 @@ static int load_shell_ini(sp_dir_t *dir, sp_cfg_shell_ini_t *shell, const sp_cfg
|
|
|
if (rc != 0)
|
|
|
return rc;
|
|
|
}
|
|
|
- else if ((rc = shell_init__load_startup_list(shell, shell_ini_path)) != 0) {
|
|
|
- return rc;
|
|
|
+ else {
|
|
|
+ if ((rc = shell_init__load_startup_list(shell, shell_ini_path)) != 0) {
|
|
|
+ return rc;
|
|
|
+ }
|
|
|
+ if (args->test_mode) {
|
|
|
+ array_header_t* arr = NULL;
|
|
|
+ if ((rc = shell_ini__load_entity_list(shell, &arr, shell_ini_path, 1)) != 0)
|
|
|
+ return rc;
|
|
|
+ if (arr && arr->nelts > 0) {
|
|
|
+ sp_dbg_info("append additional test entity: %d", arr->nelts);
|
|
|
+ shm_array_cat(shell->arr_startlist, arr);
|
|
|
+ }
|
|
|
+ shm_array_free(arr);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
shell->shell_debug_level = args->debug_mode ? 2 : shell_ini__load_debug_level(shell_ini_path, "SpShell");
|
|
@@ -937,6 +1039,8 @@ static int load_shell_ini(sp_dir_t *dir, sp_cfg_shell_ini_t *shell, const sp_cfg
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ shell->shell_state = (rc == 0) ? 1 /*booting*/: 3 /*breakdown*/;
|
|
|
+
|
|
|
return rc;
|
|
|
}
|
|
|
|