--- innwebd/innbbsd.cpp 2004/07/02 11:30:28 1.1 +++ innwebd/innbbsd.cpp 2004/08/02 19:48:17 1.5 @@ -1,10 +1,10 @@ /*******************************************************/ /* */ -/* LeafOK Innd */ +/* LeafOK Innbbsd */ /* Copyright (C) LeafOK.com, 2003-2004 */ /* */ /* Programmed by Leaf */ -/* E-mail:leaf@leafok.com QQ:6049044 */ +/* E-mail:leaflet@leafok.com QQ:6049044 */ /* */ /* http://bbs.leafok.com */ /* http://bbs.leafok.net */ @@ -20,6 +20,7 @@ #include ".\innbbsd.h" #include ".\service.h" #include ".\bbs_fun.h" +#include ".\App_common.h" #ifdef _DEBUG #define new DEBUG_NEW @@ -45,13 +46,30 @@ int _tmain(int argc, TCHAR* argv[], TCHA return 1; } - // TODO: 在此处为应用程序的行为编写代码。 - // System settings - const char* logfile_file = _T("innbbsd.log"); + const char* conf_file = _T("innbbsd.conf"); + const char* log_file = _T("innbbsd.log"); - syslog.open(logfile_file,ios_base::out | ios_base::app); + // Get application path + CString app_path; + int pos; + + app_path = argv[0]; + pos = app_path.ReverseFind('\\'); + if (pos != -1) + app_path = app_path.Left(pos + 1); + else + app_path = ""; + + syslog.open(app_path + log_file, ios_base::out | ios_base::app); + + // Report program information + syslog << "********************" << endl; + syslog << App_common::GetVersion() << endl; + syslog << App_common::Copyright << endl; + syslog << logfile::log_head << "Starting up..." << endl; + // Initialize sockets if(!AfxSocketInit()) { syslog << logfile::log_head << "Sockets init failed" << endl; @@ -61,32 +79,55 @@ int _tmain(int argc, TCHAR* argv[], TCHA // Create the service object service innbbsd_srv; - CString conf_file; - conf_file = argv[0]; - conf_file = conf_file.Left(conf_file.ReverseFind('\\')) + "\\innbbsd.conf"; - - innbbsd_srv.ctrld.load_conf(conf_file); + innbbsd_srv.ctrld.load_conf(app_path + conf_file); //Standalone mode if (argc == 2 && _stricmp(argv[1], "-s") == 0) { - innbbsd_srv.ctrld.begin(); - innbbsd_srv.ctrld.StartupChild(); + innbbsd_srv.ctrld.InitThreadPool(); + + if (innbbsd_srv.ctrld.begin() == 0) + { + syslog << logfile::log_head << "Begin CONTROLD ... OK" << endl; + + innbbsd_srv.ctrld.StartupChild(); + + while (innbbsd_srv.ctrld.IsRunning()) + { + Sleep(100); + } + + innbbsd_srv.ctrld.ShutdownChild(); + } + else + { + syslog << logfile::log_head << "Begin CONTROLD ... Failed" << endl; + } - while (innbbsd_srv.ctrld.IsRunning()) + if (innbbsd_srv.ctrld.end() == 0) + { + syslog << logfile::log_head << "End CONTROLD ... OK" << endl; + } + else { - Sleep(100); - } + syslog << logfile::log_head << "End CONTROLD ... Failed" << endl; + } + + innbbsd_srv.ctrld.CleanupThreadPool(); - innbbsd_srv.ctrld.bbsd.end(); - innbbsd_srv.ctrld.innd.end(); - innbbsd_srv.ctrld.outd.end(); - innbbsd_srv.ctrld.end(); + ExitProcess(0); return 0; } - // Parse for standard arguments (install, uninstall, version etc.) + // Display version infomation + if (argc == 2 && _stricmp(argv[1], "-c") == 0) + { + cout << App_common::GetVersion() << endl; + cout << App_common::Copyright << endl; + } + + // Parse for standard arguments (install, uninstall, version etc.) if (!innbbsd_srv.ParseStandardArgs(argc, argv)) { //DebugBreak(); innbbsd_srv.StartService();