コード例 #1
0
ファイル: dscfgcli.c プロジェクト: ColinIanKing/openzfs
static void
cmd_loop()
{
    char	host[1024];
    char	buffer[1024];
    int	i;

    (void) gethostname(host, sizeof (host));
    for (;;) {
        if (tty)
            (void) printf(":%s: ", host);
        (void) fgets(buffer, sizeof (buffer), stdin);
        switch (tolower(buffer[0])) {
        case 'p':
            i = atoi(buffer + 1);
            (void) sleep(i);
            break;
        case 'q':
            exit(0);
            break;
        case 'r':
            if (cfg_lock(cfg, CFG_RDLOCK) < 0)
                (void) printf("CFG_RDLOCK error\n");
            break;
        case 's':
            cfg_lockd_stat();
            break;
        case 't':
            i = atoi(buffer + 1);
            test(i);
            break;
        case 'u':
            cfg_unlock(cfg);
            break;
        case 'w':
            if (cfg_lock(cfg, CFG_WRLOCK) < 0)
                (void) printf("CFG_WRLOCK error\n");
            break;
        default:
            (void) printf("don't understand %s\n", buffer);
            break;
        }
    }
}
コード例 #2
0
ファイル: dscfgcli.c プロジェクト: ColinIanKing/openzfs
static void
test(int count)
{
    struct stat sb;
    int i;

    if (count < 1)
        count = 1;
    for (i = 0; count-- > 0; i++) {
        if (cfg_lock(cfg, CFG_RDLOCK) < 0)
            (void) printf("CFG_RDLOCK error\n");
        else
            (void) fstat(0, &sb);

        cfg_unlock(cfg);
        (void) fstat(1, &sb);

        if (cfg_lock(cfg, CFG_RDLOCK) < 0)
            (void) printf("CFG_RDLOCK error\n");
        else
            (void) fstat(0, &sb);

        cfg_unlock(cfg);
        (void) fstat(1, &sb);

        if (cfg_lock(cfg, CFG_WRLOCK) < 0)
            (void) printf("CFG_WRLOCK error\n");
        else
            (void) fstat(0, &sb);

        cfg_unlock(cfg);
        (void) fstat(1, &sb);

        if (i > 0) {
            if (i % 100 == 0)
                (void) write(1, "+", 1);
            if (i % 5000 == 0)
                (void) write(1, "\n", 1);
        }
    }
    (void) printf("\nTest complete\n");
}
コード例 #3
0
void TransformReactor::updateVocabulary(const Vocabulary& v)
{
	// first update anything in the Reactor base class that might be needed
	ConfigWriteLock cfg_lock(*this);
	Reactor::updateVocabulary(v);

	// update Vocabulary for each of the rules
	for (TransformChain::iterator i = m_transforms.begin(); i != m_transforms.end(); ++i) {
		(*i)->updateVocabulary(v);
	}
}
コード例 #4
0
ファイル: FissionReactor.cpp プロジェクト: acmorrow/pion-core
void FissionReactor::updateVocabulary(const Vocabulary& v)
{
	// first update anything in the Reactor base class that might be needed
	ConfigWriteLock cfg_lock(*this);
	Reactor::updateVocabulary(v);

	v.refreshTerm(m_input_event_type);
	v.refreshTerm(m_input_event_term);

	boost::mutex::scoped_lock codec_lock(m_codec_mutex);
	if (m_codec_ptr)
		m_codec_ptr->updateVocabulary(v);
}
コード例 #5
0
ファイル: Reactor.hpp プロジェクト: acmorrow/pion-core
	/**
	 * public function to process a new Event.  checks to make sure the reactor
	 * is running, increments "events in" counter, and ensures configuration
	 * data is not being changed before calling the virtual process() function
	 *
	 * @param e pointer to the Event to process
	 */
	inline void operator()(const EventPtr& e) {
		if ( isRunning() ) {
			ConfigReadLock cfg_lock(*this);
			// re-check after locking
			if ( isRunning() ) {
				++m_events_in;
				try {
					process(e);
				} catch (std::exception& e) {
					PION_LOG_ERROR(m_logger, "reactor_id: " << getId() << " - " << e.what() << " - rethrowing");
					throw;
				}
			}
		}
	}
コード例 #6
0
ファイル: sndrsubr.c プロジェクト: 0xffea/illumos-gate
int
get_cfg_setid(CFGFILE *cfg, char *ctag, char *tohost, char *tofile)
{
	int setnum = 0;
	int close_cfg = 0;
	char key[CFG_MAX_KEY];
	char setid[64];

	if (cfg == NULL) {
		close_cfg = 1;
		if ((cfg = cfg_open(NULL)) == NULL) {
			return (-1); /* message printed by caller */
		}
		if (!cfg_lock(cfg, CFG_RDLOCK)) {
			cfg_close(cfg);
			return (-1);
		}
	}
	setnum = find_setnumber_in_libcfg(cfg, ctag, tohost, tofile);
	if (setnum < 0)
		return (setnum);

	(void) snprintf(key, CFG_MAX_KEY, "sndr.set%d.options", setnum);
	if (cfg_get_single_option(cfg, CFG_SEC_CONF, key, "setid",
		    setid, sizeof (setid)) < 0) {
		if (close_cfg)
			cfg_close(cfg);

		spcs_log("sndr", NULL,
		    gettext("%s unable to get unique setid "
		    "for %s:%s"), program, tohost, tofile);
		return (-1);

	}
	if (close_cfg)
		cfg_close(cfg);

	return (atoi(setid));

}
コード例 #7
0
ファイル: svadm.c プロジェクト: 0xffea/illumos-gate
static void
sv_cfg_open(CFGLOCK mode)
{
	if (cfg != NULL)
		return;

	cfg = cfg_open(NULL);
	if (cfg == NULL) {
		error(NULL, gettext("unable to access the configuration"));
		/* NOTREACHED */
	}

	if (cfg_cluster_tag && *cfg_cluster_tag) {
		cfg_resource(cfg, cfg_cluster_tag);
	} else {
		cfg_resource(cfg, NULL);
	}
	if (!cfg_lock(cfg, mode)) {
		error(NULL, gettext("unable to lock the configuration"));
		/* NOTREACHED */
	}
}
コード例 #8
0
ファイル: FissionReactor.cpp プロジェクト: acmorrow/pion-core
void FissionReactor::setConfig(const Vocabulary& v, const xmlNodePtr config_ptr)
{
	// first set config options for the Reactor base class
	ConfigWriteLock cfg_lock(*this);
	Reactor::setConfig(v, config_ptr);

	// get the input event type
	std::string config_str;
	if (! ConfigManager::getConfigOption(INPUT_EVENT_TYPE_ELEMENT_NAME, config_str, config_ptr))
		throw EmptyInputEventTypeException(getId());

	// find vocabulary term for input event type
	Vocabulary::TermRef term_ref = v.findTerm(config_str);
	if (term_ref == Vocabulary::UNDEFINED_TERM_REF)
		throw UnknownTermException(config_str);
	m_input_event_type = v[term_ref];

	// make sure that term is object/event type
	if (m_input_event_type.term_type != Vocabulary::TYPE_OBJECT)
		throw NotAnObjectException(config_str);

	// get the input event term
	if (! ConfigManager::getConfigOption(INPUT_EVENT_TERM_ELEMENT_NAME, config_str, config_ptr))
		throw EmptyInputEventTermException(getId());

	// find vocabulary term for input event term
	term_ref = v.findTerm(config_str);
	if (term_ref == Vocabulary::UNDEFINED_TERM_REF)
		throw UnknownTermException(config_str);
	m_input_event_term = v[term_ref];

	// only string types are currently supported for input event term
	switch (m_input_event_term.term_type) {
	case Vocabulary::TYPE_NULL:
	case Vocabulary::TYPE_OBJECT:
	case Vocabulary::TYPE_INT8:
	case Vocabulary::TYPE_INT16:
	case Vocabulary::TYPE_INT32:
	case Vocabulary::TYPE_UINT8:
	case Vocabulary::TYPE_UINT16:
	case Vocabulary::TYPE_UINT32:
	case Vocabulary::TYPE_INT64:
	case Vocabulary::TYPE_UINT64:
	case Vocabulary::TYPE_FLOAT:
	case Vocabulary::TYPE_DOUBLE:
	case Vocabulary::TYPE_LONG_DOUBLE:
	case Vocabulary::TYPE_DATE_TIME:
	case Vocabulary::TYPE_DATE:
	case Vocabulary::TYPE_TIME:
		throw TermNotStringException(config_str);
		break;
	case Vocabulary::TYPE_SHORT_STRING:
	case Vocabulary::TYPE_STRING:
	case Vocabulary::TYPE_LONG_STRING:
	case Vocabulary::TYPE_CHAR:
	case Vocabulary::TYPE_BLOB:
	case Vocabulary::TYPE_ZBLOB:
		break;	// these are all OK
	}

	// get the codec to use
	boost::mutex::scoped_lock codec_lock(m_codec_mutex);
	if (! ConfigManager::getConfigOption(CODEC_ELEMENT_NAME, m_codec_id, config_ptr))
		throw EmptyCodecException(getId());
	m_codec_ptr = getCodecFactory().getCodec(m_codec_id);	
	PION_ASSERT(m_codec_ptr);
	codec_lock.unlock();

	// check if we should copy all terms from original event
	m_copy_all_terms = false;
	std::string copy_all_terms_str;
	if (ConfigManager::getConfigOption(COPY_ALL_TERMS_ELEMENT_NAME,
									   copy_all_terms_str, config_ptr))
	{
		if (copy_all_terms_str == "true")
			m_copy_all_terms = true;
	}

	// get list of terms to copy from original event
	m_copy_terms.clear();
	xmlNodePtr copy_term_node = config_ptr;
	while ((copy_term_node = ConfigManager::findConfigNodeByName(COPY_TERM_ELEMENT_NAME, copy_term_node)) != NULL) {
		xmlChar *xml_char_ptr = xmlNodeGetContent(copy_term_node);
		if (xml_char_ptr != NULL) {
			const std::string copy_term_str(reinterpret_cast<char*>(xml_char_ptr));
			xmlFree(xml_char_ptr);
			if (! copy_term_str.empty()) {
				// find the term in the Vocabulary
				term_ref = v.findTerm(copy_term_str);
				if (term_ref == Vocabulary::UNDEFINED_TERM_REF)
					throw UnknownTermException(copy_term_str);

				// add it to the copy terms collection
				m_copy_terms.push_back(v[term_ref]);
			}
		}

		// step to the next copy term
		copy_term_node = copy_term_node->next;
	}
}
コード例 #9
0
void TransformReactor::setConfig(const Vocabulary& v, const xmlNodePtr config_ptr)
{
	// first set config options for the Reactor base class
	ConfigWriteLock cfg_lock(*this);
	Reactor::setConfig(v, config_ptr);

	// clear the current configuration
	m_transforms.clear();

	// Outgoing Event type -- i.e. what will the outgoing event be transformed into
	// Default (UNDEFINED_TERM_REF) -- make it the same as incoming event type
	// 	<OutgoingEvent>obj-term</OutgoingEvent>
	m_event_type = Vocabulary::UNDEFINED_TERM_REF;
	std::string event_type_str;
	if (ConfigManager::getConfigOption(OUTGOING_EVENT_ELEMENT_NAME, event_type_str, config_ptr))
	{
		if (!event_type_str.empty())
			m_event_type = v.findTerm(event_type_str);
	}

	// This really doesn't make much sense anymore -- you can wire the delivery of the original right through
	// it would make sense, if it was possible to deliver "if-not-changed" but TR2 always changes...
	// 	<DeliverOriginal>always|if-not-changed|never</DeliveryOriginal>		-> DEFAULT: never
	m_deliver_original = DO_NEVER;
	std::string deliver_original_str;
	if (ConfigManager::getConfigOption(DELIVER_ORIGINAL_NAME, deliver_original_str, config_ptr))
	{
		if (deliver_original_str == "true" || deliver_original_str == "always")
			m_deliver_original = DO_ALWAYS;
		else if (deliver_original_str == "if-not-changed")
			m_deliver_original = DO_SOMETIMES;
		// Could add code to throw if d_o_s is not "never"
	}

	// What fields/terms of the original event should be COPIED into the new event
	// <CopyOriginal>all-terms|if-not-defined|none</CopyOriginal>			-> DEFAULT: if-not-defined
	m_copy_original = COPY_UNCHANGED;
	std::string copy_original_str;
	if (ConfigManager::getConfigOption(COPY_ORIGINAL_ELEMENT_NAME, copy_original_str, config_ptr))
	{
		if (copy_original_str == "all-terms")
			m_copy_original = COPY_ALL;
		else if (copy_original_str == "none")
			m_copy_original = COPY_NONE;
		// Could add code to throw if c_o_s is not "if-not-defined"
	}

	// now, parse transformation rules
	// [rpt]	<Transformation>
	xmlNodePtr transformation_node = config_ptr;
	while ( (transformation_node = ConfigManager::findConfigNodeByName(TRANSFORMATION_ELEMENT_NAME, transformation_node)) != NULL)
	{
		// parse new Transformation rule

		// get the Term used for the Transformation rule
		//	<Term>src-term</Term>
		std::string term_id;
		if (! ConfigManager::getConfigOption(TERM_ELEMENT_NAME, term_id,
											 transformation_node->children))
			throw EmptyTermException(getId());

		// make sure that the Term is valid
		const Vocabulary::TermRef term_ref = v.findTerm(term_id);
		if (term_ref == Vocabulary::UNDEFINED_TERM_REF)
			throw UnknownTermException(getId());

		// get the Type of transformation
		//	<Type>AssignValue|AssignTerm|Lookup|Rules</Type>
		std::string type_str;
		if (! ConfigManager::getConfigOption(TYPE_ELEMENT_NAME, type_str,
											 transformation_node->children))
			throw EmptyTypeException(getId());	// TODO: Improve the error message

		// Add the transformation
		const bool debug_mode = getReactionEngine().getDebugMode();
		Transform *new_transform;
		if (type_str == "AssignValue")
			new_transform = new TransformAssignValue(v, v[term_ref], transformation_node->children, debug_mode);
		else if (type_str == "AssignTerm")
			new_transform = new TransformAssignTerm(v, v[term_ref], transformation_node->children, debug_mode);
		else if (type_str == "Lookup")
			new_transform = new TransformLookup(v, v[term_ref], transformation_node->children, debug_mode);
		else if (type_str == "Rules")
			new_transform = new TransformRules(v, v[term_ref], transformation_node->children, debug_mode);
		else if (type_str == "Regex")
			new_transform = new TransformRegex(v, v[term_ref], transformation_node->children, debug_mode);
		else if (type_str == "SplitTerm")
			new_transform = new TransformSplitTerm(v, v[term_ref], transformation_node->children, debug_mode);
		else if (type_str == "JoinTerm")
			new_transform = new TransformJoinTerm(v, v[term_ref], transformation_node->children, debug_mode);
		else if (type_str == "URLEncode")
			new_transform = new TransformURLEncode(v, v[term_ref], transformation_node->children, debug_mode);
		else if (type_str == "URLDecode")
			new_transform = new TransformURLDecode(v, v[term_ref], transformation_node->children, debug_mode);
		else
			throw InvalidTransformation(type_str);

		m_transforms.push_back(new_transform);

		// step to the next Comparison rule
		transformation_node = transformation_node->next;
	}
}