/[LeafOK_CVS]/lbbs/src/section_list_loader.c
ViewVC logotype

Diff of /lbbs/src/section_list_loader.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.48 by sysadm, Mon Oct 13 02:23:27 2025 UTC Revision 1.56 by sysadm, Mon Nov 3 06:43:55 2025 UTC
# Line 22  Line 22 
22  #include "log.h"  #include "log.h"
23  #include "menu.h"  #include "menu.h"
24  #include "section_list_loader.h"  #include "section_list_loader.h"
25    #include "user_list.h"
26  #include "user_priv.h"  #include "user_priv.h"
27  #include <errno.h>  #include <errno.h>
28  #include <signal.h>  #include <signal.h>
# Line 109  int load_section_config_from_db(int upda Line 110  int load_section_config_from_db(int upda
110                  mysql_free_result(rs2);                  mysql_free_result(rs2);
111                  rs2 = NULL;                  rs2 = NULL;
112    
113                  p_section = section_list_find_by_sid(sid, NULL);                  p_section = section_list_find_by_sid(sid);
114    
115                  if (p_section == NULL)                  if (p_section == NULL)
116                  {                  {
# Line 137  int load_section_config_from_db(int upda Line 138  int load_section_config_from_db(int upda
138                                  break;                                  break;
139                          }                          }
140    
141                          strncpy(p_section->sname, row[1], sizeof(p_section->sname) - 1);                          if (section_list_update(p_section, row[1], row[2], master_list) < 0)
142                          p_section->sname[sizeof(p_section->sname) - 1] = '\0';                          {
143                          strncpy(p_section->stitle, row[2], sizeof(p_section->stitle) - 1);                                  log_error("section_list_update(sid=%d) error\n", p_section->sid);
144                          p_section->stitle[sizeof(p_section->stitle) - 1] = '\0';                                  ret = -4;
145                          strncpy(p_section->master_list, master_list, sizeof(p_section->master_list) - 1);                                  break;
146                          p_section->master_list[sizeof(p_section->master_list) - 1] = '\0';                          }
147                  }                  }
148    
149                  p_section->class_id = atoi(row[3]);                  p_section->class_id = atoi(row[3]);
# Line 286  int append_articles_from_db(int32_t star Line 287  int append_articles_from_db(int32_t star
287                          }                          }
288                  }                  }
289    
290                  if ((p_section = section_list_find_by_sid(article.sid, NULL)) == NULL)                  if ((p_section = section_list_find_by_sid(article.sid)) == NULL)
291                  {                  {
292                          log_error("section_list_find_by_sid(%d) error: unknown section, try reloading section config\n", article.sid);                          log_error("section_list_find_by_sid(%d) error: unknown section, try reloading section config\n", article.sid);
293                          ret = ERR_UNKNOWN_SECTION; // Unknown section found                          ret = ERR_UNKNOWN_SECTION; // Unknown section found
# Line 465  int apply_article_op_log_from_db(int op_ Line 466  int apply_article_op_log_from_db(int op_
466                          }                          }
467                  }                  }
468    
469                  if ((p_section = section_list_find_by_sid(p_article->sid, NULL)) == NULL)                  if ((p_section = section_list_find_by_sid(p_article->sid)) == NULL)
470                  {                  {
471                          log_error("section_list_find_by_sid(%d) error: unknown section, try reloading section config\n", p_article->sid);                          log_error("section_list_find_by_sid(%d) error: unknown section, try reloading section config\n", p_article->sid);
472                          ret = ERR_UNKNOWN_SECTION; // Unknown section found                          ret = ERR_UNKNOWN_SECTION; // Unknown section found
# Line 590  int apply_article_op_log_from_db(int op_ Line 591  int apply_article_op_log_from_db(int op_
591    
592                          if (sid_dest > 0 && sid_dest != p_article->sid)                          if (sid_dest > 0 && sid_dest != p_article->sid)
593                          {                          {
594                                  p_section_dest = section_list_find_by_sid(sid_dest, NULL);                                  p_section_dest = section_list_find_by_sid(sid_dest);
595                                  if (p_section_dest == NULL)                                  if (p_section_dest == NULL)
596                                  {                                  {
597                                          ret = ERR_UNKNOWN_SECTION;                                          ret = ERR_UNKNOWN_SECTION;
# Line 689  int section_list_loader_launch(void) Line 690  int section_list_loader_launch(void)
690          int article_count;          int article_count;
691          int load_count;          int load_count;
692          int last_mid;          int last_mid;
693          int i;          time_t tm_section_list_reload = 0;
694            time_t tm_user_list_reload = time(NULL);
695            time_t tm_user_online_list_reload = time(NULL);
696    
697          if (section_list_loader_pid != 0)          if (section_list_loader_pid != 0)
698          {          {
# Line 717  int section_list_loader_launch(void) Line 720  int section_list_loader_launch(void)
720    
721          // Detach menu in shared memory          // Detach menu in shared memory
722          detach_menu_shm(&bbs_menu);          detach_menu_shm(&bbs_menu);
723            detach_menu_shm(&top10_menu);
724    
725          // Set signal handler          // Set signal handler
726          act.sa_handler = SIG_DFL;          act.sa_handler = SIG_DFL;
# Line 733  int section_list_loader_launch(void) Line 737  int section_list_loader_launch(void)
737          // Do section data loader periodically          // Do section data loader periodically
738          while (!SYS_server_exit)          while (!SYS_server_exit)
739          {          {
740                    tm_section_list_reload = time(NULL);
741    
742                  if (SYS_conf_reload)                  if (SYS_conf_reload)
743                  {                  {
744                          SYS_conf_reload = 0;                          SYS_conf_reload = 0;
# Line 798  int section_list_loader_launch(void) Line 804  int section_list_loader_launch(void)
804                          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);
805                  }                  }
806    
807                  if (SYS_conf_reload)                  // Reload user list
808                    if (time(NULL) - tm_user_list_reload >= BBS_user_list_load_interval)
809                  {                  {
810                          continue;                          if (user_list_pool_reload(0) < 0)
811                            {
812                                    log_error("user_list_pool_reload(all_user) error\n");
813                            }
814    
815                            if (user_stat_update() < 0)
816                            {
817                                    log_error("user_stat_update() error\n");
818                            }
819    
820                            tm_user_list_reload = time(NULL);
821                  }                  }
822    
823                  for (i = 0; i < BBS_section_list_load_interval && !SYS_server_exit && !SYS_conf_reload; i++)                  // Reload user online list
824                    if (time(NULL) - tm_user_online_list_reload >= BBS_user_online_list_load_interval)
825                    {
826                            if (user_list_pool_reload(1) < 0)
827                            {
828                                    log_error("user_list_pool_reload(online_user) error\n");
829                            }
830    
831                            tm_user_online_list_reload = time(NULL);
832                    }
833    
834                    // Wait for BBS_section_list_load_interval seconds
835                    while (!SYS_server_exit && time(NULL) - tm_section_list_reload < BBS_section_list_load_interval)
836                  {                  {
837                          sleep(1);                          sleep(1);
838                  }                  }
# Line 820  int section_list_loader_launch(void) Line 849  int section_list_loader_launch(void)
849          detach_section_list_shm();          detach_section_list_shm();
850          detach_article_block_shm();          detach_article_block_shm();
851          detach_trie_dict_shm();          detach_trie_dict_shm();
852            detach_user_list_pool_shm();
853    
854          log_common("Section list loader process exit normally\n");          log_common("Section list loader process exit normally\n");
855          log_end();          log_end();
# Line 1059  int scan_unread_article_in_section(SECTI Line 1089  int scan_unread_article_in_section(SECTI
1089                  }                  }
1090          }          }
1091    
1092            // release lock of section
1093            if (section_list_rd_unlock(p_section) < 0)
1094            {
1095                    log_error("section_list_rd_unlock(sid = %d) error\n", p_section->sid);
1096                    return -2;
1097            }
1098    
1099            return (p_article != NULL && p_article != p_article_cur ? 1 : 0);
1100    }
1101    
1102    int scan_article_in_section_by_uid(SECTION_LIST *p_section, const ARTICLE *p_article_cur,
1103                                                                       int direction, int32_t uid, const ARTICLE **pp_article)
1104    {
1105            ARTICLE *p_article;
1106            int ret = 0;
1107    
1108            if (p_section == NULL || p_article_cur == NULL || pp_article == NULL)
1109            {
1110                    log_error("NULL pointer error\n");
1111                    return -1;
1112            }
1113    
1114            if (p_article_cur->sid != p_section->sid)
1115            {
1116                    log_error("Inconsistent SID\n");
1117                    return -1;
1118            }
1119    
1120            // acquire lock of section
1121            if ((ret = section_list_rd_lock(p_section)) < 0)
1122            {
1123                    log_error("section_list_rd_lock(sid = %d) error\n", p_section->sid);
1124                    return -2;
1125            }
1126    
1127            *pp_article = NULL;
1128    
1129            if (direction >= 0)
1130            {
1131                    for (p_article = p_article_cur->p_next; p_article != NULL && p_article != p_article_cur; p_article = p_article->p_next)
1132                    {
1133                            if (p_article->visible && p_article->uid == uid)
1134                            {
1135                                    *pp_article = p_article;
1136                                    break;
1137                            }
1138                    }
1139            }
1140            else // direction < 0
1141            {
1142                    for (p_article = p_article_cur->p_prior; p_article != NULL && p_article != p_article_cur; p_article = p_article->p_prior)
1143                    {
1144                            if (p_article->visible && p_article->uid == uid)
1145                            {
1146                                    *pp_article = p_article;
1147                                    break;
1148                            }
1149                    }
1150            }
1151    
1152            // release lock of section
1153            if (section_list_rd_unlock(p_section) < 0)
1154            {
1155                    log_error("section_list_rd_unlock(sid = %d) error\n", p_section->sid);
1156                    return -2;
1157            }
1158    
1159            return (p_article != NULL && p_article != p_article_cur ? 1 : 0);
1160    }
1161    
1162    int scan_article_in_section_by_username(SECTION_LIST *p_section, const ARTICLE *p_article_cur,
1163                                                                                    int direction, const char *username, const ARTICLE **pp_article)
1164    {
1165            ARTICLE *p_article;
1166            int ret = 0;
1167    
1168            if (p_section == NULL || p_article_cur == NULL || username == NULL || pp_article == NULL)
1169            {
1170                    log_error("NULL pointer error\n");
1171                    return -1;
1172            }
1173    
1174            if (p_article_cur->sid != p_section->sid)
1175            {
1176                    log_error("Inconsistent SID\n");
1177                    return -1;
1178            }
1179    
1180            // acquire lock of section
1181            if ((ret = section_list_rd_lock(p_section)) < 0)
1182            {
1183                    log_error("section_list_rd_lock(sid = %d) error\n", p_section->sid);
1184                    return -2;
1185            }
1186    
1187            *pp_article = NULL;
1188    
1189            if (direction >= 0)
1190            {
1191                    for (p_article = p_article_cur->p_next; p_article != NULL && p_article != p_article_cur; p_article = p_article->p_next)
1192                    {
1193                            if (p_article->visible && strcasecmp(p_article->username, username) == 0)
1194                            {
1195                                    *pp_article = p_article;
1196                                    break;
1197                            }
1198                    }
1199            }
1200            else // direction < 0
1201            {
1202                    for (p_article = p_article_cur->p_prior; p_article != NULL && p_article != p_article_cur; p_article = p_article->p_prior)
1203                    {
1204                            if (p_article->visible && strcasecmp(p_article->username, username) == 0)
1205                            {
1206                                    *pp_article = p_article;
1207                                    break;
1208                            }
1209                    }
1210            }
1211    
1212          // release lock of section          // release lock of section
1213          if (section_list_rd_unlock(p_section) < 0)          if (section_list_rd_unlock(p_section) < 0)
1214          {          {


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1