/[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.57 by sysadm, Mon Nov 3 07:14:25 2025 UTC Revision 1.66 by sysadm, Sun Nov 16 02:06:56 2025 UTC
# Line 1  Line 1 
1  /***************************************************************************  /* SPDX-License-Identifier: GPL-3.0-or-later */
2                                          section_list_loader.c  -  description  /*
3                                                           -------------------   * section_list_loader
4          Copyright            : (C) 2004-2025 by Leaflet   *   - load and query operations of section articles
5          Email                : leaflet@leafok.com   *
6   ***************************************************************************/   * Copyright (C) 2004-2025  Leaflet <leaflet@leafok.com>
7     */
8  /***************************************************************************  
9   *                                                                         *  #ifdef HAVE_CONFIG_H
10   *   This program is free software; you can redistribute it and/or modify  *  #include "config.h"
11   *   it under the terms of the GNU General Public License as published by  *  #endif
  *   the Free Software Foundation; either version 3 of the License, or     *  
  *   (at your option) any later version.                                   *  
  *                                                                         *  
  ***************************************************************************/  
12    
13  #include "article_cache.h"  #include "article_cache.h"
14  #include "article_view_log.h"  #include "article_view_log.h"
# Line 34  Line 30 
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    static void loader_proc_sig_usr1_handler(int i)
34    {
35            // Restart log
36            if (log_restart() < 0)
37            {
38                    log_error("Restart logging failed\n");
39            }
40    }
41    
42  int load_section_config_from_db(int update_gen_ex)  int load_section_config_from_db(int update_gen_ex)
43  {  {
44          MYSQL *db = NULL;          MYSQL *db = NULL;
# Line 723  int section_list_loader_launch(void) Line 728  int section_list_loader_launch(void)
728          detach_menu_shm(&top10_menu);          detach_menu_shm(&top10_menu);
729    
730          // Set signal handler          // Set signal handler
731          act.sa_handler = SIG_DFL;          act.sa_handler = SIG_IGN;
732          if (sigaction(SIGHUP, &act, NULL) == -1)          if (sigaction(SIGHUP, &act, NULL) == -1)
733          {          {
734                  log_error("set signal action of SIGHUP error: %d\n", errno);                  log_error("set signal action of SIGHUP error: %d\n", errno);
# Line 733  int section_list_loader_launch(void) Line 738  int section_list_loader_launch(void)
738          {          {
739                  log_error("set signal action of SIGCHLD error: %d\n", errno);                  log_error("set signal action of SIGCHLD error: %d\n", errno);
740          }          }
741            act.sa_handler = loader_proc_sig_usr1_handler;
742            if (sigaction(SIGUSR1, &act, NULL) == -1)
743            {
744                    log_error("set signal action of SIGUSR1 error: %d\n", errno);
745            }
746    
747          // Do section data loader periodically          // Do section data loader periodically
748          while (!SYS_server_exit)          while (!SYS_server_exit)
# Line 892  int query_section_articles(SECTION_LIST Line 902  int query_section_articles(SECTION_LIST
902          }          }
903          else if (page_id < 0 || page_id >= *p_page_count)          else if (page_id < 0 || page_id >= *p_page_count)
904          {          {
905    #ifdef _DEBUG
906                  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);
907    #endif
908                  ret = -3;                  ret = -3;
909          }          }
910          else          else
# Line 931  int query_section_articles(SECTION_LIST Line 943  int query_section_articles(SECTION_LIST
943                                           : (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);
944                          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)
945                          {                          {
946                                  p_articles[(*p_article_count)++] = p_section->p_ontop_articles[i++];                                  p_articles[*p_article_count] = p_section->p_ontop_articles[i++];
947                                    (*p_article_count)++;
948                          }                          }
949                  }                  }
950          }          }
# Line 1015  int locate_article_in_section(SECTION_LI Line 1028  int locate_article_in_section(SECTION_LI
1028                  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);
1029                  if (p_article != NULL)                  if (p_article != NULL)
1030                  {                  {
1031                          *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);
1032    
1033                          p_article = p_section->p_page_first_article[page_id];                          p_article = p_section->p_page_first_article[page_id];
1034                          for (i = 0; i < *p_article_count && p_article != NULL;)                          for (i = 0; i < *p_article_count && p_article != NULL;)
# Line 1036  int locate_article_in_section(SECTION_LI Line 1049  int locate_article_in_section(SECTION_LI
1049                                                  break;                                                  break;
1050                                          }                                          }
1051                                  }                                  }
1052    
1053                                  p_article = p_article->p_next;                                  p_article = p_article->p_next;
1054                                    if (p_article == p_section->p_page_first_article[page_id])
1055                                    {
1056                                            log_error("Dead loop detected at page=%d, article_count=%d\n", page_id, *p_article_count);
1057                                            break;
1058                                    }
1059                          }                          }
1060    
1061                          // Include ontop articles                          // Include ontop articles
# Line 1054  int locate_article_in_section(SECTION_LI Line 1073  int locate_article_in_section(SECTION_LI
1073          return (ret < 0 ? ret : (p_article == NULL ? 0 : 1));          return (ret < 0 ? ret : (p_article == NULL ? 0 : 1));
1074  }  }
1075    
1076    int last_article_in_section(SECTION_LIST *p_section, const ARTICLE **pp_article)
1077    {
1078            int ret = 0;
1079    
1080            const ARTICLE *p_article;
1081    
1082            if (p_section == NULL || pp_article == NULL)
1083            {
1084                    log_error("NULL pointer error\n");
1085                    return -1;
1086            }
1087    
1088            *pp_article = NULL;
1089    
1090            // acquire lock of section
1091            if ((ret = section_list_rd_lock(p_section)) < 0)
1092            {
1093                    log_error("section_list_rd_lock(sid = %d) error\n", p_section->sid);
1094                    return -2;
1095            }
1096    
1097            for (p_article = p_section->p_article_tail;
1098                     p_article && p_article != p_section->p_article_head && !p_article->visible;
1099                     p_article = p_article->p_prior)
1100                    ;
1101    
1102            if (p_article && p_article->visible)
1103            {
1104                    *pp_article = p_article;
1105                    ret = 1;
1106            }
1107    
1108            // release lock of section
1109            if (section_list_rd_unlock(p_section) < 0)
1110            {
1111                    log_error("section_list_rd_unlock(sid = %d) error\n", p_section->sid);
1112                    ret = -2;
1113            }
1114    
1115            return ret;
1116    }
1117    
1118  int scan_unread_article_in_section(SECTION_LIST *p_section, const ARTICLE *p_article_cur, const ARTICLE **pp_article_unread)  int scan_unread_article_in_section(SECTION_LIST *p_section, const ARTICLE *p_article_cur, const ARTICLE **pp_article_unread)
1119  {  {
1120          ARTICLE *p_article;          ARTICLE *p_article;
# Line 1220  int scan_article_in_section_by_username( Line 1281  int scan_article_in_section_by_username(
1281  }  }
1282    
1283  int scan_article_in_section_by_title(SECTION_LIST *p_section, const ARTICLE *p_article_cur,  int scan_article_in_section_by_title(SECTION_LIST *p_section, const ARTICLE *p_article_cur,
1284                                                                                  int direction, const char *title, const ARTICLE **pp_article)                                                                           int direction, const char *title, const ARTICLE **pp_article)
1285  {  {
1286          ARTICLE *p_article;          ARTICLE *p_article;
1287          int ret = 0;          int ret = 0;


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

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