--- lbbs/src/bbs_main.c 2025/11/02 08:13:50 1.96 +++ lbbs/src/bbs_main.c 2025/11/20 09:02:46 1.111 @@ -1,24 +1,21 @@ -/*************************************************************************** - bbs_main.c - description - ------------------- - Copyright : (C) 2004-2025 by Leaflet - Email : leaflet@leafok.com - ***************************************************************************/ - -/*************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 3 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * bbs_main + * - entry and major procedures of user interactive access + * + * Copyright (C) 2004-2025 Leaflet + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif #include "article_favor.h" #include "article_view_log.h" #include "bbs.h" #include "bbs_cmd.h" #include "bbs_main.h" +#include "bwf.h" #include "common.h" #include "database.h" #include "editor.h" @@ -29,9 +26,11 @@ #include "screen.h" #include "section_list.h" #include "section_list_display.h" +#include "str_process.h" #include "trie_dict.h" #include "user_list.h" #include "user_priv.h" +#include #include #include #include @@ -39,9 +38,18 @@ #include #include +static void child_proc_sig_usr1_handler(int i) +{ + // Restart log + if (log_restart() < 0) + { + log_error("Restart logging failed\n"); + } +} + int bbs_info() { - prints("欢迎光临 \033[1;33m%s \033[32m[%s] \033[37m( %s )\033[m\r\n", + prints("\r\n欢迎光临 \033[1;33m%s \033[32m[%s] \033[37m(%s)\033[m\r\n", BBS_name, BBS_server, APP_INFO); return iflush(); @@ -86,7 +94,7 @@ int bbs_welcome(void) "\033[32m目前上站人数 [\033[36m%d/%d\033[32m] " "匿名游客[\033[36m%d\033[32m] " "注册用户数[\033[36m%d/%d\033[32m]\r\n" - "从 [\033[36m%s\033[32m] 起,累计访问人次:[\033[36m%d\033[32m]\033[m\r\n", + "从 [\033[36m%s\033[32m] 起,累计访问人次: [\033[36m%d\033[32m]\033[m\r\n", BBS_name, u_online, BBS_max_client, u_anonymous, u_total, BBS_max_user_count, BBS_start_dt, u_login_count); @@ -146,6 +154,9 @@ int bbs_center() if (ch != KEY_NULL && ch != KEY_TIMEOUT) { BBS_last_access_tm = time(NULL); +#ifdef _DEBUG + log_error("Debug: BBS_last_access_tm is updated\n"); +#endif } if (bbs_menu.choose_step == 0 && time(NULL) - t_last_action >= 10) @@ -169,7 +180,7 @@ int bbs_center() log_error("KEY_NULL\n"); return 0; case KEY_TIMEOUT: - if (time(NULL) - BBS_last_access_tm >= MAX_DELAY_TIME) + if (time(NULL) - BBS_last_access_tm >= BBS_max_user_idle_time) { log_error("User input timeout\n"); return 0; @@ -208,31 +219,56 @@ int bbs_charset_select() int ch; snprintf(msg, sizeof(msg), - "\rChoose character set in 5 seconds [UTF-8, GBK]: [U/g]"); + "\rChoose character set in 5 seconds, (U)UTF-8, (G)GBK [U]: "); while (!SYS_server_exit) { ch = press_any_key_ex(msg, 5); - switch (ch) + switch (toupper(ch)) { case KEY_NULL: return -1; case KEY_TIMEOUT: case CR: - case 'u': case 'U': - return 0; - case 'g': + break; case 'G': if (io_conv_init("GBK") < 0) { log_error("io_conv_init(%s) error\n", "GBK"); return -1; } - return 0; + break; default: continue; } + + break; + } + + snprintf(msg, sizeof(msg), + "\r请在5秒内选择宽字符显示规则, (V)变宽, (F)定宽? [V]: "); + + while (!SYS_server_exit) + { + ch = press_any_key_ex(msg, 5); + switch (toupper(ch)) + { + case KEY_NULL: + return -1; + case KEY_TIMEOUT: + case CR: + case 'V': + UTF8_fixed_width = 0; + break; + case 'F': + UTF8_fixed_width = 1; + break; + default: + continue; + } + + break; } return 0; @@ -256,6 +292,12 @@ int bbs_main() log_error("set signal action of SIGCHLD error: %d\n", errno); goto cleanup; } + act.sa_handler = child_proc_sig_usr1_handler; + if (sigaction(SIGUSR1, &act, NULL) == -1) + { + log_error("set signal action of SIGUSR1 error: %d\n", errno); + goto cleanup; + } // Set data pools in shared memory readonly if (set_trie_dict_shm_readonly() < 0) @@ -270,10 +312,12 @@ int bbs_main() { goto cleanup; } +#ifdef HAVE_SYSTEM_V if (set_user_list_pool_shm_readonly() < 0) { goto cleanup; } +#endif // Load menu in shared memory if (set_menu_shm_readonly(&bbs_menu) < 0) @@ -282,16 +326,19 @@ int bbs_main() } // Set default charset - if (io_conv_init(BBS_DEFAULT_CHARSET) < 0) + if (io_conv_init(BBS_default_charset) < 0) { - log_error("io_conv_init(%s) error\n", BBS_DEFAULT_CHARSET); + log_error("io_conv_init(%s) error\n", BBS_default_charset); goto cleanup; } set_input_echo(0); // Set user charset - bbs_charset_select(); + if (bbs_charset_select() < 0) + { + goto cleanup; + } // System info if (bbs_info() < 0) @@ -323,7 +370,7 @@ int bbs_main() log_error("article_view_log_load() error\n"); goto cleanup; } - + // Load article view log if (article_view_log_load(BBS_priv.uid, &BBS_article_view_log, 0) < 0) { @@ -397,5 +444,8 @@ cleanup: detach_article_block_shm(); detach_trie_dict_shm(); + // Cleanup BWF + bwf_unload(); + return 0; }