/* * We can't run the VM in the main thread (because it has to handle events). * So we run the VM in this thread. */ static DWORD WINAPI vm_thread_routine(LPVOID lpvParam) { // Print arguments that we are using JVMSPI_PrintRaw("Running VM"); JVMSPI_PrintRaw("\n"); for (int i = 1; i < _argc; i++) { JVMSPI_PrintRaw(" "); JVMSPI_PrintRaw(_argv[i]); JVMSPI_PrintRaw("\n"); } // Call this before any other Jvm_ functions. JVM_Initialize(); int argc = _argc; char ** argv = _argv; // Ignore arg[0] -- the name of the program. argc --; argv ++; while (true) { int n = JVM_ParseOneArg(argc, argv); if (n < 0) { JVMSPI_DisplayUsage(NULL); return -1; } else if (n == 0) { break; } argc -= n; argv += n; } if (LogConsole) { write_console("Console output logged at \n"); write_console(logfilename); write_console("\n"); for (int index=0; index<_argc; index++) { log_console(_argv[index]); log_console(" "); } log_console("\n"); } if (!WriteConsole) { write_console("On-screen console output disabled.\n"); } int code = JVM_Start(NULL, NULL, argc, argv); JVMSPI_Exit(code); SHOULD_NOT_REACH_HERE(); return 0; }
void JVMSPI_PrintRaw(const char* s) { if (WriteConsole) { write_console(s); } if (LogConsole) { log_console(s); } }
int main(int argc, char **argv) { struct sigaction sig_stop; struct sigaction sig_time; _main = main_init(argc, argv); _log = log_init(); _main->conf = conf_init(argc, argv); _main->work = work_init(); _main->tcp = tcp_init(); _main->node = node_init(); _main->mime = mime_init(); /* Check configuration */ conf_print(); /* Catch SIG INT */ unix_signal(&sig_stop, &sig_time); /* Fork daemon */ unix_fork(log_console(_log)); /* Increase limits */ unix_limits(_main->conf->cores, CONF_EPOLL_MAX_EVENTS); /* Load mime types */ mime_load(); mime_hash(); /* Prepare TCP daemon */ tcp_start(); /* Drop privileges */ unix_dropuid0(); /* Start worker threads */ work_start(); /* Stop worker threads */ work_stop(); /* Stop TCP daemon */ tcp_stop(); mime_free(); node_free(); tcp_free(); work_free(); conf_free(); log_free(_log); main_free(); return 0; }
void Log::initMe() { setDefaultConfig(); m_interceptMouseEvents = gCore->settingValue("Log/mouseEvents", false).toBool(); m_interceptQtMessages = gCore->settingValue("Log/messagesQt", false).toBool(); m_logRotateCounter = gCore->settingValue("Log/logRotateCounter").toLongLong(); QString logRotateFileSize = gCore->settingValue("Log/logRotateFileSize").toString(); if (logRotateFileSize.contains("kb", Qt::CaseInsensitive)) m_logRotateFileSize = logRotateFileSize.remove("kb", Qt::CaseInsensitive).toInt() * 1024; else if (logRotateFileSize.contains("mb", Qt::CaseInsensitive)) m_logRotateFileSize = logRotateFileSize.remove("mb", Qt::CaseInsensitive).toInt() * 1024000; else m_logRotateFileSize = logRotateFileSize.toInt(); m_sync = gCore->settingValue("Log/synchronously", false).toBool(); m_isInited = true; /// do logrotate if needed logRotate(); /// process it after exit from Core::init because gCore->scene() is not inited yet if (m_interceptMouseEvents) QTimer::singleShot(0, this, SLOT(initMouseHandler())); /// Setting up the qDebug handler only after m_isInited = true ensures that /// qDebug statements within the logger initialization don't cause stack (as /// warnings need to be logged if a log call is made during logger init.) if (m_interceptQtMessages) startCustomHandler(); if (gCore->settingValue("Log/enabled", true).toBool()) { QString context_size = gCore->settingValue("Log/contextMaxSize").toString(); int s = 0; if (context_size.contains("kb", Qt::CaseInsensitive)) s = context_size.remove("kb", Qt::CaseInsensitive).toInt() * 1024; else if (context_size.contains("mb", Qt::CaseInsensitive)) s = context_size.remove("mb", Qt::CaseInsensitive).toInt() * 1024000; else s = logRotateFileSize.toInt(); m_logProcessor = new LogProcessor(); m_logProcessor->setContextSize(s); m_logProcessor->setMouseEventFile(gCore->settingValue("Log/mouseLogFilename", "").toString()); m_logProcessor->setFilters(this->getFilters()); m_logProcessor->setGeneralMatrix( this->getGeneralLevelsSettings()); m_logProcessor->setModulesMatrix( this->getModulesLevelsSettings()); /// synchronous or asynchronous /// if (!m_sync) { log_console("Log is asynchronous"); m_processorThread = new QThread(this); m_logProcessor->moveToThread(m_processorThread); connect(this, SIGNAL(logMessage(int,QString,QString,QString)), m_logProcessor, SLOT(put(int,QString,QString,QString)), Qt::QueuedConnection); m_processorThread->start(QThread::LowestPriority); log_console(QString("Log current thread pointer is %1").arg(qint64(this->thread()))); log_console(QString("Log processor thread pointer is %1").arg(qint64(m_logProcessor->thread()))); } else {