Esempio n. 1
0
void PostgreSQLConfig::setCanonicalPathes( const std::string& refPath )
{
	if ( ! m_sslCert.empty() )	{
		std::string oldPath = m_sslCert;
		m_sslCert = utils::getCanonicalPath( m_sslCert, refPath);
		if ( oldPath != m_sslCert ) {
			LOG_WARNING << logPrefix() << "Using absolute SSL certificate filename '" << m_sslCert
				       << "' instead of '" << oldPath << "'";
		}
	}
	if ( ! m_sslKey.empty() )	{
		std::string oldPath = m_sslKey;
		m_sslKey = utils::getCanonicalPath( m_sslKey, refPath );
		if ( oldPath != m_sslKey ) {
			LOG_WARNING << logPrefix() << "Using absolute SSL key filename '" << m_sslKey
				       << "' instead of '" << oldPath << "'";
		}
	}
	if ( ! m_sslRootCert.empty() )	{
		std::string oldPath = m_sslRootCert;
		m_sslRootCert = utils::getCanonicalPath( m_sslRootCert, refPath );
		if ( oldPath != m_sslRootCert ) {
			LOG_WARNING << logPrefix() << "Using absolute CA certificate filename '" << m_sslRootCert
				       << "' instead of '" << oldPath << "'";
		}
	}
	if ( ! m_sslCRL.empty() )	{
		std::string oldPath = m_sslCRL;
		m_sslCRL = utils::getCanonicalPath( m_sslCRL, refPath );
		if ( oldPath != m_sslCRL ) {
			LOG_WARNING << logPrefix() << "Using absolute CRL filename '" << m_sslCRL
				       << "' instead of '" << oldPath << "'";
		}
	}
}
Esempio n. 2
0
void error(const std::string& msg, const bool append_errno)
{
    logger().error(logPrefix() + msg +
                   (append_errno
                    ? (std::string(" (errno: ") + strerror(errno) + ").")
                    : std::string("")));
}
Esempio n. 3
0
bool PostgreSQLConfig::check() const
{
	if ( m_connections == 0 )	{
		LOG_ERROR << logPrefix() << " " << m_config_pos.logtext() << ": number of database connections cannot be 0";
		return false;
	}
	return true;
}
Esempio n. 4
0
bool SQLiteConfig::check() const
{
	if ( m_filename.empty() )	{
		LOG_ERROR << logPrefix() << " " << m_config_pos.logtext() << ": SQLite database filename cannot be empty";
		return false;
	}
	return true;
}
Esempio n. 5
0
bool PostgreSQLConfig::mapValueDomains()
{
	bool retVal = true;
	if (m_port == 0)
	{
		LOG_FATAL << logPrefix() << " " << m_config_pos.logtext() << ": port must be defined as a non zero non negative number";
		retVal = false;
	}
	if (!m_sslMode.empty())
	{
		if ( boost::algorithm::iequals( m_sslMode, "disable" ))
			m_sslMode = "disable";
		else if ( boost::algorithm::iequals( m_sslMode, "allow" ))
			m_sslMode = "allow";
		else if ( boost::algorithm::iequals( m_sslMode, "prefer" ))
			m_sslMode = "prefer";
		else if ( boost::algorithm::iequals( m_sslMode, "require" ))
			m_sslMode = "require";
		else if ( boost::algorithm::iequals( m_sslMode, "verify-ca" ))
			m_sslMode = "verify-ca";
		else if ( boost::algorithm::iequals( m_sslMode, "verify-full" ))
			m_sslMode = "verify-full";
		else	{
			LOG_FATAL << logPrefix() << " " << m_config_pos.logtext() << ": unknown SSL mode: '" << m_sslMode << "'";
			retVal = false;
		}
	}
	if ( !m_sslCert.empty() && m_sslKey.empty() )	{
		LOG_FATAL << logPrefix() << " " << m_config_pos.logtext() << ": SSL certificate configured but no SSL key specified";
		retVal = false;
	}
	if ( !m_sslCert.empty() && m_sslKey.empty() )	{
		LOG_FATAL << logPrefix() << " " << m_config_pos.logtext() << ": SSL key configured but no SSL certificate specified";
		retVal = false;
	}
	if ( boost::algorithm::iequals( m_sslMode, "verify-ca" ) ||
	     boost::algorithm::iequals( m_sslMode, "verify-full" ))	{
		LOG_FATAL << logPrefix() << " " << m_config_pos.logtext() << ": server SSL certificate requested but no root CA specified";
		retVal = false;
	}
	if ( m_sslMode.empty())
		m_sslMode = "prefer";
	return retVal;
}
Esempio n. 6
0
 void shutdownWebSocket(Poco::Net::WebSocket& ws)
 {
     try
     {
         ws.shutdown();
     }
     catch (Poco::IOException& exc)
     {
         Poco::Util::Application::instance().logger().error(logPrefix() + "IOException: " + exc.message());
     }
 }
Esempio n. 7
0
void SQLiteConfig::setCanonicalPathes( const std::string& refPath )
{
	if ( ! m_filename.empty() )	{
		std::string oldPath = m_filename;
		m_filename = utils::getCanonicalPath( m_filename, refPath);
		if ( oldPath != m_filename )	{
			LOG_WARNING << logPrefix() << "Using absolute database filename '" << m_filename
				       << "' instead of '" << oldPath << "'";
		}
	}
}
Esempio n. 8
0
bool pEchoConfiguration::parse( const config::ConfigurationNode& pt, const std::string& /*node*/,
				const module::ModuleDirectory* /*modules*/ )
{
	bool retVal = true;
	bool isSet = false;

	for ( config::ConfigurationNode::const_iterator L1it = pt.begin(); L1it != pt.end(); L1it++ )	{
		if ( boost::algorithm::iequals( L1it->first, "idle" ))	{
			if ( !config::Parser::getValue( logPrefix().c_str(), *L1it, timeout ))
				retVal = false;
			isSet = true;
		}
		else
			LOG_WARNING << logPrefix() << "unknown configuration option: '"
				    << L1it->first << "'";
	}
	if ( !isSet )
		timeout = DEFAULT_TIMEOUT;

	return retVal;
}
	bool parse( const config::ConfigurationNode& pt, const std::string& node,
			const module::ModuleDirectory*)
	{
		try
		{
			if (!m_baseptr) throw std::logic_error("configuration structure base pointer not set with setBasePtr(void*)");
			serialize::parseConfigStructureVP( m_baseptr, m_descr, pt);
			return true;
		}
		catch (const std::runtime_error& e)
		{
			LOG_ERROR << logPrefix() << e.what() << " in " << node << " " << pt.position().logtext();
			return false;
		}
	}
Esempio n. 10
0
void _Logger::log(CCI_LOG_LEVEL level, const char *msg)
{
  cci::_MutexAutolock lock(&critical);

  gettimeofday(&context.now, NULL);

  if (useDefaultPrefix)
    {
      logPrefix(level);
    }

  write(msg);

  if (useDefaultNewLine)
    {
      write("\n");
    }
}
Esempio n. 11
0
 void error(const std::string& msg)
 {
     logger().error(logPrefix() + msg + " (" + strerror(errno) + ").");
 }
Esempio n. 12
0
 void warn(const std::string& msg)
 {
     logger().warning(logPrefix() + msg);
 }
Esempio n. 13
0
 void info(const std::string& msg)
 {
     logger().information(logPrefix() + msg);
 }
Esempio n. 14
0
 void debug(const std::string& msg)
 {
     logger().debug(logPrefix() + msg);
 }
Esempio n. 15
0
 void trace(const std::string& msg)
 {
     logger().trace(logPrefix() + msg);
 }
Esempio n. 16
0
void start()
{
    std::ofstream pidfile(SC_PID);
    if (!pidfile.good()) {
        std::cerr << "cannot open PID file " << SC_PID << ": " << strerror(errno) << std::endl;
        exit(errno);
    }
    pidfile << getpid() << std::endl;
    pidfile.close();

    std::ofstream log;

    log.open(SC_LOG, std::ofstream::app);
    log << "\n"
        << logPrefix() << "starting shoutcast daemon" << std::endl;
    log << logPrefix() << "reading shoutcast configuration files from " << SC_CONFIG << std::endl;
    log.close();

    // Enumerate config files in shoutcast config dir.
    DIR *dir;
    struct dirent *ent;
    dir = opendir (SC_CONFIG);
    if (dir == NULL) {
        log.open(SC_LOG, std::ofstream::app);
        log << logPrefix() << "cannot read scd configuration direcoty " << SC_CONFIG << ": " << strerror(errno) << std::endl;
        log.close();
        exit(errno);
    }

    for (; ent = readdir(dir); ent != NULL) {
        std::string cfgfile = ent->d_name;
        if (cfgfile == "." || cfgfile == "..") {
            continue;
        }
        std::string cfgpath = SC_CONFIG;
        cfgpath += "/";
        cfgpath += cfgfile;
        Child c;
        c.pid = 0;
        c.config = cfgpath;
        size_t idx = cfgfile.find(".");
        c.log = SC_LOGDIR"sc_stream_";
        c.log += cfgfile.substr(0, idx);
        c.log += ".log";
        g_children.push_back(c);

        log.open(SC_LOG, std::ofstream::app);
        log << logPrefix() << "found shoutcast configuration: " << cfgpath << std::endl;
        log.close();
    }
    closedir(dir);

    // Start respawn loop.
    while (g_running) {
        // Respawn all children with zero pid.
        for (Children::iterator i = g_children.begin();
                i != g_children.end(); ++i) {
            if (i->pid == 0) {
                i->pid = fork();
                if (i->pid == 0) {
                    // Open log file and redirect stdout, stderr.
                    FILE *f = fopen(i->log.c_str(), "a");
                    int r1 = dup2(fileno(f), 1);
                    int r2 = dup2(fileno(f), 2);
                    fclose(f);

                    // Start child process.
                    std::cout << timeStr()
                              << "[" << getpid() << "] started"
                              << std::endl;
                    if (execl(SC_EXEC, SC_EXEC, i->config.c_str(),
                            (char*)0) < 0) {
                        exit(1);
                    }
                } else {
                    log.open(SC_LOG, std::ofstream::app);
                    log << logPrefix() << "spawned server for config " << i->config << ", server pid is [" << i->pid << "]" << std::endl;
                    log.close();
                }
            }
        }

        // Wait for any failed children.
        int status;
        pid_t pid = wait(&status);
        if (!g_running)
            break;

        // Mark a failed child to restart.
        for (Children::iterator i = g_children.begin(); i != g_children.end(); ++i) {
            if (i->pid == pid) {
                log.open(SC_LOG, std::ofstream::app);
                log << logPrefix() << "server with pid [" << pid << "] (" << i->config << ") failed with status " << status << std::endl;
                log.close();
                i->pid = 0;
                break;
            }
        }
    }

    log.open(SC_LOG, std::ofstream::app);
    log << logPrefix() << "terminated" << "\n" << std::endl;
    log.close();
}