| 17 |
|
|
| 18 |
#include "bbs.h" |
#include "bbs.h" |
| 19 |
#include "common.h" |
#include "common.h" |
| 20 |
|
#include "io.h" |
| 21 |
|
#include "menu.h" |
| 22 |
|
#include <string.h> |
| 23 |
|
|
| 24 |
void |
void |
| 25 |
app_help(void) |
app_help(void) |
| 26 |
{ |
{ |
| 27 |
printf ( |
prints ( |
| 28 |
"Usage: bbsd [-fhv] [...]\n\n" |
"Usage: bbsd [-fhv] [...]\n\n" |
| 29 |
"-f\t--foreground\t\tForce program run in foreground\n" |
"-f\t--foreground\t\tForce program run in foreground\n" |
| 30 |
"-h\t--help\t\t\tDisplay this help message\n" |
"-h\t--help\t\t\tDisplay this help message\n" |
| 38 |
void |
void |
| 39 |
arg_error(void) |
arg_error(void) |
| 40 |
{ |
{ |
| 41 |
printf ("Invalid arguments\n"); |
prints ("Invalid arguments\n"); |
| 42 |
app_help(); |
app_help(); |
| 43 |
} |
} |
| 44 |
|
|
| 78 |
} |
} |
| 79 |
else |
else |
| 80 |
{ |
{ |
| 81 |
if (strcmp(argv[i]+2, "foreground") == 0) |
if (strcmp (argv[i]+2, "foreground") == 0) |
| 82 |
{ |
{ |
| 83 |
daemon = 0; |
daemon = 0; |
| 84 |
break; |
break; |
| 85 |
} |
} |
| 86 |
if (strcmp(argv[i]+2, "help") == 0) |
if (strcmp (argv[i]+2, "help") == 0) |
| 87 |
{ |
{ |
| 88 |
app_help(); |
app_help(); |
| 89 |
exit(0); |
exit(0); |
| 90 |
} |
} |
| 91 |
if (strcmp(argv[i]+2, "version") == 0) |
if (strcmp (argv[i]+2, "version") == 0) |
| 92 |
{ |
{ |
| 93 |
puts (app_version); |
puts (app_version); |
| 94 |
exit(0); |
exit(0); |
| 95 |
} |
} |
| 96 |
if (strcmp(argv[i]+2, "display-log") == 0) |
if (strcmp (argv[i]+2, "display-log") == 0) |
| 97 |
{ |
{ |
| 98 |
std_log_redir = 1; |
std_log_redir = 1; |
| 99 |
} |
} |
| 100 |
if (strcmp(argv[i]+2, "display-error-log") == 0) |
if (strcmp (argv[i]+2, "display-error-log") == 0) |
| 101 |
{ |
{ |
| 102 |
error_log_redir = 1; |
error_log_redir = 1; |
| 103 |
} |
} |
| 111 |
init_daemon (); |
init_daemon (); |
| 112 |
|
|
| 113 |
//Initialize log |
//Initialize log |
| 114 |
strncpy(app_home_dir, argv[0], rindex(argv[0],'/')-argv[0]+1); |
strncpy (app_home_dir, argv[0], rindex(argv[0],'/')-argv[0]+1); |
| 115 |
strcpy(log_dir, app_home_dir); |
strcat (app_home_dir, "../"); |
| 116 |
strcat(log_dir, "log/"); |
strcpy (app_temp_dir, "/tmp/lbbs/"); |
| 117 |
strcpy(file_log_std, log_dir); |
mkdir (app_temp_dir, 0700); |
| 118 |
strcpy(file_log_error, log_dir); |
strcpy (log_dir, app_home_dir); |
| 119 |
strcat(file_log_std, "bbsd.log"); |
strcat (log_dir, "log/"); |
| 120 |
strcat(file_log_error, "error.log"); |
strcpy (file_log_std, log_dir); |
| 121 |
mkdir(log_dir,0700); |
strcpy (file_log_error, log_dir); |
| 122 |
if (log_begin(file_log_std,file_log_error)<0) |
strcat (file_log_std, "bbsd.log"); |
| 123 |
|
strcat (file_log_error, "error.log"); |
| 124 |
|
mkdir (log_dir, 0700); |
| 125 |
|
if (log_begin (file_log_std, file_log_error)<0) |
| 126 |
exit(-1); |
exit(-1); |
| 127 |
|
|
| 128 |
if ((!daemon) && std_log_redir) |
if ((!daemon) && std_log_redir) |
| 129 |
log_std_redirect(2); |
log_std_redirect(2); |
| 130 |
if ((!daemon) && error_log_redir) |
if ((!daemon) && error_log_redir) |
| 131 |
log_err_redirect(3); |
log_err_redirect(3); |
| 132 |
|
|
| 133 |
//Load configuration |
//Load configuration |
| 134 |
strcpy(file_config, app_home_dir); |
strcpy (file_config, app_home_dir); |
| 135 |
strcat(file_config, "conf/bbsd.conf"); |
strcat (file_config, "conf/bbsd.conf"); |
| 136 |
if (load_conf(file_config)<0) |
if (load_conf(file_config)<0) |
| 137 |
exit(-2); |
exit(-2); |
| 138 |
|
|
| 139 |
|
//Load menus |
| 140 |
|
strcpy (file_config, app_home_dir); |
| 141 |
|
strcat (file_config, "conf/menu.conf"); |
| 142 |
|
if (load_menu (&bbs_menu, file_config)<0) |
| 143 |
|
exit(-3); |
| 144 |
|
|
| 145 |
//Initialize socket server |
//Initialize socket server |
| 146 |
net_server(BBS_address, BBS_port); |
net_server (BBS_address, BBS_port); |
| 147 |
|
|
| 148 |
return 0; |
return 0; |
| 149 |
} |
} |