--- lbbs/src/net_server.c 2025/06/24 10:01:24 1.65 +++ lbbs/src/net_server.c 2025/06/25 02:49:20 1.67 @@ -25,6 +25,7 @@ #include "login.h" #include "menu.h" #include "net_server.h" +#include "section_list.h" #include "section_list_loader.h" #include #include @@ -258,7 +259,7 @@ int net_server(const char *hostaddr, in_ int nfds, epollfd; siginfo_t siginfo; int sd_notify_stopping = 0; - MENU_SET *p_bbs_menu_new; + MENU_SET bbs_menu_new; int i, j; pid_t pid; int ssh_log_level = SSH_LOG_NOLOG; @@ -419,28 +420,32 @@ int net_server(const char *hostaddr, in_ log_error("Reload conf failed\n"); } - p_bbs_menu_new = calloc(1, sizeof(MENU_SET)); - if (p_bbs_menu_new == NULL) + // acquire rw lock of all sections to avoid conflict with menu reload in data loader process + ret = section_list_rw_lock(NULL); + if (ret < 0) { - log_error("OOM: calloc(MENU_SET)\n"); - } - else if (load_menu(p_bbs_menu_new, CONF_MENU) < 0) - { - unload_menu(p_bbs_menu_new); - free(p_bbs_menu_new); - p_bbs_menu_new = NULL; - - log_error("Reload menu failed\n"); + log_error("section_list_rw_lock(NULL) error\n"); } else { - unload_menu(p_bbs_menu); - free(p_bbs_menu); - - p_bbs_menu = p_bbs_menu_new; - p_bbs_menu_new = NULL; + if (load_menu(&bbs_menu_new, CONF_MENU) < 0) + { + unload_menu(&bbs_menu_new); + log_error("Reload menu failed\n"); + } + else + { + unload_menu(&bbs_menu); + memcpy(&bbs_menu, &bbs_menu_new, sizeof(bbs_menu_new)); + log_common("Reload menu successfully\n"); + } - log_common("Reload menu successfully\n"); + // release rw lock of all sections + ret = section_list_rw_unlock(NULL); + if (ret < 0) + { + log_error("section_list_rw_unlock(NULL) error\n"); + } } sd_notify(0, "READY=1");