/[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.20 by sysadm, Wed Apr 30 09:18:19 2025 UTC Revision 1.24 by sysadm, Wed May 7 05:35:01 2025 UTC
# Line 1  Line 1 
1  /***************************************************************************  /***************************************************************************
2                                                    main.c  -  description                                                    main.c  -  description
3                                                           -------------------                                                           -------------------
4          begin                : Mon Oct 11 2004          Copyright            : (C) 2004-2025 by Leaflet
5          copyright            : (C) 2004 by Leaflet          Email                : leaflet@leafok.com
         email                : leaflet@leafok.com  
6   ***************************************************************************/   ***************************************************************************/
7    
8  /***************************************************************************  /***************************************************************************
9   *                                                                         *   *                                                                         *
10   *   This program is free software; you can redistribute it and/or modify  *   *   This program is free software; you can redistribute it and/or modify  *
11   *   it under the terms of the GNU General Public License as published by  *   *   it under the terms of the GNU General Public License as published by  *
12   *   the Free Software Foundation; either version 2 of the License, or     *   *   the Free Software Foundation; either version 3 of the License, or     *
13   *   (at your option) any later version.                                   *   *   (at your option) any later version.                                   *
14   *                                                                         *   *                                                                         *
15   ***************************************************************************/   ***************************************************************************/
# Line 26  Line 25 
25  #include <signal.h>  #include <signal.h>
26  #include <string.h>  #include <string.h>
27  #include <unistd.h>  #include <unistd.h>
28    #include <libgen.h>
29  #include <sys/types.h>  #include <sys/types.h>
30  #include <sys/stat.h>  #include <sys/stat.h>
31    
# Line 48  void arg_error(void) Line 48  void arg_error(void)
48    
49  int main(int argc, char *argv[])  int main(int argc, char *argv[])
50  {  {
51          char log_dir[256], file_log_std[256], file_log_error[256], file_config[256];          char file_path_temp[FILE_PATH_LEN];
52          int i, j;          int daemon = 1;
53          int daemon = 1, std_log_redir = 0, error_log_redir = 0;          int std_log_redir = 0;
54            int error_log_redir = 0;
55    
56          // Parse args          // Parse args
57          for (i = 1; i < argc; i++)          for (int i = 1; i < argc; i++)
58          {          {
59                  switch (argv[i][0])                  switch (argv[i][0])
60                  {                  {
61                  case '-':                  case '-':
62                          if (argv[i][1] != '-')                          if (argv[i][1] != '-')
63                          {                          {
64                                  for (j = 1; j < strlen(argv[i]); j++)                                  for (int j = 1; j < strlen(argv[i]); j++)
65                                  {                                  {
66                                          switch (argv[i][j])                                          switch (argv[i][j])
67                                          {                                          {
# Line 116  int main(int argc, char *argv[]) Line 117  int main(int argc, char *argv[])
117          }          }
118    
119          // Change current dir          // Change current dir
120          strncpy(app_home_dir, argv[0], strrchr(argv[0], '/') - argv[0] + 1);          strncpy(file_path_temp, argv[0], sizeof(file_path_temp) - 1);
121          strcat(app_home_dir, "../");          file_path_temp[sizeof(file_path_temp) - 1] = '\0';
122          chdir(app_home_dir);  
123            chdir(dirname(file_path_temp));
124            chdir("..");
125    
126          // Initialize log          // Initialize log
127          strcpy(app_temp_dir, "var/");          if (log_begin(LOG_FILE_INFO, LOG_FILE_ERROR) < 0)
128          mkdir(app_temp_dir, 0750);          {
         strcpy(log_dir, app_home_dir);  
         strcat(log_dir, "log/");  
         strcpy(file_log_std, log_dir);  
         strcpy(file_log_error, log_dir);  
         strcat(file_log_std, "bbsd.log");  
         strcat(file_log_error, "error.log");  
         mkdir(log_dir, 0750);  
         if (log_begin(file_log_std, file_log_error) < 0)  
129                  exit(-1);                  exit(-1);
130            }
131    
132          if ((!daemon) && std_log_redir)          if ((!daemon) && std_log_redir)
133            {
134                  log_std_redirect(2);                  log_std_redirect(2);
135            }
136          if ((!daemon) && error_log_redir)          if ((!daemon) && error_log_redir)
137            {
138                  log_err_redirect(3);                  log_err_redirect(3);
139            }
140    
141          // Load configuration          // Load configuration
142          strcpy(file_config, app_home_dir);          if (load_conf("conf/bbsd.conf") < 0)
         strcat(file_config, "conf/bbsd.conf");  
         if (load_conf(file_config) < 0)  
143                  exit(-2);                  exit(-2);
144    
145          // Load menus          // Load menus
146          strcpy(file_config, app_home_dir);          if (load_menu(&bbs_menu, "conf/menu.conf") < 0)
         strcat(file_config, "conf/menu.conf");  
         if (load_menu(&bbs_menu, file_config) < 0)  
147                  exit(-3);                  exit(-3);
148    
149          // Set signal handler          // Set signal handler
# Line 161  int main(int argc, char *argv[]) Line 157  int main(int argc, char *argv[])
157          // Wait for child process exit          // Wait for child process exit
158          while (SYS_child_process_count > 0)          while (SYS_child_process_count > 0)
159          {          {
160                  log_std(".");                  log_std("Waiting for %d child process to exit\n", SYS_child_process_count);
161                  sleep(1);                  sleep(1);
162          }          }
163    
164          // Cleanup          // Cleanup
165          unload_menu(&bbs_menu);          unload_menu(&bbs_menu);
         rmdir(app_temp_dir);  
166    
167            log_std("Main process exit\n");
168            
169          return 0;          return 0;
170  }  }


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

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