示例#1
0
int Test_server::run()
{
    pre_log("begin to start thread child module.\n");

    // 启动各个模块线程
    m_module1->start();
//    m_module2->start();

    for (int i=0; ; i++)
    {
        // 检查信号退出
        if ((SIGINT == get_signal()) || (SIGTERM == get_signal()))
        {
            pre_log("catch signal %d. exit\n", get_signal());
            m_module1->set_signal(get_signal());
//            m_module2->set_signal(get_signal());
            break;
        }

        sleep(1);
    }

    m_module1->join();
    delete m_module1;
    m_module1 = NULL;

//    m_module2->join();
//    delete m_module2;
//    m_module2 = NULL;

    return 0;
}
示例#2
0
int Test_server::load_config()
{
    pre_log("start to load test server config file\n");

    // 打开配置文件
    Inifile inifile;

    if (inifile.open(get_config_file()) == false)
    {
        printf("load %s inifile failed\n", get_config_file());
        return 1;
    }

    m_module1 = new Module1;
//    m_module2 = new Module2;

    m_module1->set_name("module1");
//    m_module2->set_name("module2");

    //读取global配置信息
    char buffer[100];
    inifile.get_value("global", "log_dir", buffer, sizeof(buffer));
    pre_log("read global config, log_dir %s\n", buffer);

    m_module1->init_log("module1", buffer, "debug");
//    m_module2->init_log("module2", buffer, "debug");

    return 0;
}
示例#3
0
int RakNet_core_server::load_config()
{
    pre_log("start to load test server config file\n");

    // 打开配置文件
    Inifile inifile;

    if (inifile.open(get_config_file()) == false)
    {
        printf("load %s inifile failed\n", get_config_file());
        return 1;
    }

    m_network_module = new Network_module;

    //读取global配置信息
    char buffer[100];
    inifile.get_value("global", "log_dir", buffer, sizeof(buffer));
    pre_log("read global config, log_dir %s\n", buffer);

    m_network_module->init_log("network_module", buffer, "debug");

    inifile.get_value("network_module", "max_connection", buffer, sizeof(buffer));
    m_network_module->set_max_connection(buffer);

    inifile.get_value("network_module", "max_income_connection", buffer, sizeof(buffer));
    m_network_module->set_max_income_connection(buffer);

    inifile.get_value("network_module", "local_port", buffer, sizeof(buffer));
    m_network_module->set_local_port(buffer);

    return 0;
}
示例#4
0
int pre_exec_module(module_list_t *mfunc, filelist_t *files, char *path, char *argv[], struct subdir_list *subdirs) {
	filelist_t *ftmp;
	struct subdir_list *stmp;
	hashtable_t *cfg;
	char *tmpf;
	int rc;

	// run mod_func_dir on each dir
	for (stmp = subdirs; stmp; stmp = stmp->next) {

		tmpf = malloc(strlen(path) + strlen(stmp->dir) + 2);
		if (strlen(stmp->dir) > 0)
			sprintf(tmpf, "%s/%s", path, stmp->dir);
		else {
			// we got the top-dir
			strcpy(tmpf, path);

			// run the mod_func_rel on the rlsdir.
			if (mfunc->mod_func_rel != 0) {
				pre_log("MODULE-REL", "%s %s", mfunc->mod_name, stmp->dir);
				rc = mfunc->mod_func_rel(tmpf, argv);
			}
		}

		if (mfunc->mod_func_dir != 0) {
			pre_log("MODULE-DIR", "%s %s", mfunc->mod_name, stmp->dir);

			rc = mfunc->mod_func_dir(tmpf, argv);
		}

		free(tmpf);

		// break if mod_func_dir signals not to continue.
		if (rc == 0)
			break;
	}


	// run mod_func_file on each file.
	for (ftmp = files; mfunc->mod_func_file && ftmp; ftmp = ftmp->next) {

		pre_log("MODULE-FILE", "%s %s", mfunc->mod_name, ftmp->file);

		tmpf = malloc(strlen(ftmp->file) + strlen(path) + 2);
		sprintf(tmpf, "%s/%s", path, ftmp->file);

		rc = mfunc->mod_func_file(tmpf, argv);

		free(tmpf);

		// if module returns 0, then break.
		if (rc == 0)
			break;
	}

	return 1;
}
示例#5
0
int pre_do_module(char *module, filelist_t *files, char *path, char *argv[], struct subdir_list *subdirs) {

	void *handle;
	module_list_t *module_func;
	module_list_t* (*module_loader)();
	void (*set_config)(hashtable_t *ht);
	char *err;

	pre_log("MODULE", "%s", module);

	handle = dlopen(module, RTLD_LAZY);
	if (!handle) {
		err = dlerror();
		pre_log("MODULE-ERROR", "%s \"%s\"", module, err);
		printf("Error loading module %s: %s\n", module, err);
		return 0;
	}

	module_loader = dlsym(handle, MODULE_LOADER_FUNC);
	set_config = dlsym(handle, MODULE_SETCONFIG_FUNC);

	if (!module_loader || !set_config) {
		pre_log("MODULE-ERROR", "%s %s", module, "No loader func found");
		printf("Error loading module %s: No loader func found\n");
		dlclose(handle);
		return 0;
	}

	pre_log("MODULE-RUN", "%s %s", module, path);

	set_config(get_config());

	// try to set environment if module allows.
	set_config = dlsym(handle, MODULE_SETENV_FUNC);
	if (set_config)
		set_config(get_context());

	pre_exec_module(module_loader(), files, path, argv, subdirs);

	pre_log("MODULE-DONE", "%s %s", module, path);

	dlclose(handle);

	return 1;
}
示例#6
0
int pre_handler(int argc, char *argv[]) {
	hashtable_t *env, *cfg;
	strlist_t *groups;
	char *dest_section, *destpath;
	struct stat st;
	char source[1024], destination[1024], *tmp, *group;
	char buf[1024];
	int rc;

	env = get_context();
	cfg = get_config();

	pre_log("START", "%s %s %s", ht_get(env, PROPERTY_USER), argv[1], argv[2]);

	// set etcdir for the pwd functions
	if (tmp = ht_get(cfg, PROPERTY_ETCDIR))
		pwd_set_etcdir(tmp);

	if (tmp = ht_get(cfg, PROPERTY_TEXT_HEAD))
		printf(tmp);

	groups = user_find_groups(ht_get(env, PROPERTY_USER));

	if (!groups)
		quit(" * Error finding your groups, go bug sysop!\n");

	if (argc < 2) {
		printf(USAGE);

		show_groupdirs(groups);

		quit(0);
	}

	// check if someone are trying to fool us.
	if (strchr(argv[1], '/'))
		quit(" * You cant give paths in releasename ('/' not allowed)!\n");

	char *sourcebis = getcwd(NULL, 0);

	// check if we are in a position to pre.
	group = group_find_by_dir(groups, sourcebis);

	if (!group) {
		printf(" * You are not in the group-dir of any of your groups.\n\n");

		show_groupdirs(groups);

		quit(0);
	}

	pre_log("GROUP", "%s %s", sourcebis, group);

	printf(" * Looks like this is going to be a %s pre..\n", group);
	ht_put(env, PROPERTY_GROUP, group);

	// check if we have chosen a valid destination for our pre.
	dest_section = section_find_by_name(group, argc > 2 ? argv[2] : 0);

	if (!dest_section) {
		show_groupdirs(groups);

		quit(0);
	}

	printf(" * Destination for pre will be the %s section..\n", dest_section);
	ht_put(env, "section", dest_section);

	destpath = section_expand_path(dest_section);
	ht_put(env, "RESOLVEDDESTINATION", destpath);

        strcpy(source, sourcebis);
        strcat(source, "/");
        strcat(source, argv[1]);

	// check if source dir is okay.
	if ((stat(source, &st) == -1) || !S_ISDIR(st.st_mode)) {
		sprintf(source, " * Hm, '%s' doesnt exist or isnt a dir ?\n",
				argv[1]);
		quit(source);
	}

	// touch the source.
	touch_dir(source);

	// check if destination dir exists.
	sprintf(destination, "%s/%s", destpath, argv[1]);

	rc = stat(destination, &st);

	// try rename if requested
	if ((rc == 0) && (argc > 3) && (!strcasecmp(argv[3], "force"))) {

		sprintf(buf, "%s_TRADING", destination);
		rc = rename(destination, buf);

		if (rc == 0)
			printf(" + Renamed existing to %s_TRADING ..\n", argv[1]);
		else
			printf(" ! Failed rename existing to %s_TRADING ..\n", argv[1]);
	}

	// check if destination exists.
	if (stat(destination, &st) == -1)
		pre(dest_section, destination, source, argv[1], group, argv);
	else {
		sprintf(source, " * Hm destination already exists. You're too late with pre!\n + Use SITE PRE %s %s FORCE to force pre.\n   (this will rename the existing dir, which you can then nuke or wipe afterwards!)\n");
		quit(source);
	}

	// log DONE: "<preuser>" "<pregroup>" "<release>" "<destinationdir>"
	pre_log("DONE", "\"%s\" \"%s\" \"%s\" \"%s\"",
			ht_get(env, PROPERTY_USER), group,
			argv[1], destpath);

	return 0;
}
示例#7
0
int main(int argc, char* argv[])
{
    pre_log("test server now start\n");

    bool is_daemon = false;
    const char* config_file = NULL;

    Test_server test_server;
    test_server.set_version("v1.0.0");
    test_server.set_name("test_server");

    //指定默认配置文件
    config_file = "../conf/config.ini";

    pre_log("read command line parameter\n");
    // 命令行解释
    int optch = 0;

    while ((optch=getopt(argc , argv , "c:dhv"))  != -1)
    {
        switch (optch)
        {
            case 'c':
                config_file = optarg;
                continue;

            case 'd':
                is_daemon = true;
                continue;

            case 'v':
                test_server.print_version();
                return 0;

            case 'h':
            default:
                test_server.print_usage();
                return 0;
        }
    }

    if (NULL == config_file)
    {
        test_server.print_usage();
        return 0;
    }

    // 允许没有配置文件,但指定了配置文件却没权限读取则退出失败返回
    if ((config_file[0] != '\0') && (access(config_file, R_OK) != 0))
    {
        pre_log("No access config file: (%s)\n", config_file);
        test_server.print_usage();
        return 1;
    }

    test_server.set_config_file(config_file);

    // 变成daemon进程
    if (is_daemon)
    {
        make_daemon();
    }

    test_server.start();

    return 0;
}