Esempio n. 1
0
struct KeyValue *db_lookup(struct DB *const db, uint16_t klen,
                           const uint8_t *const key) {
    uint8_t hash[HASHBYTES] __attribute__((aligned(8)));
    SHA1(key, klen, hash);

    stat_inc(&(db->stat.nr_get));
    const uint64_t ticket = rwlock_reader_lock(&(db->rwlock));
    // 1st lookup at active table[0]
    // 2nd lookup at active table[1]
    for (uint64_t i = 0; i < 2; i++) {
        struct Table *t = db->active_table[i];
        if (!t)
            continue;
        // immutable item
        struct KeyValue *const kv = table_lookup(t, klen, key, hash);
        if (kv) {
            rwlock_reader_unlock(&(db->rwlock), ticket);
            stat_inc(&(db->stat.nr_get_at_hit[i]));
            return kv;
        }
    }

    // 3rd lookup into vcroot
    struct KeyValue *const kv2 =
        recursive_lookup(&(db->stat), db->vcroot, klen, key, hash);
    rwlock_reader_unlock(&(db->rwlock), ticket);
    if (!kv2) {
        stat_inc(&(db->stat.nr_get_miss));
    }
    return kv2;
}
Esempio n. 2
0
bool db_insert(struct DB *const db, struct KeyValue *const kv) {
    stat_inc(&(db->stat.nr_set));
    while (!db_insert_try(db, kv)) {
        db_wait_active_table(db);
        stat_inc(&(db->stat.nr_set_retry));
    }
    return true;
}
Esempio n. 3
0
bot_t *echo_run(dlist_t * dlist_node, bot_t * bot)
{
	char *dl_module_arg_after_options, *dl_options_ptr;

	debug(bot, "echo_run: Entered\n");

	if (!dlist_node || !bot)
		return NULL;

	debug(bot,
	      "echo_run: Entered: initial output buf=[%s], input buf=[%s], mod_arg=[%s]\n",
	      bot->txt_data_out, bot->txt_data_in, bot->dl_module_arg);

	stat_inc(bot, bot->trig_called);

	if (_bot_shouldreturn(bot))
		return NULL;

	MOD_OPTIONS_TOP_HALF;
	MOD_OPTIONS_BOTTOM_HALF;

	bot->shouldsend = 1;

	MOD_PARSE_TOP_HALF;
	l_new_str = echo_change_string(l_str_ptr);
	MOD_PARSE_BOTTOM_HALF;

	return bot;
}
Esempio n. 4
0
bot_t *bin_run(dlist_t * dlist_node, bot_t * bot)
{
	char *dl_module_arg_after_options, *dl_options_ptr;
	char *opt_prog = NULL, *opt_options = NULL;

	debug(bot, "bin_run: Entered\n");

	if (!dlist_node || !bot)
		return NULL;

	stat_inc(bot, bot->trig_called);

	debug(bot,
	      "bin_run: Entered: initial output buf=[%s], input buf=[%s], mod_arg=[%s]\n",
	      bot->txt_data_out, bot->txt_data_in, bot->dl_module_arg);

	if (_bot_shouldreturn(bot))
		return NULL;

	MOD_OPTIONS_TOP_HALF;
	opt_prog = strtok(dl_options_ptr, ",");
	if (opt_prog) {
		opt_options = strtok(NULL, "");
	}

	MOD_OPTIONS_BOTTOM_HALF;

	MOD_PARSE_TOP_HALF_NODL;
	l_new_str =
	    bin_change_string(bot, opt_prog, opt_options, l_str_ptr,
			      dlist_node);
	MOD_PARSE_BOTTOM_HALF_NODL;

	return bot;
}
Esempio n. 5
0
bot_t *me_run(dlist_t * dlist_node, bot_t * bot)
{
	char *dl_module_arg_after_options, *dl_options_ptr;
	int opt = 0;
	me_t me;

	debug(bot, "me_run: Entered\n");

	if (!dlist_node || !bot)
		return NULL;

	debug(bot,
	      "me_run: Entered: initial output buf=[%s], input buf=[%s], mod_arg=[%s]\n",
	      bot->txt_data_out, bot->txt_data_in, bot->dl_module_arg);

	stat_inc(bot, bot->trig_called);

	if (_bot_shouldreturn(bot))
		return NULL;

	_memset(&me, 0, sizeof(me));

	MOD_OPTIONS_TOP_HALF;
	me_parse_options(dl_options_ptr, &me);
	MOD_OPTIONS_BOTTOM_HALF;

	bot->shouldsend = 1;

	MOD_PARSE_TOP_HALF_NODL;
	l_new_str = me_change_string(l_str_ptr, opt, &me);
	MOD_PARSE_BOTTOM_HALF_NODL;

	return bot;
}
Esempio n. 6
0
bot_t *moby_run(dlist_t * dlist_node, bot_t * bot)
{
	char *dl_module_arg_after_options, *dl_options_ptr;

	int opt;

	debug(bot, "moby_run: Entered\n");

	if (!dlist_node || !bot)
		return NULL;

	stat_inc(bot, bot->trig_called);

	debug(bot,
	      "moby_run: Entered: initial output buf=[%s], input buf=[%s], mod_arg=[%s]\n",
	      bot->txt_data_out, bot->txt_data_in, bot->dl_module_arg);

	if (_bot_shouldreturn(bot))
		return NULL;

	opt = MOBY_SINGLE;

	MOD_OPTIONS_TOP_HALF;

	if (!strncasecmp_len(dl_options_ptr, "list"))
		opt = MOBY_LIST;

	MOD_OPTIONS_BOTTOM_HALF;

	MOD_PARSE_TOP_HALF;
	l_new_str = moby_change_string(l_str_ptr, opt);
	MOD_PARSE_BOTTOM_HALF;

	return bot;
}
/*
 * Allocate a page and add it to freelist of given pool.
 */
static int grow_pool(struct xv_pool *pool, gfp_t flags)
{
	struct page *page;
	struct block_header *block;

	page = alloc_page(flags);
	if (unlikely(!page))
		return -ENOMEM;

	stat_inc(&pool->total_pages);

	spin_lock(&pool->lock);
	block = get_ptr_atomic(page, 0);

	block->size = PAGE_SIZE - XV_ALIGN;
	set_flag(block, BLOCK_FREE);
	clear_flag(block, PREV_FREE);
	set_blockprev(block, 0);

	insert_block(pool, page, 0, block);

	put_ptr_atomic(block);
	spin_unlock(&pool->lock);

	return 0;
}
Esempio n. 8
0
bot_t *shake1_run(dlist_t * dlist_node, bot_t * bot)
{
	char *dl_module_arg_after_options, *dl_options_ptr;
	int opt;

	debug(bot, "shake1_run: Entered\n");

	if (!dlist_node || !bot)
		return NULL;

	stat_inc(bot, bot->trig_called);

	debug(bot,
	      "shake1_run: Entered: initial output buf=[%s], input buf=[%s], mod_arg=[%s]\n",
	      bot->txt_data_out, bot->txt_data_in, bot->dl_module_arg);

	if (_bot_shouldreturn(bot))
		return NULL;

	opt = 0;

	MOD_OPTIONS_TOP_HALF;
	MOD_OPTIONS_BOTTOM_HALF;

	MOD_PARSE_TOP_HALF_NODL;
	l_new_str = shake1_change_string(l_str_ptr, opt);
	MOD_PARSE_BOTTOM_HALF_NODL;

	return bot;
}
Esempio n. 9
0
bot_t *dumbgames_run(dlist_t * dlist_node, bot_t * bot)
{
	char *dl_module_arg_after_options, *dl_options_ptr;
	int opt, sub;

	debug(bot, "dumbgames_run: Entered\n");

	if (!dlist_node || !bot)
		return NULL;

	stat_inc(bot, bot->trig_called);

	debug(bot,
	      "dumbgames_run: Entered: initial output buf=[%s], input buf=[%s], mod_arg=[%s]\n",
	      bot->txt_data_out, bot->txt_data_in, bot->dl_module_arg);

	if (_bot_shouldreturn(bot))
		return NULL;

	sub = MOD_DUMBGAMES;

	if (!strcasecmp(bot->trig_called, "^dice"))
		sub = MOD_DUMBGAMES_DICE;
	else if (!strcasecmp(bot->trig_called, "^roulette"))
		sub = MOD_DUMBGAMES_ROULETTE;

	opt = 0;

	MOD_OPTIONS_TOP_HALF;

	opt = atoi(bot->dl_module_arg + 1);
	if (opt > 6)
		opt = 6;
	else if (opt <= 0)
		opt = 1;

	MOD_OPTIONS_BOTTOM_HALF;

	MOD_PARSE_TOP_HALF_NODL;

	switch (sub) {
	case MOD_DUMBGAMES_DICE:
		{
			l_new_str = dice_change_string(opt);
			break;
		}
	case MOD_DUMBGAMES_ROULETTE:
		{
			l_new_str = roulette_change_string(opt);
			break;
		}
	default:
		break;
	}

	MOD_PARSE_BOTTOM_HALF_NODL;

	return bot;
}
Esempio n. 10
0
bot_t *map_run(dlist_t * dlist_node, bot_t * bot)
{
	char *dl_module_arg_after_options, *dl_options_ptr;
	int opt;

	char *tok_1, *tok_2, *tok_3, *tok_4, *opt_str = NULL;

	debug(bot, "map_run: Entered\n");

	if (!dlist_node || !bot)
		return NULL;

	stat_inc(bot, bot->trig_called);

	debug(bot,
	      "map_run: Entered: initial output buf=[%s], input buf=[%s], mod_arg=[%s]\n",
	      bot->txt_data_out, bot->txt_data_in, bot->dl_module_arg);

	if (_bot_shouldreturn(bot))
		return NULL;

	opt = MAP_OPT_NORMAL;

	MOD_OPTIONS_TOP_HALF;

	tok_1 = strtok(dl_options_ptr, ",");
	if (!tok_1)
		return NULL;
	tok_2 = strtok(NULL, ",");
	if (!tok_2)
		return NULL;
	tok_3 = strtok(NULL, ",");
	if (!tok_3)
		return NULL;
	tok_4 = strtok(NULL, "");
	if (!tok_4)
		return NULL;

	if (!strcasecmp(tok_2, "PIPE"))
		tok_2 = "|";

	if (!strcasecmp(tok_3, "PIPE"))
		tok_3 = "|";

	opt_str = _eat_whitespace(tok_2);

	MOD_OPTIONS_BOTTOM_HALF;

	if (!opt_str)
		return NULL;

	MOD_PARSE_TOP_HALF_NODL;
	l_new_str =
	    map_change_string(dlist_node, bot, l_str_ptr, opt, tok_2, tok_3,
			      _eat_whitespace(tok_4));
	MOD_PARSE_BOTTOM_HALF_NODL;

	return bot;
}
Esempio n. 11
0
bot_t *gnull_run(dlist_t * dlist_node, bot_t * bot)
{
	dlist_t *dptr_gmod = NULL;
	bot_gmod_elm_t *gmod = NULL;
	gnull_t *gnull = NULL;

	char *dl_module_arg_after_options, *dl_options_ptr;

	debug(bot, "gnull_run: Entered\n");

	if (!dlist_node || !bot)
		return NULL;

	stat_inc(bot, bot->trig_called);

	debug(bot,
	      "gnull_run: Entered: initial output buf=[%s], input buf=[%s], gmod_arg=[%s]\n",
	      bot->txt_data_out, bot->txt_data_in, bot->dl_module_arg);

	if (_bot_shouldreturn(bot))
		return NULL;

	dptr_gmod =
	    (dlist_t *) gmodule_find_gmod_dptr(bot, gmod_gnull_info.trigger,
					       gmod_gnull_info.trigger_ext);
	if (!dptr_gmod)
		return NULL;

	gmod = (bot_gmod_elm_t *) dlist_data(dptr_gmod);
	if (!gmod) {
		debug(NULL, "gnull_run: GNULL GMOD=NULL\n");
		return NULL;
	}

	if (!gmod->data) {
		debug(NULL, "gnull_run: GIRCD GMOD->DATA = NULL, ALLOCATING\n");
		gnull_gmod_init(bot, gmod, dptr_gmod);
		gnull = gmod->data;
	}

	MOD_OPTIONS_TOP_HALF;

	gnull_process_options(gnull, dl_options_ptr);

	MOD_OPTIONS_BOTTOM_HALF;

	gmodule_set_can_pass_up(gmod);
	gmodule_set_can_pass_down(gmod);

	gnull_input(dptr_gmod, bot);

	gmodule_set_has_run(gmod);

	return bot;
}
Esempio n. 12
0
static struct KeyValue *recursive_lookup(struct Stat *const stat,
                                         struct VirtualContainer *const vc,
                                         uint64_t klen,
                                         const uint8_t *const key,
                                         const uint8_t *const hash) {
    // lookup in current vc
    // test if using bloomcontainer
    uint64_t bitmap = UINT64_MAX;
    if (vc->cc.bc) {
        const uint64_t index = table_select_barrel(hash);
        assert(index < UINT64_C(0x100000000));
        const uint64_t *phv = ((const uint64_t *)(&(hash[12])));
        const uint64_t hv = *phv;
        bitmap = bloomcontainer_match(vc->cc.bc, (uint32_t)index, hv);
        stat_inc(&(stat->nr_fetch_bc));
    }
    for (int64_t j = vc->cc.count - 1; j >= 0; j--) {
        struct MetaTable *const mt = vc->cc.metatables[j];
        if (!mt)
            continue;

        if ((bitmap & (1u << j)) == 0u) {
            stat_inc(&(stat->nr_true_negative));
            continue;  // skip
        }
        struct KeyValue *const kv = metatable_lookup(mt, klen, key, hash);
        if (kv) {
            stat_inc(&(stat->nr_get_vc_hit[vc->start_bit]));
            return kv;
        }
    }
    // in sub_vc
    const uint64_t sub_id = compaction_select_table(hash, vc->start_bit + 3);
    if (vc->sub_vc[sub_id]) {
        return recursive_lookup(stat, vc->sub_vc[sub_id], klen, key, hash);
    }
    return NULL;
}
Esempio n. 13
0
bot_t *rant_run(dlist_t * dlist_node, bot_t * bot)
{
	char *dl_module_arg_after_options, *dl_options_ptr;
	int opt;

	debug(bot, "rant_run: Entered\n");

	if (!dlist_node || !bot)
		return NULL;

	stat_inc(bot, bot->trig_called);

	debug(bot,
	      "rant_run: Entered: initial output buf=[%s], input buf=[%s], mod_arg=[%s]\n",
	      bot->txt_data_out, bot->txt_data_in, bot->dl_module_arg);

	if (_bot_shouldreturn(bot))
		return NULL;

	opt = 0;

	opt |= MOD_RANT_PUSH;

	MOD_OPTIONS_TOP_HALF;

	if (!strncasecmp_len(dl_options_ptr, "clear")) {
		opt &= ~MOD_RANT_PUSH;
		opt = MOD_RANT_CLEAR;
	} else if (!strncasecmp_len(dl_options_ptr, "size")) {
		opt &= ~MOD_RANT_PUSH;
		opt = MOD_RANT_SIZE;
	} else if (!strncasecmp_len(dl_options_ptr, "push")) {
		opt = MOD_RANT_PUSH;
	} else if (!strncasecmp_len(dl_options_ptr, "pop")) {
		opt &= ~MOD_RANT_PUSH;
		opt = MOD_RANT_POP;
	} else if (!strncasecmp_len(dl_options_ptr, "list")) {
		opt &= ~MOD_RANT_PUSH;
		opt = MOD_RANT_LIST;
	}

	MOD_OPTIONS_BOTTOM_HALF;

	MOD_PARSE_TOP_HALF_NODL;
	l_new_str = rant_change_string(bot, l_str_ptr, opt);
	MOD_PARSE_BOTTOM_HALF_NODL;

	return bot;
}
Esempio n. 14
0
static void compaction_main(struct DB *const db,
                            struct VirtualContainer *const vc,
                            const uint64_t nr_feed) {
    struct Compaction comp;
    const double sec0 = debug_time_sec();
    compaction_initial(&comp, db, vc, nr_feed);
    // feed (must sequential)
    compaction_feed_all(&comp);
    compaction_build_bt_all(&comp);
    compaction_dump_and_bc_all(&comp);
    compaction_update_vc(&comp);
    compaction_free_old(&comp);
    db_log_diff(db, sec0, "COMP @%" PRIu64 " %2" PRIu64, vc->start_bit / 3u,
                nr_feed);
    stat_inc(&(db->stat.nr_compaction));
}
Esempio n. 15
0
bot_t *cmph_run(dlist_t * dlist_node, bot_t * bot)
{
	char *dl_module_arg_after_options, *dl_options_ptr;
	int opt;

	debug(bot, "cmph_run: Entered\n");

	if (!dlist_node || !bot)
		return NULL;

	stat_inc(bot, bot->trig_called);

	debug(bot,
	      "cmph_run: Entered: initial output buf=[%s], input buf=[%s], mod_arg=[%s]\n",
	      bot->txt_data_out, bot->txt_data_in, bot->dl_module_arg);

	if (_bot_shouldreturn(bot))
		return NULL;

	opt = 0;

	MOD_OPTIONS_TOP_HALF;

	if (!strncasecmp_len(dl_options_ptr, "clear")) {
		opt = MOD_CMPH_CLEAR;
	} else if (!strncasecmp_len(dl_options_ptr, "size")) {
		opt = MOD_CMPH_SIZE;
	} else if (!strncasecmp_len(dl_options_ptr, "find")) {
		opt = MOD_CMPH_FIND;
	} else if (!strncasecmp_len(dl_options_ptr, "build")) {
		opt = MOD_CMPH_BUILD;
	} else if (!strncasecmp_len(dl_options_ptr, "list")) {
		opt = MOD_CMPH_LIST;
	}

	MOD_OPTIONS_BOTTOM_HALF;

	MOD_PARSE_TOP_HALF_NODL;
	l_new_str = cmph_change_string(bot, l_str_ptr, opt);
	MOD_PARSE_BOTTOM_HALF_NODL;

	return bot;
}
Esempio n. 16
0
bot_t *mod_auto_rejoin_run(dlist_t * dlist_node, bot_t * bot)
{

	if (!dlist_node || !bot)
		return NULL;

	stat_inc(bot, bot->trig_called);

	debug(bot, "mod_auto_rejoin_run: Entered\n");

	debug(bot,
	      "mod_auto_rejoin_run: Entered: initial hook buf=[%s], input buf=[%s], mod_arg=[%s]\n",
	      bot->txt_data_out, bot->txt_data_in, bot->dl_module_arg);

	if (_bot_shouldreturn(bot))
		return NULL;

	return bot;
}
Esempio n. 17
0
bool db_multi_insert(struct DB *const db, uint64_t nr_items,
                     const struct KeyValue *const kvs) {
    uint64_t i = 0;
    while (i < nr_items) {
        const uint64_t ticket = rwlock_writer_lock(&(db->rwlock));
        struct Table *at = db->active_table[0];
        while (i < nr_items) {
            if (!table_insert_kv_safe(at, &kvs[i]))
                break;
            i++;
        }
        rwlock_writer_unlock(&(db->rwlock), ticket);

        if (i < nr_items) {
            db_wait_active_table(db);
            stat_inc(&(db->stat.nr_set_retry));
        }
    }
    stat_inc_n(&(db->stat.nr_set), nr_items);
    return true;
}
Esempio n. 18
0
bot_t *attrib_run(dlist_t * dlist_node, bot_t * bot)
{
	char *dl_module_arg_after_options, *dl_options_ptr;
	int opt, sub;

	if (!dlist_node || !bot)
		return NULL;

	stat_inc(bot, bot->trig_called);

	debug(bot, "attrib_run: Entered\n");

	debug(bot,
	      "attrib_run: Entered: initial output buf=[%s], input buf=[%s], mod_arg=[%s]\n",
	      bot->txt_data_out, bot->txt_data_in, bot->dl_module_arg);

	if (_bot_shouldreturn(bot))
		return NULL;

	sub = MOD_ATTRIB;
	if (!strcasecmp(bot->trig_called, "^bold"))
		sub = MOD_ATTRIB_BOLD;
	else if (!strcasecmp(bot->trig_called, "^underline"))
		sub = MOD_ATTRIB_UNDERLINE;
	else if (!strcasecmp(bot->trig_called, "^multi"))
		sub = MOD_ATTRIB_MULTI;

	opt = 0;

	MOD_OPTIONS_TOP_HALF;
	MOD_OPTIONS_BOTTOM_HALF;

	MOD_PARSE_TOP_HALF;
/*
  l_new_str = attrib_change_string (l_str_ptr, opt);
*/
	switch (sub) {
	case MOD_ATTRIB:
		{
			l_new_str = attrib_change_string(bot, l_str_ptr, opt);
			break;
		}
	case MOD_ATTRIB_BOLD:
		{
			l_new_str = bold_change_string(bot, l_str_ptr, opt);
			break;
		}
	case MOD_ATTRIB_UNDERLINE:
		{
			l_new_str =
			    underline_change_string(bot, l_str_ptr, opt);
			break;
		}
	case MOD_ATTRIB_MULTI:
		{
			l_new_str = multi_change_string(bot);
			break;
		}
	default:
		break;
	}

	MOD_PARSE_BOTTOM_HALF;

	return bot;
}
Esempio n. 19
0
bot_t *leet_run(dlist_t * dlist_node, bot_t * bot)
{
	char *str_ptr = NULL, *dl_module_arg_after_options, *dl_options_ptr;
	int opt_1, opt_2;

	debug(bot, "leet_run: Entered\n");

	if (!dlist_node || !bot)
		return NULL;

	stat_inc(bot, bot->trig_called);

	debug(bot,
	      "leet_run: Entered: initial output buf=[%s], input buf=[%s], mod_arg=[%s]\n",
	      bot->txt_data_out, bot->txt_data_in, bot->dl_module_arg);

	if (_bot_shouldreturn(bot))
		return NULL;

	opt_1 = 1;
	opt_2 = 0;

	MOD_OPTIONS_TOP_HALF;

	if (!strncasecmp_len(dl_options_ptr, "0")) {
		opt_1 = 0;
	} else if (!strncasecmp_len(dl_options_ptr, "1")) {
		opt_1 = 1;
	} else if (!strncasecmp_len(dl_options_ptr, "2")) {
		opt_1 = 2;
	} else if (!strncasecmp_len(dl_options_ptr, "3")) {
		opt_1 = 3;
	}

	else {
		opt_1 = 1;
	}

	str_ptr = strstr(dl_options_ptr, ",");
	if (str_ptr) {
		str_ptr++;

		if (!strncasecmp_len(str_ptr, "0")) {
			opt_2 = 0;
		} else if (!strncasecmp_len(str_ptr, "1")) {
			opt_2 = 1;
		} else if (!strncasecmp_len(str_ptr, "2")) {
			opt_2 = 2;
		} else {
			opt_2 = 0;
		}
	}

	MOD_OPTIONS_BOTTOM_HALF;

	MOD_PARSE_TOP_HALF;
	l_new_str = leet_change_string(l_str_ptr, opt_1, opt_2);
	MOD_PARSE_BOTTOM_HALF;

	return bot;
}
Esempio n. 20
0
bot_t *fork_run(dlist_t * dlist_node, bot_t * bot)
{
    char *dl_module_arg_after_options, *dl_options_ptr;
    char **argv = NULL;
    int argc = 0;
    int c, opt;

    debug(bot, "fork_run: Entered\n");

    if (!dlist_node || !bot)
        return NULL;

    debug(bot,
          "fork_run: Entered: initial output buf=[%s], input buf=[%s], mod_arg=[%s]\n",
          bot->txt_data_out, bot->txt_data_in, bot->dl_module_arg);

    stat_inc(bot, bot->trig_called);

    if (_bot_shouldreturn(bot))
        return NULL;

    opt = 0;

    MOD_OPTIONS_TOP_HALF;
    argv =
        tokenize_str2argv(dl_options_ptr, &argc, TOKENIZE_STR2ARGV_ARGV0);
    if (argv) {

        optind = 0;

        while ((c = getopt(argc, argv, "vd")) != -1) {
            switch (c) {
            case 'v':
            {
                opt |= MOD_FORK_OPT_VERBOSE;
                break;
            }
            case 'd':
            {
                opt |= MOD_FORK_OPT_DAEMON;
                break;
            }
            default:
                break;
            }

        }

        tokenize_destroy_array(NULL, argv);
    }

    MOD_OPTIONS_BOTTOM_HALF;

    bot->shouldsend = 1;

    MOD_PARSE_TOP_HALF_NODL;
    l_new_str = fork_change_string(bot, l_str_ptr, opt);
    MOD_PARSE_BOTTOM_HALF_NODL;

    return bot;
}
Esempio n. 21
0
bot_t *rf_run(dlist_t * dlist_node, bot_t * bot)
{
    dlist_t *dptr;
    module_t *module;
    char *dl_module_arg_after_options, *dl_options_ptr;
    char **array, trig_tmp[32];
    int array_size;

    int rand_val;

    array = NULL;
    array_size = 0;

    debug(bot, "rf_run: Entered\n");

    if (!dlist_node || !bot)
        return NULL;

    if (gi->mongo_isconnected == 0) {
        debug(bot, "rf_run: Mongo is not connected\n");
        return NULL;
    }

    stat_inc(bot, bot->trig_called);

    debug(bot,
          "rf_run: Entered: initial output buf=[%s], input buf=[%s], mod_arg=[%s]\n",
          bot->txt_data_out, bot->txt_data_in, bot->dl_module_arg);

    if (_bot_shouldreturn(bot))
        return NULL;

    MOD_OPTIONS_TOP_HALF;

    array =
        tokenize_array(bot, dl_options_ptr,
                       TOKENIZE_NORMAL | TOKENIZE_LEAVEQUOTES,
                       ":::", &array_size);
    if (!array)
        return NULL;

    MOD_OPTIONS_BOTTOM_HALF;

    if (!array)
        return NULL;

    rand_val = rand() % (array_size);

    strlcpy_safe(&trig_tmp[1], ret_trig(&array[rand_val][1]),
                 sizeof(trig_tmp) - 2);
    if (!_sNULL(&trig_tmp[1]))
        return NULL;

    trig_tmp[0] = '^';

    dptr = xmodule_find_by_trig_dptr(XMODULE_TYPE_MODULE, trig_tmp);
    if (dptr) {
        module = (module_t *) dlist_data(dptr);
        if (module) {
            if (module->run) {
                strlcpy_buf(bot->txt_data_in, array[rand_val]);
                bot->dl_module_arg =
                    bot->txt_data_in + strlen(module->trigger);
                module->run(dptr, bot);
            }
        }
    }

    tokenize_destroy_array(bot, array);

    return bot;
}
Esempio n. 22
0
bot_t *gdaemon_run(dlist_t * dlist_node, bot_t * bot)
{
	dlist_t *dptr_gmod = NULL;
	bot_gmod_elm_t *gmod = NULL;
	gdaemon_t *gdaemon = NULL;
	pid_t pid = 0;

	char *dl_module_arg_after_options, *dl_options_ptr;

	debug(bot, "gdaemon_run: Entered\n");

	if (!dlist_node || !bot)
		return NULL;

	stat_inc(bot, bot->trig_called);

	debug(bot,
	      "gdaemon_run: Entered: initial output buf=[%s], input buf=[%s], gmod_arg=[%s]\n",
	      bot->txt_data_out, bot->txt_data_in, bot->dl_module_arg);

	if (_bot_shouldreturn(bot))
		return NULL;

	dptr_gmod =
	    (dlist_t *) gmodule_find_gmod_dptr(bot, gmod_gdaemon_info.trigger,
					       gmod_gdaemon_info.trigger_ext);
	if (!dptr_gmod)
		return NULL;

	gmod = (bot_gmod_elm_t *) dlist_data(dptr_gmod);
	if (!gmod) {
		debug(NULL, "gdaemon_run: GDAEMON GMOD=NULL");
		return NULL;
	}

	if (!gmod->data) {
		debug(NULL, "gdaemon_run: GIRCD GMOD->DATA = NULL, ALLOCATING");
		gdaemon_gmod_init(bot, gmod, dptr_gmod);
		gdaemon = gmod->data;
	}

	MOD_OPTIONS_TOP_HALF;

	gdaemon_process_options(gdaemon, dl_options_ptr);

	MOD_OPTIONS_BOTTOM_HALF;

	gmodule_set_can_pass_up(gmod);
	gmodule_set_can_pass_down(gmod);

	gmodule_set_has_run(gmod);

	pid = bot_fork_clean(bot);
	if (!pid) {
		char **mod_names = NULL;
		bot_t *bots[2] = { bot, NULL };

		mod_names = (char **)
		    dlist_convert_dlist_to_array(gdaemon->dl_mod_names);

		bot_daemon(gdaemon->flags, mod_names, bots, gdaemon->new_name,
			   gdaemon->fd_unix_path);

		gi->pid_child = getpid();
	} else
		return bot;

	gdaemon_input(dptr_gmod, bot);

	return bot;
}
Esempio n. 23
0
// pthread
static void *thread_active_dumper(void *ptr) {
    struct DB *const db = (typeof(db))ptr;

    conc_set_affinity_n(2);
    while (db->active_table[0]) {
        // active
        pthread_mutex_lock(&(db->mutex_active));
        if ((db->active_table[0]->volume == 0) && db->closing) {
            pthread_mutex_unlock(&(db->mutex_active));
            table_free(db->active_table[0]);
            db->active_table[0] = NULL;
            break;
        }
        while ((!table_full(db->active_table[0])) && (!db->closing)) {
            pthread_cond_wait(&(db->cond_active), &(db->mutex_active));
        }
        // shift active table
        const uint64_t ticket1 = rwlock_writer_lock(&(db->rwlock));
        db->active_table[1] = db->active_table[0];
        if (db->closing) {
            db->active_table[0] = NULL;
        } else {
            db->active_table[0] = table_alloc_default(15.0);
        }
        rwlock_writer_unlock(&(db->rwlock), ticket1);
        // notify writers
        pthread_cond_broadcast(&(db->cond_writer));
        pthread_mutex_unlock(&(db->mutex_active));

        struct Table *const table1 = db->active_table[1];
        if (containermap_unused(db->cms[0]) < 8u) {
            db_log(db,
                   "ContainerMap is near full, dropping current active-table");
            sleep(10);
            const uint64_t ticket2 = rwlock_writer_lock(&(db->rwlock));
            db->active_table[1] = NULL;
            rwlock_writer_unlock(&(db->rwlock), ticket2);
        } else if (table1->volume > 0) {
            const bool rbt = table_build_bloomtable(table1);
            assert(rbt);

            const uint64_t mtid = db_table_dump(db, table1, 0);
            struct MetaTable *const mt =
                db_load_metatable(db, mtid, db->cms[0]->raw_fd, false);
            assert(mt);
            stat_inc_n(&(db->stat.nr_write[0]), TABLE_NR_BARRELS);
            mt->bt = table1->bt;
            // mark !active_table[1]->bt before free it

            // wait for room
            pthread_mutex_lock(&(db->mutex_current));
            while (db->vcroot->cc.count == DB_CONTAINER_NR) {
                pthread_cond_wait(&(db->cond_root_producer),
                                  &(db->mutex_current));
            }
            pthread_mutex_unlock(&(db->mutex_current));

            // insert
            const uint64_t ticket2 = rwlock_writer_lock(&(db->rwlock));
            const bool ri = vc_insert_internal(db->vcroot, mt, NULL);
            assert(ri);
            stat_inc(&(db->stat.nr_active_dumped));
            // alert compaction thread if have work to be done
            if (db->vcroot->cc.count >= 8) {
                pthread_mutex_lock(&(db->mutex_current));
                pthread_cond_broadcast(&(db->cond_root_consumer));
                pthread_mutex_unlock(&(db->mutex_current));
            }
            db->active_table[1] = NULL;
            rwlock_writer_unlock(&(db->rwlock), ticket2);

            // post process
            table1->bt = NULL;
        }
        table_free(table1);
    }
    pthread_exit(NULL);
    return NULL;
}
Esempio n. 24
0
bot_t *quiz_run(dlist_t * dlist_node, bot_t * bot)
{
	char *dl_module_arg_after_options, *dl_options_ptr;
	int opt;

	debug(bot, "quiz_run: Entered\n");

	quiz_clear_db_from_files();

	if (!bot)
		return NULL;

	if (gi->mongo_isconnected == 0) {
		debug(bot, "quiz_run: Mongo is not connected\n");
		return NULL;
	}

	stat_inc(bot, bot->trig_called);

	debug(bot,
	      "quiz_run: Entered: initial output buf=[%s], input buf=[%s], mod_arg=[%s]\n",
	      bot->txt_data_out, bot->txt_data_in, bot->dl_module_arg);

	if (_bot_shouldreturn(bot))
		return NULL;

	opt = QUIZ_OPT_ANSWER;

	if (!strcasecmp(bot->trig_called, "^answer")
	    || !strcasecmp(bot->trig_called, "^ans")) {
		opt = QUIZ_OPT_ANSWER;
	}

	MOD_OPTIONS_TOP_HALF;

	if (xstrcasestr_len(dl_options_ptr, "SETUP", len_options_area)) {
		opt = QUIZ_OPT_SETUP;
	} else if (xstrcasestr_len(dl_options_ptr, "answer", len_options_area)) {
		opt = QUIZ_OPT_ANSWER;
	}

	else if (xstrcasestr_len(dl_options_ptr, "get", len_options_area)) {
		opt = QUIZ_OPT_GET;

	} else if (xstrcasestr_len(dl_options_ptr, "add", len_options_area)) {
		opt = QUIZ_OPT_ADD;
	}

	else if (xstrcasestr_len(dl_options_ptr, "info", len_options_area)) {
		opt = QUIZ_OPT_INFO;
	}

	else if (xstrcasestr_len(dl_options_ptr, "getmore", len_options_area)) {

		opt = QUIZ_OPT_GETMORE;
	} else if (xstrcasestr_len(dl_options_ptr, "list", len_options_area)) {
		opt = QUIZ_OPT_LIST;
	}

	else if (xstrcasestr_len(dl_options_ptr, "timeout", len_options_area)) {
		opt = QUIZ_OPT_TIMEOUT;
	} else
	    if (xstrcasestr_len
		(dl_options_ptr, "clear_winners", len_options_area)) {
		opt = QUIZ_OPT_CLEAR_WINNERS;
	} else if (xstrcasestr_len(dl_options_ptr, "clear", len_options_area)) {
		opt = QUIZ_OPT_CLEAR;
	} else if (xstrcasestr_len(dl_options_ptr, "size", len_options_area)) {
		opt = QUIZ_OPT_SIZE;
	} else if (xstrcasestr_len(dl_options_ptr, "winners", len_options_area)) {
		opt = QUIZ_OPT_WINNERS;
	} else if (xstrcasestr_len(dl_options_ptr, "channel", len_options_area)) {
		opt = QUIZ_OPT_CHANNEL;
	} else if (xstrcasestr_len(dl_options_ptr, "multi", len_options_area)) {
		opt = QUIZ_OPT_MULTI;
	} else
	    if (xstrcasestr_len
		(dl_options_ptr, "newline", len_options_area - 1)) {
		opt = QUIZ_OPT_NEWLINES;
	} else
	    if (xstrcasestr_len
		(dl_options_ptr, "hidekey", len_options_area - 1)) {
		opt = QUIZ_OPT_HIDEKEY;
	} else
	    if (xstrcasestr_len(dl_options_ptr, "fixkey", len_options_area - 1))
	{
		opt = QUIZ_OPT_FIXKEY;
	}

	MOD_OPTIONS_BOTTOM_HALF;

	MOD_PARSE_TOP_HALF_NODL;
	l_new_str = quiz_change_string(bot, l_str_ptr, opt);
	if (l_new_str)
		bot->var_multi = 1;
	MOD_PARSE_BOTTOM_HALF_NODL;

	return bot;

}
Esempio n. 25
0
/** thread routine for the thread which does unprotection of regions */
static void *unprot_thread(void *dummy_param) {
	unprot_thread_g = self_thread();
	if(semaph_post(&init_sem_g)) {
		fprintf(stderr, "unprot_thread: can\'t post init semaphore\n");
		return 0;
	}
	rqueue_elem_t elem;
	// the number of regions which have been unprotected, but have not yet been
	// synced to host
	unsigned pending_regions = 0;
	// starting and ending time for this time period
	rtime_t start_time, end_time;
	while(1) {
		rqueue_get(&unprot_queue_g, &elem);
		region_t *region = elem.region;
		switch(elem.op) {

		case REGION_OP_QUIT:
			// quit the thread
			return 0;

		case REGION_OP_UNPROTECT:
			//fprintf(stderr, "unprotect request received\n");
			stat_inc(GPUVM_STAT_PAGEFAULTS);
			if(region->prot_status == PROT_NONE) {
				// fully unprotect region
				// remove protection, stop threads if necessary
				if(!pending_regions) {
					if(stat_enabled())
						start_time = rtime_get();
					//fprintf(stderr, "stopping other threads\n");
					stop_other_threads();
					//fprintf(stderr, "stopped other threads\n");
				}				
				region_unprotect(region);
				//fprintf(stderr, "unprotect request satisfied - BLOCK\n");
				region_post_unprotect(region);
			
				pending_regions++;
				elem.op = REGION_OP_SYNC_TO_HOST;
				rqueue_put(&sync_queue_g, &elem);
			} else if(region->prot_status == PROT_READ) {
				// mark all data as actual on host only, no need to stop threads				
				subreg_list_t *list;
				region_unprotect(region);
				for(list = region->subreg_list; list; list = list->next)
					subreg_sync_to_host(list->subreg);
				//fprintf(stderr, "unprotect request satisfied - RO\n");
				region_post_unprotect(region);
			} else {
				// do nothing
				//fprintf(stderr, "unprotect request satisfied - NONE\n");
				region_post_unprotect(region);
			}
			//fprintf(stderr, "unprotect message posted\n");
			break;

		case REGION_OP_SYNCED_TO_HOST:
			pending_regions--;
			if(!pending_regions) {			 
				//fprintf(stderr, "continuing other threads\n");
				cont_other_threads();
				if(stat_enabled()) {
					end_time = rtime_get();
					stat_acc_unblocked_double(GPUVM_STAT_PAGEFAULT_TIME, 
													rtime_diff(&start_time, &end_time));
				}
			}  // if(!pending_regions)
			break;

		default:
			fprintf(stderr, "unprot_thread: invalid region operation %d\n", elem.op);
			break;
		}  // switch(elem->op)

	}  // while()
}  // unprot_thread()