| 16 |
***************************************************************************/ |
***************************************************************************/ |
| 17 |
|
|
| 18 |
#include "bbs.h" |
#include "bbs.h" |
| 19 |
|
#include "init.h" |
| 20 |
#include "common.h" |
#include "common.h" |
| 21 |
|
#include "net_server.h" |
| 22 |
|
#include "log.h" |
| 23 |
#include "io.h" |
#include "io.h" |
| 24 |
#include "menu.h" |
#include "menu.h" |
| 25 |
|
#include <stdlib.h> |
| 26 |
#include <signal.h> |
#include <signal.h> |
| 27 |
#include <string.h> |
#include <string.h> |
|
#include <sys/types.h> |
|
| 28 |
#include <unistd.h> |
#include <unistd.h> |
| 29 |
|
#include <libgen.h> |
| 30 |
|
#include <sys/types.h> |
| 31 |
|
#include <sys/stat.h> |
| 32 |
|
|
| 33 |
void app_help(void) |
void app_help(void) |
| 34 |
{ |
{ |
| 49 |
|
|
| 50 |
int main(int argc, char *argv[]) |
int main(int argc, char *argv[]) |
| 51 |
{ |
{ |
| 52 |
char log_dir[256], file_log_std[256], file_log_error[256], file_config[256]; |
char file_path_temp[FILE_PATH_LEN]; |
| 53 |
int i, j; |
int daemon = 1; |
| 54 |
int daemon = 1, std_log_redir = 0, error_log_redir = 0; |
int std_log_redir = 0; |
| 55 |
|
int error_log_redir = 0; |
| 56 |
|
|
| 57 |
// Parse args |
// Parse args |
| 58 |
for (i = 1; i < argc; i++) |
for (int i = 1; i < argc; i++) |
| 59 |
{ |
{ |
| 60 |
switch (argv[i][0]) |
switch (argv[i][0]) |
| 61 |
{ |
{ |
| 62 |
case '-': |
case '-': |
| 63 |
if (argv[i][1] != '-') |
if (argv[i][1] != '-') |
| 64 |
{ |
{ |
| 65 |
for (j = 1; j < strlen(argv[i]); j++) |
for (int j = 1; j < strlen(argv[i]); j++) |
| 66 |
{ |
{ |
| 67 |
switch (argv[i][j]) |
switch (argv[i][j]) |
| 68 |
{ |
{ |
| 113 |
|
|
| 114 |
// Initialize daemon |
// Initialize daemon |
| 115 |
if (daemon) |
if (daemon) |
| 116 |
|
{ |
| 117 |
init_daemon(); |
init_daemon(); |
| 118 |
|
} |
| 119 |
|
|
| 120 |
// Change current dir |
// Change current dir |
| 121 |
strncpy(app_home_dir, argv[0], rindex(argv[0], '/') - argv[0] + 1); |
strncpy(file_path_temp, argv[0], sizeof(file_path_temp) - 1); |
| 122 |
strcat(app_home_dir, "../"); |
file_path_temp[sizeof(file_path_temp) - 1] = '\0'; |
| 123 |
chdir(app_home_dir); |
|
| 124 |
|
chdir(dirname(file_path_temp)); |
| 125 |
|
chdir(".."); |
| 126 |
|
|
| 127 |
// Initialize log |
// Initialize log |
| 128 |
strcpy(app_temp_dir, "/tmp/lbbs/"); |
if (log_begin(LOG_FILE_INFO, LOG_FILE_ERROR) < 0) |
| 129 |
mkdir(app_temp_dir, 0777); |
{ |
|
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) |
|
| 130 |
exit(-1); |
exit(-1); |
| 131 |
|
} |
| 132 |
|
|
| 133 |
if ((!daemon) && std_log_redir) |
if ((!daemon) && std_log_redir) |
| 134 |
|
{ |
| 135 |
log_std_redirect(2); |
log_std_redirect(2); |
| 136 |
|
} |
| 137 |
if ((!daemon) && error_log_redir) |
if ((!daemon) && error_log_redir) |
| 138 |
|
{ |
| 139 |
log_err_redirect(3); |
log_err_redirect(3); |
| 140 |
|
} |
| 141 |
|
|
| 142 |
// Load configuration |
// Load configuration |
| 143 |
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) |
|
| 144 |
exit(-2); |
exit(-2); |
| 145 |
|
|
| 146 |
// Load menus |
// Load menus |
| 147 |
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) |
|
| 148 |
exit(-3); |
exit(-3); |
| 149 |
|
|
| 150 |
// Set signal handler |
// Set signal handler |
| 158 |
// Wait for child process exit |
// Wait for child process exit |
| 159 |
while (SYS_child_process_count > 0) |
while (SYS_child_process_count > 0) |
| 160 |
{ |
{ |
|
log_std("."); |
|
| 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 |
return 0; |
return 0; |
| 168 |
} |
} |