--- lbbs/src/main.c 2025/05/30 12:51:00 1.49 +++ lbbs/src/main.c 2025/06/21 02:15:18 1.55 @@ -15,22 +15,22 @@ ***************************************************************************/ #include "bbs.h" -#include "init.h" #include "common.h" -#include "net_server.h" -#include "log.h" +#include "file_loader.h" +#include "init.h" #include "io.h" +#include "log.h" #include "menu.h" -#include "file_loader.h" +#include "net_server.h" #include "section_list_loader.h" #include -#include +#include #include +#include #include #include -#include -#include #include +#include void app_help(void) { @@ -58,6 +58,7 @@ int main(int argc, char *argv[]) FILE *fp; int ret; int last_aid; + struct sigaction act = {0}; // Parse args for (int i = 1; i < argc; i++) @@ -78,7 +79,7 @@ int main(int argc, char *argv[]) app_help(); return 0; case 'v': - puts(app_version); + puts(APP_INFO); return 0; default: arg_error(); @@ -100,7 +101,7 @@ int main(int argc, char *argv[]) } if (strcmp(argv[i] + 2, "version") == 0) { - puts(app_version); + puts(APP_INFO); return 0; } if (strcmp(argv[i] + 2, "display-log") == 0) @@ -137,13 +138,15 @@ int main(int argc, char *argv[]) if ((!daemon) && std_log_redir) { - log_std_redirect(STDERR_FILENO); + log_common_redir(STDERR_FILENO); } if ((!daemon) && error_log_redir) { - log_err_redirect(STDERR_FILENO); + log_error_redir(STDERR_FILENO); } + log_common("Starting %s\n", APP_INFO); + // Load configuration if (load_conf(CONF_BBSD) < 0) { @@ -248,12 +251,27 @@ int main(int argc, char *argv[]) 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()); + log_common("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); + act.sa_handler = sig_hup_handler; + if (sigaction(SIGHUP, &act, NULL) == -1) + { + log_error("set signal action of SIGHUP error: %d\n", errno); + goto cleanup; + } + act.sa_handler = sig_chld_handler; + if (sigaction(SIGCHLD, &act, NULL) == -1) + { + log_error("set signal action of SIGCHLD error: %d\n", errno); + goto cleanup; + } + act.sa_handler = sig_term_handler; + if (sigaction(SIGTERM, &act, NULL) == -1) + { + log_error("set signal action of SIGTERM error: %d\n", errno); + goto cleanup; + } // Launch section_list_loader process if (section_list_loader_launch() < 0) @@ -292,7 +310,7 @@ cleanup: log_error("unlink(%s) error\n", VAR_SECTION_LIST_SHM); } - log_std("Main process exit normally\n"); + log_common("Main process exit normally\n"); return 0; }