bool CCallsignList::LoadFromFile(const char *filename) { bool ok = false; char sz[256]; // and load std::ifstream file (filename); if ( file.is_open() ) { Lock(); // empty list clear(); // fill with file content while ( file.getline(sz, sizeof(sz)).good() ) { // remove leading & trailing spaces char *szt = TrimWhiteSpaces(sz); // and load if not comment if ( (::strlen(szt) > 0) && (szt[0] != '#') ) { push_back(CCallsignListItem(CCallsign(szt), CIp(), NULL)); } } // close file file.close(); // keep file path m_Filename = filename; // update time GetLastModTime(&m_LastModTime); // and done Unlock(); ok = true; std::cout << "Gatekeeper loaded " << size() << " lines from " << filename << std::endl; } else { std::cout << "Gatekeeper cannot find " << filename << std::endl; } return ok; }
int main(int argc, const char * argv[]) { #ifdef RUN_AS_DAEMON // redirect cout, cerr and clog to syslog syslog::redirect cout_redir(std::cout); syslog::redirect cerr_redir(std::cerr); syslog::redirect clog_redir(std::clog); //Fork the Parent Process pid_t pid, sid; pid = ::fork(); //pid = ::vfork(); if ( pid < 0 ) { exit(EXIT_FAILURE); } // We got a good pid, Close the Parent Process if (pid > 0) { exit(EXIT_SUCCESS); } // Change File Mask ::umask(0); //Create a new Signature Id for our child sid = ::setsid(); if (sid < 0) { exit(EXIT_FAILURE); } // Change Directory // If we cant find the directory we exit with failure. if ( (::chdir("/")) < 0) { exit(EXIT_FAILURE); } // Close Standard File Descriptors close(STDIN_FILENO); close(STDOUT_FILENO); close(STDERR_FILENO); #endif // check arguments if ( argc != 2 ) { std::cout << "Usage: ambed ip" << std::endl; std::cout << "example: ambed 192.168.178.212" << std::endl; return 1; } // initialize ambeserver g_AmbeServer.SetListenIp(CIp(argv[1])); // and let it run std::cout << "Starting AMBEd " << VERSION_MAJOR << "." << VERSION_MINOR << "." << VERSION_REVISION << std::endl << std::endl; if ( !g_AmbeServer.Start() ) { std::cout << "Error starting AMBEd" << std::endl; exit(EXIT_FAILURE); } std::cout << "AMBEd started and listening on " << g_AmbeServer.GetListenIp() << std::endl; #ifdef RUN_AS_DAEMON // run forever while ( true ) { // sleep 60 seconds CTimePoint::TaskSleepFor(60000); } #else // wait any key for (;;) { // sleep 60 seconds CTimePoint::TaskSleepFor(60000); //std::cin.get(); } #endif // and wait for end g_AmbeServer.Stop(); std::cout << "AMBEd stopped" << std::endl; // done exit(EXIT_SUCCESS); }