--- lbbs/src/main.c 2025/05/27 01:56:16 1.44 +++ lbbs/src/main.c 2025/05/29 09:44:01 1.48 @@ -23,6 +23,7 @@ #include "menu.h" #include "file_loader.h" #include "section_list_loader.h" +#include #include #include #include @@ -55,6 +56,8 @@ int main(int argc, char *argv[]) int std_log_redir = 0; int error_log_redir = 0; FILE *fp; + int ret; + int last_aid; // Parse args for (int i = 1; i < argc; i++) @@ -147,6 +150,14 @@ int main(int argc, char *argv[]) return -2; } + // Check article cache dir + ret = mkdir(VAR_ARTICLE_CACHE_DIR, S_IRWXU | S_IRGRP); + if (ret == -1 && errno != EEXIST) + { + log_error("mkdir(%s) error (%d)\n", VAR_ARTICLE_CACHE_DIR, errno); + goto cleanup; + } + // Initialize data pools if ((fp = fopen(VAR_TRIE_DICT_SHM, "w")) == NULL) { @@ -222,20 +233,35 @@ int main(int argc, char *argv[]) goto cleanup; } - // Load section config - if (append_articles_from_db(0, 1) < 0) + set_last_article_op_log_from_db(); + last_aid = 0; + + // Load section articles + do { - log_error("append_articles_from_db(0, 1) error\n"); - goto cleanup; - } + if ((ret = append_articles_from_db(last_aid + 1, 1, LOAD_ARTICLE_COUNT_LIMIT)) < 0) + { + log_error("append_articles_from_db(0, 1, %d) error\n", LOAD_ARTICLE_COUNT_LIMIT); + goto cleanup; + } - log_std("Debug: loaded %d articles, last_aid = %d\n", article_block_article_count(), article_block_last_aid()); + last_aid = article_block_last_aid(); + } while (ret == LOAD_ARTICLE_COUNT_LIMIT); + + log_std("Initially load %d articles, last_aid = %d\n", article_block_article_count(), article_block_last_aid()); // Set signal handler signal(SIGHUP, sig_hup_handler); signal(SIGCHLD, sig_chld_handler); signal(SIGTERM, sig_term_handler); + // Launch section_list_loader process + if (section_list_loader_launch() < 0) + { + log_error("section_list_loader_launch() error\n"); + goto cleanup; + } + // Initialize socket server net_server(BBS_address, BBS_port);