--- lbbs/src/net_server.c 2025/06/17 01:24:21 1.60 +++ lbbs/src/net_server.c 2025/06/29 02:28:02 1.69 @@ -14,38 +14,36 @@ * * ***************************************************************************/ -#define _XOPEN_SOURCE 500 -#define _POSIX_C_SOURCE 200809L -#define _GNU_SOURCE - -#include "net_server.h" -#include "common.h" -#include "bbs_main.h" #include "bbs.h" -#include "log.h" +#include "bbs_main.h" +#include "common.h" +#include "database.h" +#include "file_loader.h" #include "io.h" #include "init.h" -#include "menu.h" -#include "database.h" +#include "log.h" #include "login.h" -#include "file_loader.h" +#include "menu.h" +#include "net_server.h" +#include "section_list.h" #include "section_list_loader.h" #include #include -#include #include #include +#include #include -#include -#include -#include -#include #include -#include -#include +#include #include #include -#include +#include +#include +#include +#include +#include +#include +#include struct process_sockaddr_t { @@ -261,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; @@ -273,6 +271,7 @@ int net_server(const char *hostaddr, in_ if (ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_BINDADDR, hostaddr) < 0 || ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_BINDPORT, &port) < 0 || ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_HOSTKEY, SSH_HOST_KEYFILE) < 0 || + ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_HOSTKEY_ALGORITHMS, "ssh-rsa,rsa-sha2-512,rsa-sha2-256") < 0 || ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_LOG_VERBOSITY, &ssh_log_level) < 0) { log_error("Error setting SSH bind options: %s\n", ssh_get_error(sshbind)); @@ -408,6 +407,8 @@ int net_server(const char *hostaddr, in_ } sd_notifyf(0, "STATUS=Waiting for %d child process to exit", SYS_child_process_count); + + sleep(1); // Sleep for a while to avoid notifying child processes too frequently } if (SYS_conf_reload && !SYS_server_exit) @@ -421,38 +422,18 @@ 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) - { - log_error("OOM: calloc(MENU_SET)\n"); - } - else if (load_menu(p_bbs_menu_new, CONF_MENU) < 0) + if (load_menu(&bbs_menu_new, CONF_MENU) < 0) { - unload_menu(p_bbs_menu_new); - free(p_bbs_menu_new); - p_bbs_menu_new = NULL; - + unload_menu(&bbs_menu_new); log_error("Reload menu failed\n"); } else { - unload_menu(p_bbs_menu); - free(p_bbs_menu); - - p_bbs_menu = p_bbs_menu_new; - p_bbs_menu_new = NULL; - + unload_menu(&bbs_menu); + memcpy(&bbs_menu, &bbs_menu_new, sizeof(bbs_menu_new)); log_common("Reload menu successfully\n"); } - sd_notify(0, "READY=1"); - } - - if (SYS_data_file_reload && !SYS_server_exit) - { - SYS_data_file_reload = 0; - sd_notify(0, "RELOADING=1"); - for (int i = 0; i < data_files_load_startup_count; i++) { if (load_file(data_files_load_startup[i]) < 0) @@ -460,19 +441,19 @@ int net_server(const char *hostaddr, in_ log_error("load_file_mmap(%s) error\n", data_files_load_startup[i]); } } - log_common("Reload data files successfully\n"); - sd_notify(0, "READY=1"); - } - if (SYS_section_list_reload && !SYS_server_exit) - { - SYS_section_list_reload = 0; - - if (section_list_loader_reload() < 0) + // Load section config and gen_ex + if (load_section_config_from_db(1) < 0) + { + log_error("load_section_config_from_db(1) error\n"); + } + else { - log_error("ksection_list_loader_reload() failed\n"); + log_common("Reload section config and gen_ex successfully\n"); } + + sd_notify(0, "READY=1"); } nfds = epoll_wait(epollfd, events, MAX_EVENTS, 100); // 0.1 second @@ -525,7 +506,7 @@ int net_server(const char *hostaddr, in_ port_client = ntohs(sin.sin_port); - log_common("Accept %sconnection from %s:%d\n", (SSH_v2 ? "" : "SSH2 "), hostaddr_client, port_client); + log_common("Accept %s connection from %s:%d\n", (SSH_v2 ? "SSH" : "telnet"), hostaddr_client, port_client); if (SYS_child_process_count - 1 < BBS_max_client) {