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


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

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