| 58 |
FILE *fp; |
FILE *fp; |
| 59 |
int ret; |
int ret; |
| 60 |
int last_aid; |
int last_aid; |
| 61 |
|
struct sigaction act = {0}; |
| 62 |
|
|
| 63 |
// Parse args |
// Parse args |
| 64 |
for (int i = 1; i < argc; i++) |
for (int i = 1; i < argc; i++) |
| 79 |
app_help(); |
app_help(); |
| 80 |
return 0; |
return 0; |
| 81 |
case 'v': |
case 'v': |
| 82 |
puts(app_version); |
puts(APP_NAME_VER); |
| 83 |
return 0; |
return 0; |
| 84 |
default: |
default: |
| 85 |
arg_error(); |
arg_error(); |
| 101 |
} |
} |
| 102 |
if (strcmp(argv[i] + 2, "version") == 0) |
if (strcmp(argv[i] + 2, "version") == 0) |
| 103 |
{ |
{ |
| 104 |
puts(app_version); |
puts(APP_NAME_VER); |
| 105 |
return 0; |
return 0; |
| 106 |
} |
} |
| 107 |
if (strcmp(argv[i] + 2, "display-log") == 0) |
if (strcmp(argv[i] + 2, "display-log") == 0) |
| 138 |
|
|
| 139 |
if ((!daemon) && std_log_redir) |
if ((!daemon) && std_log_redir) |
| 140 |
{ |
{ |
| 141 |
log_std_redirect(STDERR_FILENO); |
log_common_redir(STDERR_FILENO); |
| 142 |
} |
} |
| 143 |
if ((!daemon) && error_log_redir) |
if ((!daemon) && error_log_redir) |
| 144 |
{ |
{ |
| 145 |
log_err_redirect(STDERR_FILENO); |
log_error_redir(STDERR_FILENO); |
| 146 |
} |
} |
| 147 |
|
|
| 148 |
|
log_common("BBS Server (%s) is staring...\n", APP_NAME_VER); |
| 149 |
|
|
| 150 |
// Load configuration |
// Load configuration |
| 151 |
if (load_conf(CONF_BBSD) < 0) |
if (load_conf(CONF_BBSD) < 0) |
| 152 |
{ |
{ |
| 154 |
} |
} |
| 155 |
|
|
| 156 |
// Check article cache dir |
// Check article cache dir |
| 157 |
ret = mkdir(VAR_ARTICLE_CACHE_DIR, S_IRWXU | S_IRGRP); |
ret = mkdir(VAR_ARTICLE_CACHE_DIR, 0750); |
| 158 |
if (ret == -1 && errno != EEXIST) |
if (ret == -1 && errno != EEXIST) |
| 159 |
{ |
{ |
| 160 |
log_error("mkdir(%s) error (%d)\n", VAR_ARTICLE_CACHE_DIR, errno); |
log_error("mkdir(%s) error (%d)\n", VAR_ARTICLE_CACHE_DIR, errno); |
| 251 |
last_aid = article_block_last_aid(); |
last_aid = article_block_last_aid(); |
| 252 |
} while (ret == LOAD_ARTICLE_COUNT_LIMIT); |
} while (ret == LOAD_ARTICLE_COUNT_LIMIT); |
| 253 |
|
|
| 254 |
log_std("Initially load %d articles, last_aid = %d\n", article_block_article_count(), article_block_last_aid()); |
log_common("Initially load %d articles, last_aid = %d\n", article_block_article_count(), article_block_last_aid()); |
| 255 |
|
|
| 256 |
// Set signal handler |
// Set signal handler |
| 257 |
signal(SIGHUP, sig_hup_handler); |
act.sa_handler = sig_hup_handler; |
| 258 |
signal(SIGCHLD, sig_chld_handler); |
if (sigaction(SIGHUP, &act, NULL) == -1) |
| 259 |
signal(SIGTERM, sig_term_handler); |
{ |
| 260 |
|
log_error("set signal action of SIGHUP error: %d\n", errno); |
| 261 |
|
goto cleanup; |
| 262 |
|
} |
| 263 |
|
act.sa_handler = sig_chld_handler; |
| 264 |
|
if (sigaction(SIGCHLD, &act, NULL) == -1) |
| 265 |
|
{ |
| 266 |
|
log_error("set signal action of SIGCHLD error: %d\n", errno); |
| 267 |
|
goto cleanup; |
| 268 |
|
} |
| 269 |
|
act.sa_handler = sig_term_handler; |
| 270 |
|
if (sigaction(SIGTERM, &act, NULL) == -1) |
| 271 |
|
{ |
| 272 |
|
log_error("set signal action of SIGTERM error: %d\n", errno); |
| 273 |
|
goto cleanup; |
| 274 |
|
} |
| 275 |
|
|
| 276 |
// Launch section_list_loader process |
// Launch section_list_loader process |
| 277 |
if (section_list_loader_launch() < 0) |
if (section_list_loader_launch() < 0) |
| 310 |
log_error("unlink(%s) error\n", VAR_SECTION_LIST_SHM); |
log_error("unlink(%s) error\n", VAR_SECTION_LIST_SHM); |
| 311 |
} |
} |
| 312 |
|
|
| 313 |
log_std("Main process exit normally\n"); |
log_common("Main process exit normally\n"); |
| 314 |
|
|
| 315 |
return 0; |
return 0; |
| 316 |
} |
} |