/[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.3 by sysadm, Mon Oct 18 11:34:15 2004 UTC Revision 1.7 by sysadm, Fri Oct 22 15:20:32 2004 UTC
# Line 15  Line 15 
15   *                                                                         *   *                                                                         *
16   ***************************************************************************/   ***************************************************************************/
17    
18    #include "bbs.h"
19  #include "common.h"  #include "common.h"
20    #include "io.h"
21    #include <string.h>
22    
23  char app_home_dir[256];  void
24    app_help(void)
25    {
26      prints (
27        "Usage: bbsd [-fhv] [...]\n\n"
28        "-f\t--foreground\t\tForce program run in foreground\n"
29        "-h\t--help\t\t\tDisplay this help message\n"
30        "-v\t--version\t\tDisplay version information\n"
31        "\t--display-log\t\tDisplay standard log information\n"
32        "\t--display-error-log\tDisplay error log information\n"
33        "\n    If meet any bug, please report to <leaflet@leafok.com>\n\n"
34      );
35    }
36    
37    void
38    arg_error(void)
39    {
40      prints ("Invalid arguments\n");
41      app_help();
42    }
43    
44  int  int
45  main (int argc, char *argv[])  main (int argc, char *argv[])
46  {  {
47    char log_dir[256], file_log_std[256], file_log_error[256];    char log_dir[256], file_log_std[256], file_log_error[256], file_config[256];
48        int i,j;
49      int daemon = 1, std_log_redir = 0, error_log_redir = 0;
50    
51      //Parse args
52      for (i=1; i<argc; i++)
53      {
54        switch (argv[i][0])
55        {
56          case '-':
57            if (argv[i][1] != '-')
58            {
59            for (j=1; j<strlen(argv[i]); j++)
60            {
61              switch (argv[i][j])
62              {
63                case 'f':
64                  daemon = 0;
65                  break;
66                case 'h':
67                  app_help();
68                  exit(0);
69                case 'v':
70                  puts (app_version);
71                  exit(0);
72                default:
73                  arg_error();
74                  exit(1);
75              }
76            }
77            }
78            else
79            {
80              if (strcmp(argv[i]+2, "foreground") == 0)
81              {
82                  daemon = 0;
83                  break;
84              }
85              if (strcmp(argv[i]+2, "help") == 0)
86              {
87                app_help();
88                exit(0);
89              }
90              if (strcmp(argv[i]+2, "version") == 0)
91              {
92                puts (app_version);
93                exit(0);
94              }
95              if (strcmp(argv[i]+2, "display-log") == 0)
96              {
97                std_log_redir = 1;
98              }
99              if (strcmp(argv[i]+2, "display-error-log") == 0)
100              {
101                error_log_redir = 1;
102              }
103            }
104            break;
105        }
106      }
107                
108    //Initialize daemon    //Initialize daemon
109    init_daemon ();    if (daemon)
110        init_daemon ();
111    
112    //Initialize log    //Initialize log
113    strncpy(app_home_dir,argv[0],rindex(argv[0],'/')-argv[0]+1);    strncpy(app_home_dir, argv[0], rindex(argv[0],'/')-argv[0]+1);
114    strcpy(log_dir,app_home_dir);    strcpy(log_dir, app_home_dir);
115    strcat(log_dir,"log/");    strcat(log_dir, "log/");
116    strcpy(file_log_std,log_dir);    strcpy(file_log_std, log_dir);
117    strcpy(file_log_error,log_dir);    strcpy(file_log_error, log_dir);
118    strcat(file_log_std,"bbsd.log");    strcat(file_log_std, "bbsd.log");
119    strcat(file_log_error,"error.log");    strcat(file_log_error, "error.log");
120    mkdir(log_dir,0700);    mkdir(log_dir,0700);
121    log_begin(file_log_std,file_log_error);    if (log_begin(file_log_std,file_log_error)<0)
122        exit(-1);
123      if ((!daemon) && std_log_redir)
124        log_std_redirect(2);
125      if ((!daemon) && error_log_redir)
126        log_err_redirect(3);
127    
128      //Load configuration
129      strcpy(file_config, app_home_dir);
130      strcat(file_config, "conf/bbsd.conf");
131      if (load_conf(file_config)<0)
132        exit(-2);
133    
134    //Initialize socket server    //Initialize socket server
135    net_server("",2323);    net_server(BBS_address, BBS_port);
   
 /*  
   FILE *fp;  
   time_t t;  
   
   while (1)  
     {  
       sleep (60);  
       if ((fp = fopen ("bbsd.log", "a")) >= 0)  
         {  
           t = time (0);  
           fprintf (fp, "I'm here at %s\n", asctime (localtime (&t)));  
           fclose (fp);  
         }  
     }  
 */  
136    
137    return 0;    return 0;
138  }  }


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

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