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

Contents of /lbbs/src/main.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.16 - (show annotations)
Sat May 7 12:15:30 2005 UTC (20 years, 10 months ago) by sysadm
Branch: MAIN
Changes since 1.15: +1 -1 lines
Content type: text/x-csrc
*** empty log message ***

1 /***************************************************************************
2 main.c - description
3 -------------------
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 #include "bbs.h"
19 #include "common.h"
20 #include "io.h"
21 #include "menu.h"
22 #include <signal.h>
23 #include <string.h>
24 #include <sys/types.h>
25 #include <unistd.h>
26
27 void
28 app_help (void)
29 {
30 prints ("Usage: bbsd [-fhv] [...]\n\n"
31 "-f\t--foreground\t\tForce program run in foreground\n"
32 "-h\t--help\t\t\tDisplay this help message\n"
33 "-v\t--version\t\tDisplay version information\n"
34 "\t--display-log\t\tDisplay standard log information\n"
35 "\t--display-error-log\tDisplay error log information\n"
36 "\n If meet any bug, please report to <leaflet@leafok.com>\n\n");
37 }
38
39 void
40 arg_error (void)
41 {
42 prints ("Invalid arguments\n");
43 app_help ();
44 }
45
46 int
47 main (int argc, char *argv[])
48 {
49 char log_dir[256], file_log_std[256], file_log_error[256], file_config[256];
50 int i, j;
51 int daemon = 1, std_log_redir = 0, error_log_redir = 0;
52
53 //Parse args
54 for (i = 1; i < argc; i++)
55 {
56 switch (argv[i][0])
57 {
58 case '-':
59 if (argv[i][1] != '-')
60 {
61 for (j = 1; j < strlen (argv[i]); j++)
62 {
63 switch (argv[i][j])
64 {
65 case 'f':
66 daemon = 0;
67 break;
68 case 'h':
69 app_help ();
70 exit (0);
71 case 'v':
72 puts (app_version);
73 exit (0);
74 default:
75 arg_error ();
76 exit (1);
77 }
78 }
79 }
80 else
81 {
82 if (strcmp (argv[i] + 2, "foreground") == 0)
83 {
84 daemon = 0;
85 break;
86 }
87 if (strcmp (argv[i] + 2, "help") == 0)
88 {
89 app_help ();
90 exit (0);
91 }
92 if (strcmp (argv[i] + 2, "version") == 0)
93 {
94 puts (app_version);
95 exit (0);
96 }
97 if (strcmp (argv[i] + 2, "display-log") == 0)
98 {
99 std_log_redir = 1;
100 }
101 if (strcmp (argv[i] + 2, "display-error-log") == 0)
102 {
103 error_log_redir = 1;
104 }
105 }
106 break;
107 }
108 }
109
110 //Initialize daemon
111 if (daemon)
112 init_daemon ();
113
114 //Change current dir
115 strncpy (app_home_dir, argv[0], rindex (argv[0], '/') - argv[0] + 1);
116 strcat (app_home_dir, "../");
117 chdir (app_home_dir);
118
119 //Initialize log
120 strcpy (app_temp_dir, "/tmp/lbbs/");
121 mkdir (app_temp_dir, 0750);
122 strcpy (log_dir, app_home_dir);
123 strcat (log_dir, "log/");
124 strcpy (file_log_std, log_dir);
125 strcpy (file_log_error, log_dir);
126 strcat (file_log_std, "bbsd.log");
127 strcat (file_log_error, "error.log");
128 mkdir (log_dir, 0750);
129 if (log_begin (file_log_std, file_log_error) < 0)
130 exit (-1);
131
132 if ((!daemon) && std_log_redir)
133 log_std_redirect (2);
134 if ((!daemon) && error_log_redir)
135 log_err_redirect (3);
136
137 //Load configuration
138 strcpy (file_config, app_home_dir);
139 strcat (file_config, "conf/bbsd.conf");
140 if (load_conf (file_config) < 0)
141 exit (-2);
142
143 //Load menus
144 strcpy (file_config, app_home_dir);
145 strcat (file_config, "conf/menu.conf");
146 if (load_menu (&bbs_menu, file_config) < 0)
147 exit (-3);
148
149 //Set signal handler
150 signal (SIGCHLD, child_exit);
151 signal (SIGTERM, system_exit);
152 signal (SIG_RELOAD_MENU, reload_bbs_menu);
153
154 //Initialize socket server
155 net_server (BBS_address, BBS_port);
156
157 //Wait for child process exit
158 while (SYS_child_process_count > 0)
159 {
160 log_std (".");
161 sleep(1);
162 }
163
164 return 0;
165 }

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