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