/[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.1 by sysadm, Mon May 26 03:42:45 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     */
 /***************************************************************************  
  *                                                                         *  
  *   This program is free software; you can redistribute it and/or modify  *  
  *   it under the terms of the GNU General Public License as published by  *  
  *   the Free Software Foundation; either version 3 of the License, or     *  
  *   (at your option) any later version.                                   *  
  *                                                                         *  
  ***************************************************************************/  
8    
9  #include "section_list_loader.h"  #ifdef HAVE_CONFIG_H
10  #include "log.h"  #include "config.h"
11    #endif
12    
13    #include "article_cache.h"
14    #include "article_view_log.h"
15    #include "bbs.h"
16  #include "database.h"  #include "database.h"
17  #include <stdio.h>  #include "ip_mask.h"
18  #include <string.h>  #include "log.h"
19    #include "menu.h"
20    #include "section_list_loader.h"
21    #include "user_list.h"
22    #include "user_priv.h"
23  #include <errno.h>  #include <errno.h>
24    #include <signal.h>
25    #include <stdio.h>
26  #include <stdlib.h>  #include <stdlib.h>
27    #include <string.h>
28    #include <unistd.h>
29    
30  int load_section_config_from_db(MYSQL *db)  int section_list_loader_pid;
31    int last_article_op_log_mid;
32    
33    static void loader_proc_sig_usr1_handler(int i)
34  {  {
35          MYSQL_RES *rs, *rs2;          // 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)
43    {
44            MYSQL *db = NULL;
45            MYSQL_RES *rs = NULL, *rs2 = NULL;
46          MYSQL_ROW row, row2;          MYSQL_ROW row, row2;
47          char sql[SQL_BUFFER_LEN];          char sql[SQL_BUFFER_LEN];
48          int32_t sid;          int32_t sid;
49          char master_name[BBS_username_max_len + 1];          char master_list[(BBS_username_max_len + 1) * 3 + 1];
50          SECTION_LIST *p_section;          SECTION_LIST *p_section;
51          int ret;          char ex_menu_conf[FILE_PATH_LEN];
52            MENU_SET ex_menu_set_new;
53            int ret = 0;
54    
55            db = db_open();
56            if (db == NULL)
57            {
58                    log_error("db_open() error: %s\n", mysql_error(db));
59                    ret = -1;
60                    goto cleanup;
61            }
62    
63          snprintf(sql, sizeof(sql),          snprintf(sql, sizeof(sql),
64                           "SELECT section_config.SID, sname, title, section_config.CID, read_user_level, write_user_level, "                           "SELECT section_config.SID, sname, section_config.title, section_config.CID, "
65                           "section_config.enable * section_class.enable AS enable "                           "read_user_level, write_user_level, section_config.enable * section_class.enable AS enable, "
66                           "FROM section_config INNER JOIN section_class ON section_config.CID = sectioN_class.CID "                           "UNIX_TIMESTAMP(ex_menu_tm) AS ex_menu_tm "
67                             "FROM section_config INNER JOIN section_class ON section_config.CID = section_class.CID "
68                           "ORDER BY section_config.SID");                           "ORDER BY section_config.SID");
69    
70          if (mysql_query(db, sql) != 0)          if (mysql_query(db, sql) != 0)
71          {          {
72                  log_error("Query section_list error: %s\n", mysql_error(db));                  log_error("Query section_list error: %s\n", mysql_error(db));
73                  return -1;                  ret = -2;
74                    goto cleanup;
75          }          }
76          if ((rs = mysql_store_result(db)) == NULL)          if ((rs = mysql_store_result(db)) == NULL)
77          {          {
78                  log_error("Get section_list data failed\n");                  log_error("Get section_list data failed\n");
79                  return -1;                  ret = -2;
80                    goto cleanup;
81          }          }
82    
83            ret = 0;
84          while ((row = mysql_fetch_row(rs)))          while ((row = mysql_fetch_row(rs)))
85          {          {
86                  sid = atoi(row[0]);                  sid = atoi(row[0]);
# Line 57  int load_section_config_from_db(MYSQL *d Line 90  int load_section_config_from_db(MYSQL *d
90                                   "SELECT username FROM section_master "                                   "SELECT username FROM section_master "
91                                   "INNER JOIN user_list ON section_master.UID = user_list.UID "                                   "INNER JOIN user_list ON section_master.UID = user_list.UID "
92                                   "WHERE SID = %d AND section_master.enable AND (NOW() BETWEEN begin_dt AND end_dt) "                                   "WHERE SID = %d AND section_master.enable AND (NOW() BETWEEN begin_dt AND end_dt) "
93                                   "ORDER BY major DESC LIMIT 1",                                   "ORDER BY major DESC, begin_dt ASC LIMIT 3",
94                                   sid);                                   sid);
95    
96                  if (mysql_query(db, sql) != 0)                  if (mysql_query(db, sql) != 0)
97                  {                  {
98                          log_error("Query section_master error: %s\n", mysql_error(db));                          log_error("Query section_master error: %s\n", mysql_error(db));
99                          return -2;                          ret = -3;
100                            break;
101                  }                  }
102                  if ((rs2 = mysql_store_result(db)) == NULL)                  if ((rs2 = mysql_store_result(db)) == NULL)
103                  {                  {
104                          log_error("Get section_master data failed\n");                          log_error("Get section_master data failed\n");
105                          return -2;                          ret = -3;
106                  }                          break;
                 if ((row2 = mysql_fetch_row(rs2)))  
                 {  
                         strncpy(master_name, row2[0], sizeof(master_name) - 1);  
                         master_name[sizeof(master_name) - 1] = '\0';  
107                  }                  }
108                  else  
109                    master_list[0] = '\0';
110                    while ((row2 = mysql_fetch_row(rs2)))
111                  {                  {
112                          master_name[0] = '\0';                          strncat(master_list, row2[0], sizeof(master_list) - 1 - strnlen(master_list, sizeof(master_list)));
113                            strncat(master_list, " ", sizeof(master_list) - 1 - strnlen(master_list, sizeof(master_list)));
114                  }                  }
115                  mysql_free_result(rs2);                  mysql_free_result(rs2);
116                    rs2 = NULL;
117    
118                  p_section = section_list_find_by_sid(sid);                  p_section = section_list_find_by_sid(sid);
119    
120                  if (p_section == NULL)                  if (p_section == NULL)
121                  {                  {
122                          p_section = section_list_create(sid, row[1], row[2], "");                          p_section = section_list_create(sid, row[1], row[2], master_list);
123                          if (p_section == NULL)                          if (p_section == NULL)
124                          {                          {
125                                  log_error("load_section_config_from_db() error: load new section sid = %d sname = %s\n", sid, row[1]);                                  log_error("section_list_create() error: load new section sid = %d sname = %s\n", sid, row[1]);
126                                    ret = -4;
127                                  break;                                  break;
128                          }                          }
129    
# Line 108  int load_section_config_from_db(MYSQL *d Line 143  int load_section_config_from_db(MYSQL *d
143                                  break;                                  break;
144                          }                          }
145    
146                          strncpy(p_section->sname, row[1], sizeof(p_section->sname) - 1);                          if (section_list_update(p_section, row[1], row[2], master_list) < 0)
147                          p_section->sname[sizeof(p_section->sname) - 1] = '\0';                          {
148                          strncpy(p_section->stitle, row[1], sizeof(p_section->stitle) - 1);                                  log_error("section_list_update(sid=%d) error\n", p_section->sid);
149                          p_section->stitle[sizeof(p_section->stitle) - 1] = '\0';                                  ret = -4;
150                          strncpy(p_section->master_name, master_name, sizeof(p_section->master_name) - 1);                                  break;
151                          p_section->master_name[sizeof(p_section->master_name) - 1] = '\0';                          }
152                  }                  }
153    
154                  p_section->class_id = atoi(row[3]);                  p_section->class_id = atoi(row[3]);
# Line 121  int load_section_config_from_db(MYSQL *d Line 156  int load_section_config_from_db(MYSQL *d
156                  p_section->write_user_level = atoi(row[5]);                  p_section->write_user_level = atoi(row[5]);
157                  p_section->enable = (int8_t)atoi(row[6]);                  p_section->enable = (int8_t)atoi(row[6]);
158    
159                    // Update gen_ex menu set
160                    if (update_gen_ex && p_section->enable && atol(row[7] == NULL ? "0" : row[7]) > p_section->ex_menu_tm)
161                    {
162                            snprintf(ex_menu_conf, sizeof(ex_menu_conf), "%s/%d", VAR_GEN_EX_MENU_DIR, p_section->sid);
163    
164                            ret = load_menu(&ex_menu_set_new, ex_menu_conf);
165                            if (ret < 0)
166                            {
167                                    unload_menu(&ex_menu_set_new);
168                                    log_error("load_menu(%s) error: %d\n", ex_menu_conf, ret);
169                            }
170                            else
171                            {
172                                    if (p_section->ex_menu_tm > 0)
173                                    {
174                                            unload_menu(&(p_section->ex_menu_set));
175                                    }
176    
177                                    ex_menu_set_new.allow_exit = 1; // Allow exit menu
178                                    memcpy(&(p_section->ex_menu_set), &ex_menu_set_new, sizeof(ex_menu_set_new));
179    
180                                    p_section->ex_menu_tm = atol(row[7]);
181    #ifdef _DEBUG
182                                    log_common("Loaded gen_ex_menu of section %d [%s]\n", p_section->sid, p_section->sname);
183    #endif
184                            }
185                    }
186    
187                  // release rw lock                  // release rw lock
188                  ret = section_list_rw_unlock(p_section);                  ret = section_list_rw_unlock(p_section);
189                  if (ret < 0)                  if (ret < 0)
# Line 128  int load_section_config_from_db(MYSQL *d Line 191  int load_section_config_from_db(MYSQL *d
191                          break;                          break;
192                  }                  }
193          }          }
194    
195    cleanup:
196            mysql_free_result(rs2);
197            mysql_free_result(rs);
198            mysql_close(db);
199    
200            return ret;
201    }
202    
203    int append_articles_from_db(int32_t start_aid, int global_lock, int article_count_limit)
204    {
205            MYSQL *db = NULL;
206            MYSQL_RES *rs = NULL;
207            MYSQL_ROW row;
208            char sql[SQL_BUFFER_LEN];
209            ARTICLE article;
210            ARTICLE *p_topic;
211            SECTION_LIST *p_section = NULL;
212            int32_t last_sid = 0;
213            char sub_ip[IP_ADDR_LEN];
214            int article_count = 0;
215            int ret = 0;
216            int i;
217    
218            db = db_open();
219            if (db == NULL)
220            {
221                    log_error("db_open() error: %s\n", mysql_error(db));
222                    ret = -1;
223                    goto cleanup;
224            }
225    
226            snprintf(sql, sizeof(sql),
227                             "SELECT bbs.AID, TID, SID, bbs.CID, UID, visible, excerption, ontop, `lock`, "
228                             "transship, username, nickname, title, UNIX_TIMESTAMP(sub_dt) AS sub_dt, "
229                             "sub_ip, bbs_content.content "
230                             "FROM bbs INNER JOIN bbs_content ON bbs.CID = bbs_content.CID "
231                             "WHERE bbs.AID >= %d ORDER BY bbs.AID LIMIT %d",
232                             start_aid, article_count_limit);
233    
234            if (mysql_query(db, sql) != 0)
235            {
236                    log_error("Query article list error: %s\n", mysql_error(db));
237                    ret = -2;
238                    goto cleanup;
239            }
240            if ((rs = mysql_use_result(db)) == NULL)
241            {
242                    log_error("Get article list data failed\n");
243                    ret = -2;
244                    goto cleanup;
245            }
246    
247            // acquire global lock
248            if (global_lock && (ret = section_list_rw_lock(NULL)) < 0)
249            {
250                    log_error("section_list_rw_lock(sid = 0) error\n");
251                    goto cleanup;
252            }
253    
254            while ((row = mysql_fetch_row(rs)))
255            {
256                    memset(&article, 0, sizeof(ARTICLE));
257    
258                    // copy data of article
259                    i = 0;
260    
261                    article.aid = atoi(row[i++]);
262                    article.tid = atoi(row[i++]);
263                    article.sid = atoi(row[i++]);
264                    article.cid = atoi(row[i++]);
265                    article.uid = atoi(row[i++]);
266                    article.visible = (int8_t)atoi(row[i++]);
267                    article.excerption = (int8_t)atoi(row[i++]);
268                    article.ontop = (int8_t)atoi(row[i++]);
269                    article.lock = (int8_t)atoi(row[i++]);
270                    article.transship = (int8_t)atoi(row[i++]);
271    
272                    strncpy(article.username, row[i++], sizeof(article.username) - 1);
273                    article.username[sizeof(article.username) - 1] = '\0';
274                    strncpy(article.nickname, row[i++], sizeof(article.nickname) - 1);
275                    article.nickname[sizeof(article.nickname) - 1] = '\0';
276                    strncpy(article.title, row[i++], sizeof(article.title) - 1);
277                    article.title[sizeof(article.title) - 1] = '\0';
278    
279                    article.sub_dt = atol(row[i++]);
280    
281                    strncpy(sub_ip, row[i++], sizeof(sub_ip) - 1);
282                    sub_ip[sizeof(sub_ip) - 1] = '\0';
283                    ip_mask(sub_ip, 1, '*');
284    
285                    // release lock of last section if different from current one
286                    if (!global_lock && article.sid != last_sid && last_sid != 0)
287                    {
288                            if ((ret = section_list_rw_unlock(p_section)) < 0)
289                            {
290                                    log_error("section_list_rw_unlock(sid=%d) error\n", p_section->sid);
291                                    break;
292                            }
293                    }
294    
295                    if ((p_section = section_list_find_by_sid(article.sid)) == NULL)
296                    {
297                            log_error("section_list_find_by_sid(%d) error: unknown section, try reloading section config\n", article.sid);
298                            ret = ERR_UNKNOWN_SECTION; // Unknown section found
299                            break;
300                    }
301    
302                    if (article.visible != 0 && article.tid != 0)
303                    {
304                            // Check if topic article is visible
305                            p_topic = article_block_find_by_aid(article.tid);
306                            if (p_topic == NULL || p_topic->visible == 0)
307                            {
308                                    // log_error("Set article (aid = %d) as invisible due to invisible or non-existing topic head\n", article.aid);
309                                    article.tid = 0;
310                                    article.visible = 0;
311                            }
312                    }
313    
314                    // acquire lock of current section if different from last one
315                    if (!global_lock && article.sid != last_sid)
316                    {
317                            if ((ret = section_list_rw_lock(p_section)) < 0)
318                            {
319                                    log_error("section_list_rw_lock(sid=0) error\n");
320                                    break;
321                            }
322                    }
323    
324                    // append article to section list
325                    last_sid = article.sid;
326    
327                    if (section_list_append_article(p_section, &article) < 0)
328                    {
329                            log_error("section_list_append_article(sid=%d, aid=%d) error\n",
330                                              p_section->sid, article.aid);
331                            ret = -3;
332                            break;
333                    }
334    
335                    article_count++;
336    
337                    if (article_cache_generate(VAR_ARTICLE_CACHE_DIR, &article, p_section, row[i++], sub_ip, 0) < 0)
338                    {
339                            log_error("article_cache_generate(aid=%d, cid=%d) error\n", article.aid, article.cid);
340                            ret = -4;
341                            break;
342                    }
343            }
344    
345            // release lock of last section
346            if (!global_lock && last_sid != 0)
347            {
348                    if ((ret = section_list_rw_unlock(p_section)) < 0)
349                    {
350                            log_error("section_list_rw_unlock(sid=%d) error\n", p_section->sid);
351                    }
352            }
353    
354            // release global lock
355            if (global_lock && (ret = section_list_rw_unlock(NULL)) < 0)
356            {
357                    log_error("section_list_rw_unlock(sid=0) error\n");
358            }
359    
360    cleanup:
361            mysql_free_result(rs);
362            mysql_close(db);
363    
364            article_cache_cleanup();
365    
366            return (ret < 0 ? ret : article_count);
367    }
368    
369    int set_last_article_op_log_from_db(void)
370    {
371            MYSQL *db = NULL;
372            MYSQL_RES *rs = NULL;
373            MYSQL_ROW row;
374            char sql[SQL_BUFFER_LEN];
375            int ret = 0;
376    
377            db = db_open();
378            if (db == NULL)
379            {
380                    log_error("db_open() error: %s\n", mysql_error(db));
381                    ret = -1;
382                    goto cleanup;
383            }
384    
385            snprintf(sql, sizeof(sql),
386                             "SELECT MID FROM bbs_article_op ORDER BY MID DESC LIMIT 1");
387    
388            if (mysql_query(db, sql) != 0)
389            {
390                    log_error("Query article op error: %s\n", mysql_error(db));
391                    ret = -2;
392                    goto cleanup;
393            }
394            if ((rs = mysql_store_result(db)) == NULL)
395            {
396                    log_error("Get article op data failed\n");
397                    ret = -2;
398                    goto cleanup;
399            }
400    
401            if ((row = mysql_fetch_row(rs)))
402            {
403                    last_article_op_log_mid = atoi(row[0]);
404            }
405    
406    cleanup:
407          mysql_free_result(rs);          mysql_free_result(rs);
408            mysql_close(db);
409    
410            return (ret < 0 ? ret : last_article_op_log_mid);
411    }
412    
413    int apply_article_op_log_from_db(int op_count_limit)
414    {
415            MYSQL *db = NULL;
416            MYSQL_RES *rs = NULL, *rs2 = NULL;
417            MYSQL_ROW row, row2;
418            char sql[SQL_BUFFER_LEN];
419            ARTICLE *p_article;
420            SECTION_LIST *p_section = NULL;
421            SECTION_LIST *p_section_dest;
422            char sub_ip[IP_ADDR_LEN];
423            int32_t last_sid = 0;
424            int32_t sid_dest;
425            int op_count = 0;
426            int ret = 0;
427    
428            db = db_open();
429            if (db == NULL)
430            {
431                    log_error("db_open() error: %s\n", mysql_error(db));
432                    ret = -1;
433                    goto cleanup;
434            }
435    
436            snprintf(sql, sizeof(sql),
437                             "SELECT MID, AID, type FROM bbs_article_op "
438                             "WHERE MID > %d AND type NOT IN ('A') "
439                             "ORDER BY MID LIMIT %d",
440                             last_article_op_log_mid, op_count_limit);
441    
442            if (mysql_query(db, sql) != 0)
443            {
444                    log_error("Query article log error: %s\n", mysql_error(db));
445                    ret = -2;
446                    goto cleanup;
447            }
448            if ((rs = mysql_store_result(db)) == NULL)
449            {
450                    log_error("Get article log data failed\n");
451                    ret = -2;
452                    goto cleanup;
453            }
454    
455            while ((row = mysql_fetch_row(rs)))
456            {
457                    p_article = article_block_find_by_aid(atoi(row[1]));
458                    if (p_article == NULL) // related article has not been appended yet
459                    {
460                            ret = -2;
461                            break;
462                    }
463    
464                    // release lock of last section if different from current one
465                    if (p_article->sid != last_sid && last_sid != 0)
466                    {
467                            if ((ret = section_list_rw_unlock(p_section)) < 0)
468                            {
469                                    log_error("section_list_rw_unlock(sid = %d) error\n", p_section->sid);
470                                    break;
471                            }
472                    }
473    
474                    if ((p_section = section_list_find_by_sid(p_article->sid)) == NULL)
475                    {
476                            log_error("section_list_find_by_sid(%d) error: unknown section, try reloading section config\n", p_article->sid);
477                            ret = ERR_UNKNOWN_SECTION; // Unknown section found
478                            break;
479                    }
480    
481                    // acquire lock of current section if different from last one
482                    if (p_article->sid != last_sid)
483                    {
484                            if ((ret = section_list_rw_lock(p_section)) < 0)
485                            {
486                                    log_error("section_list_rw_lock(sid = 0) error\n");
487                                    break;
488                            }
489                    }
490    
491                    last_sid = p_article->sid;
492    
493                    switch (row[2][0])
494                    {
495                    case 'A': // Add article
496                            log_error("Operation type=A should not be found\n");
497                            break;
498                    case 'D': // Delete article
499                    case 'X': // Delete article by Admin
500                            if (section_list_set_article_visible(p_section, atoi(row[1]), 0) < 0)
501                            {
502                                    log_error("section_list_set_article_visible(sid=%d, aid=%d, visible=0) error\n", p_section->sid, atoi(row[1]));
503                            }
504                            if (section_list_calculate_page(p_section, atoi(row[1])) < 0)
505                            {
506                                    log_error("section_list_calculate_page(aid=%d) error\n", atoi(row[1]));
507                            }
508                            break;
509                    case 'S': // Restore article
510                            if (section_list_set_article_visible(p_section, atoi(row[1]), 1) < 0)
511                            {
512                                    log_error("section_list_set_article_visible(sid=%d, aid=%d, visible=1) error\n", p_section->sid, atoi(row[1]));
513                            }
514                            if (section_list_calculate_page(p_section, atoi(row[1])) < 0)
515                            {
516                                    log_error("section_list_calculate_page(aid=%d) error\n", atoi(row[1]));
517                            }
518                            break;
519                    case 'L': // Lock article
520                            p_article->lock = 1;
521                            break;
522                    case 'U': // Unlock article
523                            p_article->lock = 0;
524                            break;
525                    case 'M': // Modify article
526                            snprintf(sql, sizeof(sql),
527                                             "SELECT bbs.CID, sub_ip, bbs_content.content "
528                                             "FROM bbs INNER JOIN bbs_content ON bbs.CID = bbs_content.CID "
529                                             "WHERE bbs.AID = %d",
530                                             p_article->aid);
531    
532                            if (mysql_query(db, sql) != 0)
533                            {
534                                    log_error("Query article error: %s\n", mysql_error(db));
535                                    ret = -3;
536                                    break;
537                            }
538                            if ((rs2 = mysql_use_result(db)) == NULL)
539                            {
540                                    log_error("Get article data failed\n");
541                                    ret = -3;
542                                    break;
543                            }
544                            if ((row2 = mysql_fetch_row(rs2)))
545                            {
546                                    p_article->cid = atoi(row2[0]);
547    
548                                    strncpy(sub_ip, row2[1], sizeof(sub_ip) - 1);
549                                    sub_ip[sizeof(sub_ip) - 1] = '\0';
550                                    ip_mask(sub_ip, 1, '*');
551    
552                                    if (article_cache_generate(VAR_ARTICLE_CACHE_DIR, p_article, p_section, row2[2], sub_ip, 0) < 0)
553                                    {
554                                            log_error("article_cache_generate(aid=%d, cid=%d) error\n", p_article->aid, p_article->cid);
555                                            ret = -4;
556                                    }
557                            }
558                            else
559                            {
560                                    p_article->cid = 0;
561                                    ret = -4;
562                            }
563                            mysql_free_result(rs2);
564                            rs2 = NULL;
565    
566                            p_article->excerption = 0; // Set excerption = 0 implicitly in case of rare condition
567                            break;
568                    case 'T': // Move article
569                            snprintf(sql, sizeof(sql),
570                                             "SELECT SID FROM bbs WHERE AID = %d",
571                                             p_article->aid);
572    
573                            if (mysql_query(db, sql) != 0)
574                            {
575                                    log_error("Query article error: %s\n", mysql_error(db));
576                                    ret = -3;
577                                    break;
578                            }
579                            if ((rs2 = mysql_store_result(db)) == NULL)
580                            {
581                                    log_error("Get article data failed\n");
582                                    ret = -3;
583                                    break;
584                            }
585                            if ((row2 = mysql_fetch_row(rs2)))
586                            {
587                                    sid_dest = atoi(row2[0]);
588                            }
589                            else
590                            {
591                                    sid_dest = 0;
592                                    ret = -4;
593                            }
594                            mysql_free_result(rs2);
595                            rs2 = NULL;
596    
597                            if (sid_dest > 0 && sid_dest != p_article->sid)
598                            {
599                                    p_section_dest = section_list_find_by_sid(sid_dest);
600                                    if (p_section_dest == NULL)
601                                    {
602                                            ret = ERR_UNKNOWN_SECTION;
603                                            break;
604                                    }
605                                    // acquire lock of dest section
606                                    if ((ret = section_list_rw_lock(p_section_dest)) < 0)
607                                    {
608                                            log_error("section_list_rw_lock(sid = %d) error\n", p_section_dest);
609                                            break;
610                                    }
611                                    // Move topic
612                                    if ((ret = section_list_move_topic(p_section, p_section_dest, p_article->aid)) < 0)
613                                    {
614                                            log_error("section_list_move_topic(src_sid=%d, dest_sid=%d, aid=%d) error (%d), retry in the next loop\n",
615                                                              p_section->sid, p_section_dest->sid, p_article->aid, ret);
616                                    }
617                                    // release lock of dest section
618                                    if (section_list_rw_unlock(p_section_dest) < 0)
619                                    {
620                                            log_error("section_list_rw_unlock(sid = %d) error\n", p_section_dest);
621                                            ret = -1;
622                                    }
623                            }
624                            break;
625                    case 'E': // Set article as excerption
626                            p_article->excerption = 1;
627                            break;
628                    case 'O': // Unset article as excerption
629                            p_article->excerption = 0;
630                            break;
631                    case 'F': // Set article on top
632                    case 'V': // Unset article on top
633                            p_article->ontop = (row[2][0] == 'F' ? 1 : 0);
634                            if (section_list_update_article_ontop(p_section, p_article) < 0)
635                            {
636                                    log_error("section_list_update_article_ontop(sid=%d, aid=%d) error\n",
637                                                      p_section->sid, p_article->aid);
638                            }
639                            break;
640                    case 'Z': // Set article as trnasship
641                            p_article->transship = 1;
642                            break;
643                    default:
644                            // log_error("Operation type=%s unknown, mid=%s\n", row[2], row[0]);
645                            break;
646                    }
647    
648                    if (ret < 0)
649                    {
650                            break;
651                    }
652    
653                    // Update MID with last successfully proceeded article_op_log
654                    last_article_op_log_mid = atoi(row[0]);
655    
656                    op_count++;
657            }
658    
659            // release lock of last section
660            if (last_sid != 0)
661            {
662                    if ((ret = section_list_rw_unlock(p_section)) < 0)
663                    {
664                            log_error("section_list_rw_unlock(sid = %d) error\n", p_section->sid);
665                    }
666            }
667    
668    cleanup:
669            mysql_free_result(rs2);
670            mysql_free_result(rs);
671            mysql_close(db);
672    
673            return (ret < 0 ? ret : op_count);
674    }
675    
676    static void section_list_ex_menu_set_cleanup(void)
677    {
678            int i;
679    
680            for (i = 0; i < p_section_list_pool->section_count; i++)
681            {
682                    if (p_section_list_pool->sections[i].ex_menu_tm > 0)
683                    {
684                            unload_menu(&(p_section_list_pool->sections[i].ex_menu_set));
685                    }
686            }
687    }
688    
689    int section_list_loader_launch(void)
690    {
691            struct sigaction act = {0};
692            int pid;
693            int ret;
694            int32_t last_aid;
695            int article_count;
696            int load_count;
697            int last_mid;
698            time_t tm_section_list_reload = 0;
699            time_t tm_user_list_reload = time(NULL);
700            time_t tm_user_online_list_reload = time(NULL);
701    
702            if (section_list_loader_pid != 0)
703            {
704                    log_error("section_list_loader already running, pid = %d\n", section_list_loader_pid);
705                    return -2;
706            }
707    
708            pid = fork();
709    
710            if (pid > 0) // Parent process
711            {
712                    SYS_child_process_count++;
713                    section_list_loader_pid = pid;
714                    log_common("Section list loader process (pid = %d) start\n", pid);
715                    return 0;
716            }
717            else if (pid < 0) // Error
718            {
719                    log_error("fork() error (%d)\n", errno);
720                    return -1;
721            }
722    
723            // Child process
724            SYS_child_process_count = 0;
725    
726            // Detach menu in shared memory
727            detach_menu_shm(&bbs_menu);
728            detach_menu_shm(&top10_menu);
729    
730            // Set signal handler
731            act.sa_handler = SIG_IGN;
732            if (sigaction(SIGHUP, &act, NULL) == -1)
733            {
734                    log_error("set signal action of SIGHUP error: %d\n", errno);
735            }
736            act.sa_handler = SIG_DFL;
737            if (sigaction(SIGCHLD, &act, NULL) == -1)
738            {
739                    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
748            while (!SYS_server_exit)
749            {
750                    tm_section_list_reload = time(NULL);
751    
752                    if (SYS_conf_reload)
753                    {
754                            SYS_conf_reload = 0;
755    
756                            // Load section config
757                            if (load_section_config_from_db(0) < 0)
758                            {
759                                    log_error("load_section_config_from_db(0) error\n");
760                            }
761                            else
762                            {
763                                    log_common("Reload section config successfully\n");
764                            }
765                    }
766    
767                    // Load section articles
768                    article_count = article_block_article_count();
769    
770                    do
771                    {
772                            last_aid = article_block_last_aid();
773    
774                            if ((ret = append_articles_from_db(last_aid + 1, 0, LOAD_ARTICLE_COUNT_LIMIT)) < 0)
775                            {
776                                    log_error("append_articles_from_db(%d, 0, %d) error\n", last_aid + 1, LOAD_ARTICLE_COUNT_LIMIT);
777    
778                                    if (ret == ERR_UNKNOWN_SECTION)
779                                    {
780                                            SYS_conf_reload = 1; // Force reload section_list
781                                    }
782                            }
783                    } while (ret == LOAD_ARTICLE_COUNT_LIMIT);
784    
785                    load_count = article_block_article_count() - article_count;
786                    if (load_count > 0)
787                    {
788                            log_common("Incrementally load %d articles, last_aid = %d\n", load_count, article_block_last_aid());
789                    }
790    
791                    if (SYS_conf_reload)
792                    {
793                            continue;
794                    }
795    
796                    // Load article_op log
797                    last_mid = last_article_op_log_mid;
798    
799                    do
800                    {
801                            if ((ret = apply_article_op_log_from_db(LOAD_ARTICLE_COUNT_LIMIT)) < 0)
802                            {
803                                    log_error("apply_article_op_log_from_db() error\n");
804    
805                                    if (ret == ERR_UNKNOWN_SECTION)
806                                    {
807                                            SYS_conf_reload = 1; // Force reload section_list
808                                    }
809                            }
810                    } while (ret == LOAD_ARTICLE_COUNT_LIMIT);
811    
812                    if (last_article_op_log_mid > last_mid)
813                    {
814                            log_common("Proceeded %d article logs, last_mid = %d\n", last_article_op_log_mid - last_mid, last_article_op_log_mid);
815                    }
816    
817                    // Reload user list
818                    if (time(NULL) - tm_user_list_reload >= BBS_user_list_load_interval)
819                    {
820                            if (user_list_pool_reload(0) < 0)
821                            {
822                                    log_error("user_list_pool_reload(all_user) error\n");
823                            }
824    
825                            if (user_stat_update() < 0)
826                            {
827                                    log_error("user_stat_update() error\n");
828                            }
829    
830                            tm_user_list_reload = time(NULL);
831                    }
832    
833                    // Reload user online list
834                    if (time(NULL) - tm_user_online_list_reload >= BBS_user_online_list_load_interval)
835                    {
836                            if (user_list_pool_reload(1) < 0)
837                            {
838                                    log_error("user_list_pool_reload(online_user) error\n");
839                            }
840    
841                            tm_user_online_list_reload = time(NULL);
842                    }
843    
844                    // Wait for BBS_section_list_load_interval seconds
845                    while (!SYS_server_exit && time(NULL) - tm_section_list_reload < BBS_section_list_load_interval)
846                    {
847                            sleep(1);
848                    }
849            }
850    
851            // Child process exit
852    
853            article_cache_cleanup();
854    
855            // gen_ex_menu cleanup
856            section_list_ex_menu_set_cleanup();
857    
858            // Detach data pools shm
859            detach_section_list_shm();
860            detach_article_block_shm();
861            detach_trie_dict_shm();
862            detach_user_list_pool_shm();
863    
864            log_common("Section list loader process exit normally\n");
865            log_end();
866    
867            section_list_loader_pid = 0;
868    
869            _exit(0);
870    
871          return 0;          return 0;
872  }  }
873    
874    int query_section_articles(SECTION_LIST *p_section, int page_id, ARTICLE *p_articles[],
875                                                       int *p_article_count, int *p_page_count, int *p_ontop_start_offset)
876    {
877            ARTICLE *p_article;
878            ARTICLE *p_next_page_first_article;
879            int ret = 0;
880            int i;
881    
882            if (p_section == NULL || p_articles == NULL || p_article_count == NULL || p_page_count == NULL || p_ontop_start_offset == NULL)
883            {
884                    log_error("NULL pointer error\n");
885                    return -1;
886            }
887    
888            // acquire lock of section
889            if ((ret = section_list_rd_lock(p_section)) < 0)
890            {
891                    log_error("section_list_rd_lock(sid = %d) error\n", p_section->sid);
892                    return -2;
893            }
894    
895            *p_page_count = section_list_page_count_with_ontop(p_section);
896            *p_article_count = 0;
897            *p_ontop_start_offset = BBS_article_limit_per_page;
898    
899            if (p_section->visible_article_count == 0)
900            {
901                    // empty section
902            }
903            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);
907    #endif
908                    ret = -3;
909            }
910            else
911            {
912                    ret = page_id;
913    
914                    if (page_id <= p_section->page_count - 1)
915                    {
916                            p_article = p_section->p_page_first_article[page_id];
917                            p_next_page_first_article =
918                                    (page_id == p_section->page_count - 1 ? p_section->p_article_head : p_section->p_page_first_article[page_id + 1]);
919    
920                            do
921                            {
922                                    if (p_article->visible)
923                                    {
924                                            p_articles[*p_article_count] = p_article;
925                                            (*p_article_count)++;
926                                    }
927                                    p_article = p_article->p_next;
928                            } while (p_article != p_next_page_first_article && (*p_article_count) <= BBS_article_limit_per_page);
929    
930                            if (*p_article_count != (page_id < p_section->page_count - 1 ? BBS_article_limit_per_page : p_section->last_page_visible_article_count))
931                            {
932                                    log_error("Inconsistent visible article count %d detected in section %d page %d\n", *p_article_count, p_section->sid, page_id);
933                            }
934                    }
935    
936                    *p_ontop_start_offset = *p_article_count;
937    
938                    // Append ontop articles
939                    if (page_id >= p_section->page_count - 1)
940                    {
941                            i = (page_id == p_section->page_count - 1
942                                             ? 0
943                                             : (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)
945                            {
946                                    p_articles[*p_article_count] = p_section->p_ontop_articles[i++];
947                                    (*p_article_count)++;
948                            }
949                    }
950            }
951    
952            // release lock of section
953            if (section_list_rd_unlock(p_section) < 0)
954            {
955                    log_error("section_list_rd_unlock(sid = %d) error\n", p_section->sid);
956                    ret = -2;
957            }
958    
959            return ret;
960    }
961    
962    int locate_article_in_section(SECTION_LIST *p_section, const ARTICLE *p_article_cur, int direction, int step,
963                                                              int *p_page_id, int *p_visible_offset, int *p_article_count)
964    {
965            const ARTICLE *p_article = NULL;
966            const ARTICLE *p_article_last = NULL;
967            ARTICLE *p_tmp;
968            int32_t aid = 0;
969            int page_id = 0;
970            int offset = 0;
971            int ret = 0;
972            int i;
973    
974            if (p_section == NULL || p_article_cur == NULL || p_page_id == NULL || p_visible_offset == NULL || p_article_count == NULL)
975            {
976                    log_error("NULL pointer error\n");
977                    return -1;
978            }
979    
980            // acquire lock of section
981            if ((ret = section_list_rd_lock(p_section)) < 0)
982            {
983                    log_error("section_list_rd_lock(sid = %d) error\n", p_section->sid);
984                    return -2;
985            }
986    
987            if (direction == 0)
988            {
989                    aid = p_article_cur->aid;
990            }
991            else if (direction == 1)
992            {
993                    for (p_article_last = p_article_cur, p_article = p_article_cur->p_topic_next;
994                             step > 0 && p_article->aid > p_article_cur->aid;
995                             p_article = p_article->p_topic_next)
996                    {
997                            if (p_article->visible)
998                            {
999                                    step--;
1000                                    p_article_last = p_article;
1001                            }
1002                    }
1003                    p_article = p_article_last;
1004    
1005                    aid = (p_article->aid > p_article_cur->aid && p_article->visible ? p_article->aid : 0);
1006            }
1007            else if (direction == -1)
1008            {
1009                    for (p_article_last = p_article_cur, p_article = p_article_cur->p_topic_prior;
1010                             step > 0 && p_article->aid < p_article_cur->aid;
1011                             p_article = p_article->p_topic_prior)
1012                    {
1013                            if (p_article->visible)
1014                            {
1015                                    step--;
1016                                    p_article_last = p_article;
1017                            }
1018                    }
1019                    p_article = p_article_last;
1020    
1021                    aid = (p_article->aid < p_article_cur->aid && p_article->visible ? p_article->aid : 0);
1022            }
1023    
1024            p_article = NULL;
1025    
1026            if (aid > 0)
1027            {
1028                    p_article = section_list_find_article_with_offset(p_section, aid, &page_id, &offset, &p_tmp);
1029                    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);
1032    
1033                            p_article = p_section->p_page_first_article[page_id];
1034                            for (i = 0; i < *p_article_count && p_article != NULL;)
1035                            {
1036                                    if (p_article->visible)
1037                                    {
1038                                            if (p_article->aid == aid)
1039                                            {
1040                                                    *p_page_id = page_id;
1041                                                    *p_visible_offset = i;
1042                                                    break;
1043                                            }
1044                                            i++;
1045                                            if (i >= *p_article_count)
1046                                            {
1047                                                    log_error("Visible article (aid=%d) not found in page %d\n", aid, page_id);
1048                                                    p_article = NULL;
1049                                                    break;
1050                                            }
1051                                    }
1052    
1053                                    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
1062                            *p_article_count = section_list_page_article_count_with_ontop(p_section, page_id);
1063                    }
1064            }
1065    
1066            // release lock of section
1067            if (section_list_rd_unlock(p_section) < 0)
1068            {
1069                    log_error("section_list_rd_unlock(sid = %d) error\n", p_section->sid);
1070                    ret = -2;
1071            }
1072    
1073            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)
1119    {
1120            ARTICLE *p_article;
1121            int ret = 0;
1122    
1123            if (p_section == NULL || p_article_cur == NULL || pp_article_unread == NULL)
1124            {
1125                    log_error("NULL pointer error\n");
1126                    return -1;
1127            }
1128    
1129            if (p_article_cur->sid != p_section->sid)
1130            {
1131                    log_error("Inconsistent SID\n");
1132                    return -1;
1133            }
1134    
1135            // acquire lock of section
1136            if ((ret = section_list_rd_lock(p_section)) < 0)
1137            {
1138                    log_error("section_list_rd_lock(sid = %d) error\n", p_section->sid);
1139                    return -2;
1140            }
1141    
1142            *pp_article_unread = NULL;
1143    
1144            for (p_article = p_article_cur->p_next; p_article != NULL && p_article != p_article_cur; p_article = p_article->p_next)
1145            {
1146                    if (p_article->visible && p_article->uid != BBS_priv.uid && !article_view_log_is_viewed(p_article->aid, &BBS_article_view_log))
1147                    {
1148                            *pp_article_unread = p_article;
1149                            break;
1150                    }
1151            }
1152    
1153            // release lock of section
1154            if (section_list_rd_unlock(p_section) < 0)
1155            {
1156                    log_error("section_list_rd_unlock(sid = %d) error\n", p_section->sid);
1157                    return -2;
1158            }
1159    
1160            return (p_article != NULL && p_article != p_article_cur ? 1 : 0);
1161    }
1162    
1163    int scan_article_in_section_by_uid(SECTION_LIST *p_section, const ARTICLE *p_article_cur,
1164                                                                       int direction, int32_t uid, const ARTICLE **pp_article)
1165    {
1166            ARTICLE *p_article;
1167            int ret = 0;
1168    
1169            if (p_section == NULL || p_article_cur == NULL || pp_article == NULL)
1170            {
1171                    log_error("NULL pointer error\n");
1172                    return -1;
1173            }
1174    
1175            if (p_article_cur->sid != p_section->sid)
1176            {
1177                    log_error("Inconsistent SID\n");
1178                    return -1;
1179            }
1180    
1181            // acquire lock of section
1182            if ((ret = section_list_rd_lock(p_section)) < 0)
1183            {
1184                    log_error("section_list_rd_lock(sid = %d) error\n", p_section->sid);
1185                    return -2;
1186            }
1187    
1188            *pp_article = NULL;
1189    
1190            if (direction >= 0)
1191            {
1192                    for (p_article = p_article_cur->p_next; p_article != NULL && p_article != p_article_cur; p_article = p_article->p_next)
1193                    {
1194                            if (p_article->visible && p_article->uid == uid)
1195                            {
1196                                    *pp_article = p_article;
1197                                    break;
1198                            }
1199                    }
1200            }
1201            else // direction < 0
1202            {
1203                    for (p_article = p_article_cur->p_prior; p_article != NULL && p_article != p_article_cur; p_article = p_article->p_prior)
1204                    {
1205                            if (p_article->visible && p_article->uid == uid)
1206                            {
1207                                    *pp_article = p_article;
1208                                    break;
1209                            }
1210                    }
1211            }
1212    
1213            // release lock of section
1214            if (section_list_rd_unlock(p_section) < 0)
1215            {
1216                    log_error("section_list_rd_unlock(sid = %d) error\n", p_section->sid);
1217                    return -2;
1218            }
1219    
1220            return (p_article != NULL && p_article != p_article_cur ? 1 : 0);
1221    }
1222    
1223    int scan_article_in_section_by_username(SECTION_LIST *p_section, const ARTICLE *p_article_cur,
1224                                                                                    int direction, const char *username, const ARTICLE **pp_article)
1225    {
1226            ARTICLE *p_article;
1227            int ret = 0;
1228    
1229            if (p_section == NULL || p_article_cur == NULL || username == NULL || pp_article == NULL)
1230            {
1231                    log_error("NULL pointer error\n");
1232                    return -1;
1233            }
1234    
1235            if (p_article_cur->sid != p_section->sid)
1236            {
1237                    log_error("Inconsistent SID\n");
1238                    return -1;
1239            }
1240    
1241            // acquire lock of section
1242            if ((ret = section_list_rd_lock(p_section)) < 0)
1243            {
1244                    log_error("section_list_rd_lock(sid = %d) error\n", p_section->sid);
1245                    return -2;
1246            }
1247    
1248            *pp_article = NULL;
1249    
1250            if (direction >= 0)
1251            {
1252                    for (p_article = p_article_cur->p_next; p_article != NULL && p_article != p_article_cur; p_article = p_article->p_next)
1253                    {
1254                            if (p_article->visible && strcasecmp(p_article->username, username) == 0)
1255                            {
1256                                    *pp_article = p_article;
1257                                    break;
1258                            }
1259                    }
1260            }
1261            else // direction < 0
1262            {
1263                    for (p_article = p_article_cur->p_prior; p_article != NULL && p_article != p_article_cur; p_article = p_article->p_prior)
1264                    {
1265                            if (p_article->visible && strcasecmp(p_article->username, username) == 0)
1266                            {
1267                                    *pp_article = p_article;
1268                                    break;
1269                            }
1270                    }
1271            }
1272    
1273            // release lock of section
1274            if (section_list_rd_unlock(p_section) < 0)
1275            {
1276                    log_error("section_list_rd_unlock(sid = %d) error\n", p_section->sid);
1277                    return -2;
1278            }
1279    
1280            return (p_article != NULL && p_article != p_article_cur ? 1 : 0);
1281    }
1282    
1283    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)
1285    {
1286            ARTICLE *p_article;
1287            int ret = 0;
1288    
1289            if (p_section == NULL || p_article_cur == NULL || title == NULL || pp_article == NULL)
1290            {
1291                    log_error("NULL pointer error\n");
1292                    return -1;
1293            }
1294    
1295            if (p_article_cur->sid != p_section->sid)
1296            {
1297                    log_error("Inconsistent SID\n");
1298                    return -1;
1299            }
1300    
1301            // acquire lock of section
1302            if ((ret = section_list_rd_lock(p_section)) < 0)
1303            {
1304                    log_error("section_list_rd_lock(sid = %d) error\n", p_section->sid);
1305                    return -2;
1306            }
1307    
1308            *pp_article = NULL;
1309    
1310            if (direction >= 0)
1311            {
1312                    for (p_article = p_article_cur->p_next; p_article != NULL && p_article != p_article_cur; p_article = p_article->p_next)
1313                    {
1314                            if (p_article->visible && strcasestr(p_article->title, title) != NULL)
1315                            {
1316                                    *pp_article = p_article;
1317                                    break;
1318                            }
1319                    }
1320            }
1321            else // direction < 0
1322            {
1323                    for (p_article = p_article_cur->p_prior; p_article != NULL && p_article != p_article_cur; p_article = p_article->p_prior)
1324                    {
1325                            if (p_article->visible && strcasestr(p_article->title, title) != NULL)
1326                            {
1327                                    *pp_article = p_article;
1328                                    break;
1329                            }
1330                    }
1331            }
1332    
1333            // release lock of section
1334            if (section_list_rd_unlock(p_section) < 0)
1335            {
1336                    log_error("section_list_rd_unlock(sid = %d) error\n", p_section->sid);
1337                    return -2;
1338            }
1339    
1340            return (p_article != NULL && p_article != p_article_cur ? 1 : 0);
1341    }
1342    
1343    int get_section_ex_menu_set(SECTION_LIST *p_section, MENU_SET *p_ex_menu_set)
1344    {
1345            int ret = 0;
1346    
1347            if (p_section == NULL || p_ex_menu_set == NULL)
1348            {
1349                    log_error("NULL pointer error\n");
1350                    return -1;
1351            }
1352    
1353            // acquire lock of section
1354            if ((ret = section_list_rd_lock(p_section)) < 0)
1355            {
1356                    log_error("section_list_rd_lock(sid = %d) error\n", p_section->sid);
1357                    return -2;
1358            }
1359    
1360            memcpy(p_ex_menu_set, &(p_section->ex_menu_set), sizeof(p_section->ex_menu_set));
1361    
1362            // release lock of section
1363            if (section_list_rd_unlock(p_section) < 0)
1364            {
1365                    log_error("section_list_rd_unlock(sid = %d) error\n", p_section->sid);
1366                    ret = -2;
1367            }
1368    
1369            return ret;
1370    }


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

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