| 30 |
int section_list_loader_pid; |
int section_list_loader_pid; |
| 31 |
int last_article_op_log_mid; |
int last_article_op_log_mid; |
| 32 |
|
|
| 33 |
int load_section_config_from_db(int reload) |
int load_section_config_from_db(int update_gen_ex) |
| 34 |
{ |
{ |
| 35 |
MYSQL *db = NULL; |
MYSQL *db = NULL; |
| 36 |
MYSQL_RES *rs = NULL, *rs2 = NULL; |
MYSQL_RES *rs = NULL, *rs2 = NULL; |
| 148 |
p_section->enable = (int8_t)atoi(row[6]); |
p_section->enable = (int8_t)atoi(row[6]); |
| 149 |
|
|
| 150 |
// Update gen_ex menu set |
// Update gen_ex menu set |
| 151 |
if (reload && p_section->enable && atoi(row[7]) > p_section->ex_menu_tm) |
if (update_gen_ex && p_section->enable && atoi(row[7]) > p_section->ex_menu_tm) |
| 152 |
{ |
{ |
| 153 |
snprintf(ex_menu_conf, sizeof(ex_menu_conf), "%s/%d", VAR_GEN_EX_MENU_DIR, p_section->sid); |
snprintf(ex_menu_conf, sizeof(ex_menu_conf), "%s/%d", VAR_GEN_EX_MENU_DIR, p_section->sid); |
| 154 |
|
|
| 155 |
ret = load_menu(&ex_menu_set_new, ex_menu_conf); |
ret = load_menu(&ex_menu_set_new, ex_menu_conf); |
| 156 |
if (ret < 0) |
if (ret < 0) |
| 157 |
{ |
{ |
|
log_error("load_menu(%s) error: %d\n", ex_menu_conf, ret); |
|
| 158 |
unload_menu(&ex_menu_set_new); |
unload_menu(&ex_menu_set_new); |
| 159 |
|
log_error("load_menu(%s) error: %d\n", ex_menu_conf, ret); |
| 160 |
} |
} |
| 161 |
else |
else |
| 162 |
{ |
{ |
| 167 |
|
|
| 168 |
ex_menu_set_new.allow_exit = 1; // Allow exit menu |
ex_menu_set_new.allow_exit = 1; // Allow exit menu |
| 169 |
memcpy(&(p_section->ex_menu_set), &ex_menu_set_new, sizeof(ex_menu_set_new)); |
memcpy(&(p_section->ex_menu_set), &ex_menu_set_new, sizeof(ex_menu_set_new)); |
|
set_menu_shm_readonly(&(p_section->ex_menu_set)); |
|
| 170 |
|
|
| 171 |
p_section->ex_menu_tm = atol(row[7]); |
p_section->ex_menu_tm = atol(row[7]); |
| 172 |
#ifdef _DEBUG |
#ifdef _DEBUG |
| 700 |
SYS_child_process_count = 0; |
SYS_child_process_count = 0; |
| 701 |
|
|
| 702 |
// Detach menu in shared memory |
// Detach menu in shared memory |
| 703 |
detach_menu_shm(p_bbs_menu); |
detach_menu_shm(&bbs_menu); |
|
free(p_bbs_menu); |
|
|
p_bbs_menu = NULL; |
|
| 704 |
|
|
| 705 |
// Set signal handler |
// Set signal handler |
| 706 |
act.sa_handler = SIG_DFL; |
act.sa_handler = SIG_DFL; |
| 707 |
|
if (sigaction(SIGHUP, &act, NULL) == -1) |
| 708 |
|
{ |
| 709 |
|
log_error("set signal action of SIGHUP error: %d\n", errno); |
| 710 |
|
} |
| 711 |
|
act.sa_handler = SIG_DFL; |
| 712 |
if (sigaction(SIGCHLD, &act, NULL) == -1) |
if (sigaction(SIGCHLD, &act, NULL) == -1) |
| 713 |
{ |
{ |
| 714 |
log_error("set signal action of SIGCHLD error: %d\n", errno); |
log_error("set signal action of SIGCHLD error: %d\n", errno); |
| 715 |
} |
} |
| 716 |
|
|
|
// Force reload to load gen_ex_menu |
|
|
SYS_section_list_reload = 1; |
|
|
|
|
| 717 |
// Do section data loader periodically |
// Do section data loader periodically |
| 718 |
while (!SYS_server_exit) |
while (!SYS_server_exit) |
| 719 |
{ |
{ |
| 720 |
if (SYS_section_list_reload) |
if (SYS_conf_reload) |
| 721 |
{ |
{ |
| 722 |
SYS_section_list_reload = 0; |
SYS_conf_reload = 0; |
| 723 |
|
|
| 724 |
// Load section config |
// Load section config |
| 725 |
if (load_section_config_from_db(1) < 0) |
if (load_section_config_from_db(0) < 0) |
| 726 |
{ |
{ |
| 727 |
log_error("load_section_config_from_db() error\n"); |
log_error("load_section_config_from_db(0) error\n"); |
| 728 |
} |
} |
| 729 |
else |
else |
| 730 |
{ |
{ |
| 745 |
|
|
| 746 |
if (ret == ERR_UNKNOWN_SECTION) |
if (ret == ERR_UNKNOWN_SECTION) |
| 747 |
{ |
{ |
| 748 |
SYS_section_list_reload = 1; // Force reload section_list |
SYS_conf_reload = 1; // Force reload section_list |
| 749 |
} |
} |
| 750 |
} |
} |
| 751 |
} while (ret == LOAD_ARTICLE_COUNT_LIMIT); |
} while (ret == LOAD_ARTICLE_COUNT_LIMIT); |
| 756 |
log_common("Incrementally load %d articles, last_aid = %d\n", load_count, article_block_last_aid()); |
log_common("Incrementally load %d articles, last_aid = %d\n", load_count, article_block_last_aid()); |
| 757 |
} |
} |
| 758 |
|
|
| 759 |
if (SYS_section_list_reload) |
if (SYS_conf_reload) |
| 760 |
{ |
{ |
| 761 |
continue; |
continue; |
| 762 |
} |
} |
| 772 |
|
|
| 773 |
if (ret == ERR_UNKNOWN_SECTION) |
if (ret == ERR_UNKNOWN_SECTION) |
| 774 |
{ |
{ |
| 775 |
SYS_section_list_reload = 1; // Force reload section_list |
SYS_conf_reload = 1; // Force reload section_list |
| 776 |
} |
} |
| 777 |
} |
} |
| 778 |
} while (ret == LOAD_ARTICLE_COUNT_LIMIT); |
} while (ret == LOAD_ARTICLE_COUNT_LIMIT); |
| 782 |
log_common("Proceeded %d article logs, last_mid = %d\n", last_article_op_log_mid - last_mid, last_article_op_log_mid); |
log_common("Proceeded %d article logs, last_mid = %d\n", last_article_op_log_mid - last_mid, last_article_op_log_mid); |
| 783 |
} |
} |
| 784 |
|
|
| 785 |
if (SYS_section_list_reload) |
if (SYS_conf_reload) |
| 786 |
{ |
{ |
| 787 |
continue; |
continue; |
| 788 |
} |
} |
| 789 |
|
|
| 790 |
for (i = 0; i < BBS_section_list_load_interval && !SYS_server_exit && !SYS_section_list_reload; i++) |
for (i = 0; i < BBS_section_list_load_interval && !SYS_server_exit && !SYS_conf_reload; i++) |
| 791 |
{ |
{ |
| 792 |
sleep(1); |
sleep(1); |
| 793 |
} |
} |
| 799 |
|
|
| 800 |
// gen_ex_menu cleanup |
// gen_ex_menu cleanup |
| 801 |
section_list_ex_menu_set_cleanup(); |
section_list_ex_menu_set_cleanup(); |
| 802 |
|
|
| 803 |
// Detach data pools shm |
// Detach data pools shm |
| 804 |
detach_section_list_shm(); |
detach_section_list_shm(); |
| 805 |
detach_article_block_shm(); |
detach_article_block_shm(); |
| 814 |
|
|
| 815 |
return 0; |
return 0; |
| 816 |
} |
} |
|
|
|
|
int section_list_loader_reload(void) |
|
|
{ |
|
|
if (section_list_loader_pid == 0) |
|
|
{ |
|
|
log_error("section_list_loader not running\n"); |
|
|
return -2; |
|
|
} |
|
|
|
|
|
if (kill(section_list_loader_pid, SIGHUP) < 0) |
|
|
{ |
|
|
log_error("Send SIGTERM signal failed (%d)\n", errno); |
|
|
return -1; |
|
|
} |
|
|
|
|
|
return 0; |
|
|
} |
|
| 817 |
|
|
| 818 |
int query_section_articles(SECTION_LIST *p_section, int page_id, ARTICLE *p_articles[], |
int query_section_articles(SECTION_LIST *p_section, int page_id, ARTICLE *p_articles[], |
| 819 |
int *p_article_count, int *p_page_count, int *p_ontop_start_offset) |
int *p_article_count, int *p_page_count, int *p_ontop_start_offset) |