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

Diff of /lbbs/src/main.c

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

Revision 1.43 by sysadm, Tue May 27 00:54:01 2025 UTC Revision 1.51 by sysadm, Wed Jun 4 14:01:29 2025 UTC
# Line 23  Line 23 
23  #include "menu.h"  #include "menu.h"
24  #include "file_loader.h"  #include "file_loader.h"
25  #include "section_list_loader.h"  #include "section_list_loader.h"
26    #include <errno.h>
27  #include <stdlib.h>  #include <stdlib.h>
28  #include <signal.h>  #include <signal.h>
29  #include <string.h>  #include <string.h>
# Line 55  int main(int argc, char *argv[]) Line 56  int main(int argc, char *argv[])
56          int std_log_redir = 0;          int std_log_redir = 0;
57          int error_log_redir = 0;          int error_log_redir = 0;
58          FILE *fp;          FILE *fp;
59            int ret;
60            int last_aid;
61    
62          // Parse args          // Parse args
63          for (int i = 1; i < argc; i++)          for (int i = 1; i < argc; i++)
# Line 75  int main(int argc, char *argv[]) Line 78  int main(int argc, char *argv[])
78                                                  app_help();                                                  app_help();
79                                                  return 0;                                                  return 0;
80                                          case 'v':                                          case 'v':
81                                                  puts(app_version);                                                  puts(APP_NAME_VER);
82                                                  return 0;                                                  return 0;
83                                          default:                                          default:
84                                                  arg_error();                                                  arg_error();
# Line 97  int main(int argc, char *argv[]) Line 100  int main(int argc, char *argv[])
100                                  }                                  }
101                                  if (strcmp(argv[i] + 2, "version") == 0)                                  if (strcmp(argv[i] + 2, "version") == 0)
102                                  {                                  {
103                                          puts(app_version);                                          puts(APP_NAME_VER);
104                                          return 0;                                          return 0;
105                                  }                                  }
106                                  if (strcmp(argv[i] + 2, "display-log") == 0)                                  if (strcmp(argv[i] + 2, "display-log") == 0)
# Line 134  int main(int argc, char *argv[]) Line 137  int main(int argc, char *argv[])
137    
138          if ((!daemon) && std_log_redir)          if ((!daemon) && std_log_redir)
139          {          {
140                  log_std_redirect(STDERR_FILENO);                  log_common_redir(STDERR_FILENO);
141          }          }
142          if ((!daemon) && error_log_redir)          if ((!daemon) && error_log_redir)
143          {          {
144                  log_err_redirect(STDERR_FILENO);                  log_error_redir(STDERR_FILENO);
145          }          }
146    
147            log_common("BBS Server (%s) is staring...\n", APP_NAME_VER);
148    
149          // Load configuration          // Load configuration
150          if (load_conf(CONF_BBSD) < 0)          if (load_conf(CONF_BBSD) < 0)
151          {          {
152                  return -2;                  return -2;
153          }          }
154    
155            // Check article cache dir
156            ret = mkdir(VAR_ARTICLE_CACHE_DIR, 0750);
157            if (ret == -1 && errno != EEXIST)
158            {
159                    log_error("mkdir(%s) error (%d)\n", VAR_ARTICLE_CACHE_DIR, errno);
160                    goto cleanup;
161            }
162    
163          // Initialize data pools          // Initialize data pools
164          if ((fp = fopen(VAR_TRIE_DICT_SHM, "w")) == NULL)          if ((fp = fopen(VAR_TRIE_DICT_SHM, "w")) == NULL)
165          {          {
# Line 222  int main(int argc, char *argv[]) Line 235  int main(int argc, char *argv[])
235                  goto cleanup;                  goto cleanup;
236          }          }
237    
238          // Load section config          set_last_article_op_log_from_db();
239          if (append_articles_from_db(0, 1) < 0)          last_aid = 0;
240    
241            // Load section articles
242            do
243          {          {
244                  log_error("append_articles_from_db(0, 1) error\n");                  if ((ret = append_articles_from_db(last_aid + 1, 1, LOAD_ARTICLE_COUNT_LIMIT)) < 0)
245                  goto cleanup;                  {
246          }                          log_error("append_articles_from_db(0, 1, %d) error\n", LOAD_ARTICLE_COUNT_LIMIT);
247                            goto cleanup;
248                    }
249    
250                    last_aid = article_block_last_aid();
251            } while (ret == LOAD_ARTICLE_COUNT_LIMIT);
252    
253          log_std("Debug: last_aid = %d\n", article_block_last_aid());          log_common("Initially load %d articles, last_aid = %d\n", article_block_article_count(), article_block_last_aid());
254    
255          // Set signal handler          // Set signal handler
256          signal(SIGHUP, sig_hup_handler);          signal(SIGHUP, sig_hup_handler);
257          signal(SIGCHLD, sig_chld_handler);          signal(SIGCHLD, sig_chld_handler);
258          signal(SIGTERM, sig_term_handler);          signal(SIGTERM, sig_term_handler);
259    
260            // Launch section_list_loader process
261            if (section_list_loader_launch() < 0)
262            {
263                    log_error("section_list_loader_launch() error\n");
264                    goto cleanup;
265            }
266    
267          // Initialize socket server          // Initialize socket server
268          net_server(BBS_address, BBS_port);          net_server(BBS_address, BBS_port);
269    
# Line 266  cleanup: Line 294  cleanup:
294                  log_error("unlink(%s) error\n", VAR_SECTION_LIST_SHM);                  log_error("unlink(%s) error\n", VAR_SECTION_LIST_SHM);
295          }          }
296    
297          log_std("Main process exit normally\n");          log_common("Main process exit normally\n");
298    
299          return 0;          return 0;
300  }  }


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

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