--- lbbs/src/data_file_mgr.c 2025/11/07 13:56:11 1.1 +++ lbbs/src/data_file_mgr.c 2025/12/19 06:16:26 1.5 @@ -6,6 +6,10 @@ * Copyright (C) 2004-2025 Leaflet */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include "bbs.h" #include "bbs_cmd.h" #include "common.h" @@ -42,6 +46,8 @@ static const DATA_FILE_ITEM data_file_li {"活动看板", DATA_ACTIVE_BOARD}, {"浏览帮助", DATA_READ_HELP}, {"编辑帮助", DATA_EDITOR_HELP}, + {"敏感词表", CONF_BWF}, + {"穿梭配置", CONF_BBSNET}, }; static const int data_file_cnt = sizeof(data_file_list) / sizeof(DATA_FILE_ITEM); @@ -84,13 +90,13 @@ int data_file_mgr(void *param) if ((fd = open(path, O_RDONLY)) < 0 && (fd = open(data_file_list[i].path, O_RDONLY)) < 0) { - log_error("open(%s) error (%d)\n", data_file_list[i].path, errno); + log_error("open(%s) error (%d)", data_file_list[i].path, errno); return REDRAW; } if (fstat(fd, &sb) < 0) { - log_error("fstat(fd) error (%d)\n", errno); + log_error("fstat(fd) error (%d)", errno); goto cleanup; } @@ -98,13 +104,13 @@ int data_file_mgr(void *param) p_data = mmap(NULL, len_data, PROT_READ, MAP_SHARED, fd, 0L); if (p_data == MAP_FAILED) { - log_error("mmap() error (%d)\n", errno); + log_error("mmap() error (%d)", errno); goto cleanup; } if (close(fd) < 0) { - log_error("close(fd) error (%d)\n", errno); + log_error("close(fd) error (%d)", errno); fd = -1; goto cleanup; } @@ -113,13 +119,13 @@ int data_file_mgr(void *param) p_editor_data = editor_data_load(p_data); if (p_editor_data == NULL) { - log_error("editor_data_load(data) error\n"); + log_error("editor_data_load(data) error"); goto cleanup; } if (munmap(p_data, len_data) < 0) { - log_error("munmap() error (%d)\n", errno); + log_error("munmap() error (%d)", errno); p_data = NULL; goto cleanup; } @@ -128,7 +134,7 @@ int data_file_mgr(void *param) p_data_new = malloc(DATA_FILE_MAX_LEN); if (p_data_new == NULL) { - log_error("malloc(content) error: OOM\n"); + log_error("malloc(content) error: OOM"); goto cleanup; } @@ -163,7 +169,7 @@ int data_file_mgr(void *param) len_data_new = editor_data_save(p_editor_data, p_data_new, DATA_FILE_MAX_LEN); if (len_data_new < 0) { - log_error("editor_data_save() error\n"); + log_error("editor_data_save() error"); goto cleanup; } line_total = split_data_lines(p_data_new, SCREEN_COLS, line_offsets, MAX_SPLIT_FILE_LINES, 1, NULL); @@ -192,37 +198,50 @@ int data_file_mgr(void *param) break; } + if (SYS_server_exit) // Do not save data on shutdown + { + goto cleanup; + } + if ((fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0640)) < 0) { - log_error("open(%s) error (%d)\n", path, errno); + log_error("open(%s) error (%d)", path, errno); goto cleanup; } if (write(fd, p_data_new, (size_t)len_data_new) < 0) { - log_error("write(len=%ld) error (%d)\n", len_data_new, errno); + log_error("write(len=%ld) error (%d)", len_data_new, errno); goto cleanup; } if (close(fd) < 0) { - log_error("close(fd) error (%d)\n", errno); + log_error("close(fd) error (%d)", errno); fd = -1; goto cleanup; } - fd = -1; - if (unlink(data_file_list[i].path) < 0) + // Make another copy of the data file so that the user editored copy will be kept after upgrade / reinstall + if ((fd = open(data_file_list[i].path, O_WRONLY | O_CREAT | O_TRUNC, 0640)) < 0) + { + log_error("open(%s) error (%d)", data_file_list[i].path, errno); + goto cleanup; + } + + if (write(fd, p_data_new, (size_t)len_data_new) < 0) { - log_error("unlink(%s) error (%d)\n", data_file_list[i].path, errno); + log_error("write(len=%ld) error (%d)", len_data_new, errno); goto cleanup; } - if (link(path, data_file_list[i].path) < 0) + if (close(fd) < 0) { - log_error("link(%s, %s) error (%d)\n", path, data_file_list[i].path, errno); + log_error("close(fd) error (%d)", errno); + fd = -1; goto cleanup; } + fd = -1; clearscr(); moveto(1, 1); @@ -242,12 +261,12 @@ cleanup: if (p_data != NULL && munmap(p_data, len_data) < 0) { - log_error("munmap() error (%d)\n", errno); + log_error("munmap() error (%d)", errno); } if (fd >= 0 && close(fd) < 0) { - log_error("close(fd) error (%d)\n", errno); + log_error("close(fd) error (%d)", errno); } return REDRAW;