--- lbbs/src/main.c 2025/11/17 14:01:13 1.79 +++ lbbs/src/main.c 2025/11/21 08:59:29 1.85 @@ -31,6 +31,7 @@ #include #include #include +#include static void app_help(void) { @@ -59,16 +60,18 @@ int main(int argc, char *argv[]) int ret; int last_aid; struct sigaction act = {0}; + int i; + int j; // Parse args - for (int i = 1; i < argc; i++) + for (i = 1; i < argc; i++) { switch (argv[i][0]) { case '-': if (argv[i][1] != '-') { - for (int j = 1; j < strlen(argv[i]); j++) + for (j = 1; j < strlen(argv[i]); j++) { switch (argv[i][j]) { @@ -139,13 +142,6 @@ int main(int argc, char *argv[]) fprintf(stderr, "chdir(..) error: %d\n", errno); return -1; } -#if defined(__CYGWIN__) - if (chdir("..") < 0) - { - fprintf(stderr, "chdir(..) error: %d\n", errno); - return -1; - } -#endif // Apply the specified locale if (setlocale(LC_ALL, "en_US.UTF-8") == NULL) @@ -177,11 +173,13 @@ int main(int argc, char *argv[]) return -2; } +#ifndef __MSYS__ // Load BWF config if (bwf_load(CONF_BWF) < 0) { return -2; } +#endif // Check article cache dir ret = mkdir(VAR_ARTICLE_CACHE_DIR, 0750); @@ -250,22 +248,17 @@ int main(int argc, char *argv[]) // Load menus if (load_menu(&bbs_menu, CONF_MENU) < 0) { - log_error("load_menu(%s) error\n", CONF_MENU); + log_error("load_menu(bbs_menu) error\n"); goto cleanup; } if (load_menu(&top10_menu, CONF_TOP10_MENU) < 0) { - log_error("load_menu(%s) error\n", CONF_TOP10_MENU); + log_error("load_menu(top10_menu) error\n"); goto cleanup; } top10_menu.allow_exit = 1; // Load data files - if (file_loader_init() < 0) - { - log_error("file_loader_init() error\n"); - goto cleanup; - } for (int i = 0; i < data_files_load_startup_count; i++) { if (load_file(data_files_load_startup[i]) < 0) @@ -358,8 +351,43 @@ int main(int argc, char *argv[]) net_server(BBS_address, BBS_port); cleanup: + // Cleanup loader process if still running + if (SYS_child_process_count > 0) + { + SYS_child_exit = 0; + + if (kill(section_list_loader_pid, SIGTERM) < 0) + { + log_error("Send SIGTERM signal failed (%d)\n", errno); + } + + for(i = 0; SYS_child_exit == 0 && i < 5; i++) + { + sleep(1); // second + } + + if ((ret = waitpid(section_list_loader_pid, NULL, WNOHANG)) < 0) + { + log_error("waitpid(%d) error (%d)\n", section_list_loader_pid, errno); + } + else if (ret == 0) + { + log_common("Force kill section_list_loader process (%d)\n", section_list_loader_pid); + if (kill(section_list_loader_pid, SIGKILL) < 0) + { + log_error("Send SIGKILL signal failed (%d)\n", errno); + } + } + } + // Cleanup loaded data files - file_loader_cleanup(); + for (int i = 0; i < data_files_load_startup_count; i++) + { + if (unload_file(data_files_load_startup[i]) < 0) + { + log_error("unload_file(%s) error\n", data_files_load_startup[i]); + } + } // Cleanup menu unload_menu(&bbs_menu); @@ -371,8 +399,10 @@ cleanup: trie_dict_cleanup(); user_list_pool_cleanup(); +#ifndef __MSYS__ // Cleanup BWF bwf_unload(); +#endif if (unlink(VAR_ARTICLE_BLOCK_SHM) < 0) {