void Log::open() { Guard<Mutex> guard(mutex_); if (path() != "") { errorStream_ = warningStream_ = noticeStream_ = infoStream_ = debugStream_ = File::open(path(), File::WriteOnly|File::Append); } else if (Process::isDaemonized()) { errorStream_ = systemLog()->errorStream(); warningStream_ = systemLog()->warningStream(); noticeStream_ = systemLog()->noticeStream(); infoStream_ = systemLog()->infoStream(); debugStream_ = systemLog()->debugStream(); } else { errorStream_ = warningStream_ = noticeStream_ = infoStream_ = debugStream_ = stdErr(); } if (level() < ErrorLogLevel) errorStream_ = nullStream(); if (level() < WarningLogLevel) warningStream_ = nullStream(); if (level() < NoticeLogLevel) noticeStream_ = nullStream(); if (level() < InfoLogLevel) infoStream_ = nullStream(); if (level() < DebugLogLevel) debugStream_ = nullStream(); }
void TestManager::addAssertion(const char * message) { if (_assertion_breakpoint_enabled) { systemLog(message); CC7_BREAKPOINT(); } }
void Initializer::initDaemon() const { if (FLAGS_config_check) { // No need to daemonize, emit log lines, or create process mutexes. return; } #if !defined(__APPLE__) && !defined(WIN32) // OS X uses launchd to daemonize. if (osquery::FLAGS_daemonize) { if (daemon(0, 0) == -1) { shutdown(EXIT_FAILURE); } } #endif // Print the version to the OS system log. systemLog(binary_ + " started [version=" + kVersion + "]"); if (!FLAGS_ephemeral) { if ((Flag::isDefault("pidfile") || Flag::isDefault("database_path")) && !isDirectory(OSQUERY_HOME)) { std::cerr << CONFIG_ERROR; } // Create a process mutex around the daemon. auto pid_status = createPidFile(); if (!pid_status.ok()) { LOG(ERROR) << binary_ << " initialize failed: " << pid_status.toString(); shutdown(EXIT_FAILURE); } } // Nice ourselves if using a watchdog and the level is not too permissive. if (!FLAGS_disable_watchdog && FLAGS_watchdog_level >= 0) { // Set CPU scheduling I/O limits. setToBackgroundPriority(); #ifdef __linux__ // Using: ioprio_set(IOPRIO_WHO_PGRP, 0, IOPRIO_CLASS_IDLE); syscall(SYS_ioprio_set, IOPRIO_WHO_PGRP, 0, IOPRIO_CLASS_IDLE); #elif defined(__APPLE__) setiopolicy_np(IOPOL_TYPE_DISK, IOPOL_SCOPE_PROCESS, IOPOL_THROTTLE); #endif } }
void System::systemPrint(const char *format, ...) { va_list args; va_start(args, format); unsigned size = vsnprintf(NULL, 0, format, args); va_end(args); if (size) { char *buf = (char *)malloc(size + 1); buf[0] = '\0'; va_start(args, format); vsnprintf(buf, size + 1, format, args); va_end(args); buf[size] = '\0'; systemLog(buf); free(buf); } }
void Initializer::requestShutdown(int retcode, const std::string& system_log) { systemLog(system_log); requestShutdown(retcode); }