static wxFileName GetPortableIniPath() { wxString programFullPath = wxStandardPaths::Get().GetExecutablePath(); wxDirName programDir( wxFileName(programFullPath).GetPath() ); return programDir + "portable.ini"; }
int main(int argc, char** argv) { bool debug = false; QString logFile; // Parse command line for (int i = 1; i < argc; ++i) { QString arg(argv[i]); if (arg == "-debug") debug = true; else if (arg == "-log") logFile = argv[++i]; else if (arg == "-configDir") { if (i + 1 == argc) qFatal("Error: missing -configDir argument"); ConfigFile::setDefaultConfigDir(argv[++i]); } else { qFatal("Error: unknown command line argument: " + arg); } } // Use fd 10 for socket if (dup2(0, 10) != 10) exit(2); for (int fd = 0; fd < 10; ++fd) close(fd); QSocketDevice socket(10, QSocketDevice::Stream); // Decide on a log filename QString fileName = socket.peerAddress().toString() + ".log"; if (logFile.isEmpty()) { QFile file("/var/log/quasar/" + fileName); if (file.open(IO_WriteOnly | IO_Append)) logFile = file.name(); } if (logFile.isEmpty()) { QFile file(programDir() + "/../log/" + fileName); if (file.open(IO_WriteOnly | IO_Append)) logFile = file.name(); } if (logFile.isEmpty()) { QFile file(programDir() + "/../" + fileName); if (file.open(IO_WriteOnly | IO_Append)) logFile = file.name(); else logFile = "/tmp/" + fileName; } // Initialize logging logInitialize(logFile); logStatus("Connection started (pid %d)", getpid()); dup2(0, 1); dup2(0, 2); // Signal handling signal(SIGPIPE, SIG_IGN); signal(SIGINT, handleSignal); signal(SIGQUIT, handleSignal); signal(SIGTERM, handleSignal); QApplication app(argc, argv, false); // Command processing loop mainLoop(socket, debug); logStatus("Connection closed (pid %d)", getpid()); return 0; }