| 723 |
detach_menu_shm(&top10_menu); |
detach_menu_shm(&top10_menu); |
| 724 |
|
|
| 725 |
// Set signal handler |
// Set signal handler |
| 726 |
act.sa_handler = SIG_DFL; |
act.sa_handler = SIG_IGN; |
| 727 |
if (sigaction(SIGHUP, &act, NULL) == -1) |
if (sigaction(SIGHUP, &act, NULL) == -1) |
| 728 |
{ |
{ |
| 729 |
log_error("set signal action of SIGHUP error: %d\n", errno); |
log_error("set signal action of SIGHUP error: %d\n", errno); |
| 892 |
} |
} |
| 893 |
else if (page_id < 0 || page_id >= *p_page_count) |
else if (page_id < 0 || page_id >= *p_page_count) |
| 894 |
{ |
{ |
| 895 |
|
#ifdef _DEBUG |
| 896 |
log_error("Invalid page_id=%d, not in range [0, %d)\n", page_id, *p_page_count); |
log_error("Invalid page_id=%d, not in range [0, %d)\n", page_id, *p_page_count); |
| 897 |
|
#endif |
| 898 |
ret = -3; |
ret = -3; |
| 899 |
} |
} |
| 900 |
else |
else |
| 933 |
: (page_id - p_section->page_count + 1) * BBS_article_limit_per_page - p_section->last_page_visible_article_count); |
: (page_id - p_section->page_count + 1) * BBS_article_limit_per_page - p_section->last_page_visible_article_count); |
| 934 |
while (*p_article_count < BBS_article_limit_per_page && i < p_section->ontop_article_count) |
while (*p_article_count < BBS_article_limit_per_page && i < p_section->ontop_article_count) |
| 935 |
{ |
{ |
| 936 |
p_articles[(*p_article_count)++] = p_section->p_ontop_articles[i++]; |
p_articles[*p_article_count] = p_section->p_ontop_articles[i++]; |
| 937 |
|
(*p_article_count)++; |
| 938 |
} |
} |
| 939 |
} |
} |
| 940 |
} |
} |
| 1018 |
p_article = section_list_find_article_with_offset(p_section, aid, &page_id, &offset, &p_tmp); |
p_article = section_list_find_article_with_offset(p_section, aid, &page_id, &offset, &p_tmp); |
| 1019 |
if (p_article != NULL) |
if (p_article != NULL) |
| 1020 |
{ |
{ |
| 1021 |
*p_article_count = (page_id == p_section->page_count - 1 ? p_section->last_page_visible_article_count : BBS_article_limit_per_page); |
*p_article_count = (page_id >= p_section->page_count - 1 ? p_section->last_page_visible_article_count : BBS_article_limit_per_page); |
| 1022 |
|
|
| 1023 |
p_article = p_section->p_page_first_article[page_id]; |
p_article = p_section->p_page_first_article[page_id]; |
| 1024 |
for (i = 0; i < *p_article_count && p_article != NULL;) |
for (i = 0; i < *p_article_count && p_article != NULL;) |
| 1039 |
break; |
break; |
| 1040 |
} |
} |
| 1041 |
} |
} |
| 1042 |
|
|
| 1043 |
p_article = p_article->p_next; |
p_article = p_article->p_next; |
| 1044 |
|
if (p_article == p_section->p_page_first_article[page_id]) |
| 1045 |
|
{ |
| 1046 |
|
log_error("Dead loop detected at page=%d, article_count=%d\n", page_id, *p_article_count); |
| 1047 |
|
break; |
| 1048 |
|
} |
| 1049 |
} |
} |
| 1050 |
|
|
| 1051 |
// Include ontop articles |
// Include ontop articles |
| 1214 |
{ |
{ |
| 1215 |
*pp_article = p_article; |
*pp_article = p_article; |
| 1216 |
break; |
break; |
| 1217 |
|
} |
| 1218 |
|
} |
| 1219 |
|
} |
| 1220 |
|
|
| 1221 |
|
// release lock of section |
| 1222 |
|
if (section_list_rd_unlock(p_section) < 0) |
| 1223 |
|
{ |
| 1224 |
|
log_error("section_list_rd_unlock(sid = %d) error\n", p_section->sid); |
| 1225 |
|
return -2; |
| 1226 |
|
} |
| 1227 |
|
|
| 1228 |
|
return (p_article != NULL && p_article != p_article_cur ? 1 : 0); |
| 1229 |
|
} |
| 1230 |
|
|
| 1231 |
|
int scan_article_in_section_by_title(SECTION_LIST *p_section, const ARTICLE *p_article_cur, |
| 1232 |
|
int direction, const char *title, const ARTICLE **pp_article) |
| 1233 |
|
{ |
| 1234 |
|
ARTICLE *p_article; |
| 1235 |
|
int ret = 0; |
| 1236 |
|
|
| 1237 |
|
if (p_section == NULL || p_article_cur == NULL || title == NULL || pp_article == NULL) |
| 1238 |
|
{ |
| 1239 |
|
log_error("NULL pointer error\n"); |
| 1240 |
|
return -1; |
| 1241 |
|
} |
| 1242 |
|
|
| 1243 |
|
if (p_article_cur->sid != p_section->sid) |
| 1244 |
|
{ |
| 1245 |
|
log_error("Inconsistent SID\n"); |
| 1246 |
|
return -1; |
| 1247 |
|
} |
| 1248 |
|
|
| 1249 |
|
// acquire lock of section |
| 1250 |
|
if ((ret = section_list_rd_lock(p_section)) < 0) |
| 1251 |
|
{ |
| 1252 |
|
log_error("section_list_rd_lock(sid = %d) error\n", p_section->sid); |
| 1253 |
|
return -2; |
| 1254 |
|
} |
| 1255 |
|
|
| 1256 |
|
*pp_article = NULL; |
| 1257 |
|
|
| 1258 |
|
if (direction >= 0) |
| 1259 |
|
{ |
| 1260 |
|
for (p_article = p_article_cur->p_next; p_article != NULL && p_article != p_article_cur; p_article = p_article->p_next) |
| 1261 |
|
{ |
| 1262 |
|
if (p_article->visible && strcasestr(p_article->title, title) != NULL) |
| 1263 |
|
{ |
| 1264 |
|
*pp_article = p_article; |
| 1265 |
|
break; |
| 1266 |
|
} |
| 1267 |
|
} |
| 1268 |
|
} |
| 1269 |
|
else // direction < 0 |
| 1270 |
|
{ |
| 1271 |
|
for (p_article = p_article_cur->p_prior; p_article != NULL && p_article != p_article_cur; p_article = p_article->p_prior) |
| 1272 |
|
{ |
| 1273 |
|
if (p_article->visible && strcasestr(p_article->title, title) != NULL) |
| 1274 |
|
{ |
| 1275 |
|
*pp_article = p_article; |
| 1276 |
|
break; |
| 1277 |
} |
} |
| 1278 |
} |
} |
| 1279 |
} |
} |