| 23 |
#include "menu.h" |
#include "menu.h" |
| 24 |
#include "file_loader.h" |
#include "file_loader.h" |
| 25 |
#include "section_list_loader.h" |
#include "section_list_loader.h" |
| 26 |
|
#include <errno.h> |
| 27 |
#include <stdlib.h> |
#include <stdlib.h> |
| 28 |
#include <signal.h> |
#include <signal.h> |
| 29 |
#include <string.h> |
#include <string.h> |
| 56 |
int std_log_redir = 0; |
int std_log_redir = 0; |
| 57 |
int error_log_redir = 0; |
int error_log_redir = 0; |
| 58 |
FILE *fp; |
FILE *fp; |
| 59 |
|
int ret; |
| 60 |
|
int last_aid; |
| 61 |
|
|
| 62 |
// Parse args |
// Parse args |
| 63 |
for (int i = 1; i < argc; i++) |
for (int i = 1; i < argc; i++) |
| 150 |
return -2; |
return -2; |
| 151 |
} |
} |
| 152 |
|
|
| 153 |
|
// Check article cache dir |
| 154 |
|
ret = mkdir(VAR_ARTICLE_CACHE_DIR, S_IRWXU | S_IRGRP); |
| 155 |
|
if (ret == -1 && errno != EEXIST) |
| 156 |
|
{ |
| 157 |
|
log_error("mkdir(%s) error (%d)\n", VAR_ARTICLE_CACHE_DIR, errno); |
| 158 |
|
goto cleanup; |
| 159 |
|
} |
| 160 |
|
|
| 161 |
// Initialize data pools |
// Initialize data pools |
| 162 |
if ((fp = fopen(VAR_TRIE_DICT_SHM, "w")) == NULL) |
if ((fp = fopen(VAR_TRIE_DICT_SHM, "w")) == NULL) |
| 163 |
{ |
{ |
| 233 |
goto cleanup; |
goto cleanup; |
| 234 |
} |
} |
| 235 |
|
|
| 236 |
// Load section config |
set_last_article_op_log_from_db(); |
| 237 |
if (append_articles_from_db(0, 1) < 0) |
last_aid = 0; |
| 238 |
|
|
| 239 |
|
// Load section articles |
| 240 |
|
do |
| 241 |
{ |
{ |
| 242 |
log_error("append_articles_from_db(0, 1) error\n"); |
if ((ret = append_articles_from_db(last_aid + 1, 1, LOAD_ARTICLE_COUNT_LIMIT)) < 0) |
| 243 |
goto cleanup; |
{ |
| 244 |
} |
log_error("append_articles_from_db(0, 1, %d) error\n", LOAD_ARTICLE_COUNT_LIMIT); |
| 245 |
|
goto cleanup; |
| 246 |
|
} |
| 247 |
|
|
| 248 |
log_std("Debug: loaded %d articles, last_aid = %d\n", article_block_article_count(), article_block_last_aid()); |
last_aid = article_block_last_aid(); |
| 249 |
|
} while (ret == LOAD_ARTICLE_COUNT_LIMIT); |
| 250 |
|
|
| 251 |
|
log_std("Initially load %d articles, last_aid = %d\n", article_block_article_count(), article_block_last_aid()); |
| 252 |
|
|
| 253 |
// Set signal handler |
// Set signal handler |
| 254 |
signal(SIGHUP, sig_hup_handler); |
signal(SIGHUP, sig_hup_handler); |
| 255 |
signal(SIGCHLD, sig_chld_handler); |
signal(SIGCHLD, sig_chld_handler); |
| 256 |
signal(SIGTERM, sig_term_handler); |
signal(SIGTERM, sig_term_handler); |
| 257 |
|
|
| 258 |
|
// Launch section_list_loader process |
| 259 |
|
if (section_list_loader_launch() < 0) |
| 260 |
|
{ |
| 261 |
|
log_error("section_list_loader_launch() error\n"); |
| 262 |
|
goto cleanup; |
| 263 |
|
} |
| 264 |
|
|
| 265 |
// Initialize socket server |
// Initialize socket server |
| 266 |
net_server(BBS_address, BBS_port); |
net_server(BBS_address, BBS_port); |
| 267 |
|
|