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

Annotation of /lbbs/src/main.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (hide annotations)
Thu Oct 21 17:28:46 2004 UTC (21 years, 5 months ago) by sysadm
Branch: MAIN
Changes since 1.5: +87 -2 lines
Content type: text/x-csrc
*** empty log message ***

1 sysadm 1.1 /***************************************************************************
2 sysadm 1.3 main.c - description
3 sysadm 1.1 -------------------
4     begin : Mon Oct 11 2004
5     copyright : (C) 2004 by Leaflet
6     email : leaflet@leafok.com
7     ***************************************************************************/
8    
9     /***************************************************************************
10     * *
11     * This program is free software; you can redistribute it and/or modify *
12     * it under the terms of the GNU General Public License as published by *
13     * the Free Software Foundation; either version 2 of the License, or *
14     * (at your option) any later version. *
15     * *
16     ***************************************************************************/
17    
18 sysadm 1.4 #include "bbs.h"
19 sysadm 1.1 #include "common.h"
20    
21 sysadm 1.6 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 sysadm 1.1 int
43     main (int argc, char *argv[])
44     {
45 sysadm 1.4 char log_dir[256], file_log_std[256], file_log_error[256], file_config[256];
46 sysadm 1.6 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 sysadm 1.3 //Initialize daemon
107 sysadm 1.6 if (daemon)
108     init_daemon ();
109 sysadm 1.3
110     //Initialize log
111 sysadm 1.4 strncpy(app_home_dir, argv[0], rindex(argv[0],'/')-argv[0]+1);
112     strcpy(log_dir, app_home_dir);
113     strcat(log_dir, "log/");
114     strcpy(file_log_std, log_dir);
115     strcpy(file_log_error, log_dir);
116     strcat(file_log_std, "bbsd.log");
117     strcat(file_log_error, "error.log");
118 sysadm 1.3 mkdir(log_dir,0700);
119 sysadm 1.4 if (log_begin(file_log_std,file_log_error)<0)
120     exit(-1);
121 sysadm 1.6 if ((!daemon) && std_log_redir)
122     log_std_redirect(2);
123     if ((!daemon) && error_log_redir)
124     log_err_redirect(3);
125 sysadm 1.4
126     //Load configuration
127     strcpy(file_config, app_home_dir);
128     strcat(file_config, "conf/bbsd.conf");
129     if (load_conf(file_config)<0)
130     exit(-2);
131 sysadm 1.3
132     //Initialize socket server
133 sysadm 1.4 net_server(BBS_address, BBS_port);
134 sysadm 1.3
135 sysadm 1.1 return 0;
136     }

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