| 21 |
#include "log.h" |
#include "log.h" |
| 22 |
#include "io.h" |
#include "io.h" |
| 23 |
#include "menu.h" |
#include "menu.h" |
| 24 |
|
#include "file_loader.h" |
| 25 |
#include <stdlib.h> |
#include <stdlib.h> |
| 26 |
#include <signal.h> |
#include <signal.h> |
| 27 |
#include <string.h> |
#include <string.h> |
| 145 |
return -2; |
return -2; |
| 146 |
} |
} |
| 147 |
|
|
| 148 |
|
// Initialize trie dict pool |
| 149 |
|
if (trie_dict_init(CONF_BBSD, TRIE_NODE_PER_POOL) < 0) |
| 150 |
|
{ |
| 151 |
|
printf("trie_dict_init failed\n"); |
| 152 |
|
return -3; |
| 153 |
|
} |
| 154 |
|
|
| 155 |
|
// Load BBS cmd |
| 156 |
|
if (load_cmd() < 0) |
| 157 |
|
{ |
| 158 |
|
return -3; |
| 159 |
|
} |
| 160 |
|
|
| 161 |
// Load menus |
// Load menus |
| 162 |
p_bbs_menu = calloc(1, sizeof(MENU_SET)); |
p_bbs_menu = calloc(1, sizeof(MENU_SET)); |
| 163 |
if (p_bbs_menu == NULL) |
if (p_bbs_menu == NULL) |
| 168 |
if (load_menu(p_bbs_menu, CONF_MENU) < 0) |
if (load_menu(p_bbs_menu, CONF_MENU) < 0) |
| 169 |
{ |
{ |
| 170 |
unload_menu(p_bbs_menu); |
unload_menu(p_bbs_menu); |
| 171 |
|
free(p_bbs_menu); |
| 172 |
return -3; |
return -3; |
| 173 |
} |
} |
| 174 |
|
|
| 175 |
|
// Load data files |
| 176 |
|
if (file_loader_init() < 0) |
| 177 |
|
{ |
| 178 |
|
log_error("file_loader_init() error\n"); |
| 179 |
|
return -4; |
| 180 |
|
} |
| 181 |
|
for (int i = 0; i < data_files_load_startup_count; i++) |
| 182 |
|
{ |
| 183 |
|
if (load_file(data_files_load_startup[i]) < 0) |
| 184 |
|
{ |
| 185 |
|
log_error("load_file_mmap(%s) error\n", data_files_load_startup[i]); |
| 186 |
|
} |
| 187 |
|
} |
| 188 |
|
|
| 189 |
|
log_std("Debug: trie dict nodes used = %d, limit = %d\n", trie_dict_used_nodes(), TRIE_NODE_PER_POOL); |
| 190 |
|
|
| 191 |
// Set signal handler |
// Set signal handler |
| 192 |
signal(SIGHUP, sig_hup_handler); |
signal(SIGHUP, sig_hup_handler); |
| 193 |
signal(SIGCHLD, sig_chld_handler); |
signal(SIGCHLD, sig_chld_handler); |
| 194 |
signal(SIGTERM, sig_term_handler); |
signal(SIGTERM, sig_term_handler); |
| 195 |
|
|
| 196 |
// Initialize socket server |
// Initialize socket server |
| 197 |
if (net_server(BBS_address, BBS_port) < 0) |
net_server(BBS_address, BBS_port); |
|
{ |
|
|
return -4; |
|
|
} |
|
| 198 |
|
|
| 199 |
|
// Cleanup loaded data files |
| 200 |
|
file_loader_cleanup(); |
| 201 |
|
|
| 202 |
// Cleanup menu |
// Cleanup menu |
| 203 |
unload_menu(p_bbs_menu); |
unload_menu(p_bbs_menu); |
| 204 |
free(p_bbs_menu); |
free(p_bbs_menu); |
| 205 |
p_bbs_menu = NULL; |
p_bbs_menu = NULL; |
| 206 |
|
|
| 207 |
|
// Cleanup trie dict pool |
| 208 |
|
trie_dict_cleanup(); |
| 209 |
|
|
| 210 |
log_std("Main process exit normally\n"); |
log_std("Main process exit normally\n"); |
| 211 |
|
|
| 212 |
return 0; |
return 0; |