--- lbbs/src/main.c 2025/11/17 04:23:09 1.76 +++ lbbs/src/main.c 2025/11/18 10:41:14 1.80 @@ -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]) { @@ -79,7 +82,8 @@ int main(int argc, char *argv[]) app_help(); return 0; case 'v': - puts(APP_INFO); + printf("%s\n", APP_INFO); + printf("%s\n", COPYRIGHT_INFO); return 0; default: arg_error(); @@ -138,6 +142,13 @@ 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) @@ -219,7 +230,7 @@ int main(int argc, char *argv[]) if (trie_dict_init(VAR_TRIE_DICT_SHM, TRIE_NODE_PER_POOL) < 0) { - printf("trie_dict_init(%s, %d) error\n", VAR_TRIE_DICT_SHM, TRIE_NODE_PER_POOL); + log_error("trie_dict_init(%s, %d) error\n", VAR_TRIE_DICT_SHM, TRIE_NODE_PER_POOL); goto cleanup; } if (article_block_init(VAR_ARTICLE_BLOCK_SHM, BBS_article_limit_per_section * BBS_max_section / BBS_article_count_per_block) < 0) @@ -350,6 +361,35 @@ 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();