Example #1
0
// iptables thread
void NsIpTablesThread(THREAD *thread, void *param)
{
	IPTABLES_STATE *state;
	NATIVE_STACK *s;
	UINT counter = 0;
	BUF *seed_buf;
	char exe_name[MAX_PATH];
	if (thread == NULL || param == NULL)
	{
		return;
	}

	s = (NATIVE_STACK *)param;

	seed_buf = NewBuf();

	WriteBuf(seed_buf, s->MacAddress, 6);

	GetExeName(exe_name, sizeof(exe_name));
	WriteBufStr(seed_buf, exe_name);

	state = StartAddIpTablesEntryForNativeStack(seed_buf->Buf, seed_buf->Size);

	FreeBuf(seed_buf);

	if (state == NULL)
	{
		NoticeThreadInit(thread);
		return;
	}

	s->IpTablesInitOk = true;
	NoticeThreadInit(thread);

	while (true)
	{
		UINT wait_interval;

		if (s->IpTablesHalt)
		{
			break;
		}

		if (MaintainAddIpTablesEntryForNativeStack(state))
		{
			counter = 0;
		}

		counter++;
		wait_interval = NS_CHECK_IPTABLES_INTERVAL_INIT * counter;
		wait_interval = MIN(wait_interval, NS_CHECK_IPTABLES_INTERVAL_MAX);

		//Debug("NsIpTablesThread: wait for %u\n", wait_interval);
		Wait(s->IpTablesHaltEvent, wait_interval);
	}

	EndAddIpTablesEntryForNativeStack(state);
}
Example #2
0
/**
 * \brief Return application path.
 */
CString COptions::GetAppPath()
{
    CString exe = GetExeName();
    int i = exe.ReverseFind(_T('\\'));
    if (i == -1)
        return _T("");
    exe = exe.Left(i);
    return exe;
}
static LPSTR FindProgram() {
	static CHAR result[MAX_PATH + 1];

	CHAR path[MAX_PATH + 1];
	LPSTR exefolder = GetExeFolder();
	if (PathCombine(path, exefolder, "vim??") == NULL) {
		Fail("PathCombine");
	}

	WIN32_FIND_DATA fdd;
	HANDLE find;
	if ((find = FindFirstFile(path, &fdd)) == INVALID_HANDLE_VALUE) {
		if (GetLastError() == ERROR_FILE_NOT_FOUND) {
			return NULL;
		}
		Fail("FindFirstFile");
	}

	std::vector<std::string> candidates;
	do {
		candidates.push_back(std::string(fdd.cFileName));
	} while(FindNextFile(find, &fdd));

	if (GetLastError() != ERROR_NO_MORE_FILES) {
		Fail("FindNextFile");
	}
	FindClose(find);

	std::sort(candidates.begin(), candidates.end(), sort_vim_folders);
	if (PathCombine(result, exefolder, candidates[0].c_str()) == NULL) {
		Fail("PathCombine");
	}
	if (PathAppend(result, GetExeName()) == NULL) {
		Fail("PathAppend");
	}
	return result;
}
Example #4
0
bool do_load_config(const char* appname, char **argv, CmdLineObj& cmdline, ConfigCollection& coll) {
	// Set GLE_TOP
	// -> prefer environment var GLE_TOP
	// -> otherwise, locate relative to executable location
	string conf_name;
	bool has_top = false;
	bool has_config = false;
	const char* top = getenv("GLE_TOP");
	vector<string> triedLocations;
	if (top == NULL || top[0] == 0) {
		string exe_name;
		bool has_exe_name = GetExeName(appname, argv, exe_name);
		if (has_exe_name) {
			GetDirName(exe_name, GLE_BIN_DIR);
			StripDirSep(GLE_BIN_DIR);
			#ifdef GLETOP_CD
				// Try relative path
				GLE_TOP_DIR = GLEAddRelPath(exe_name, GLETOP_CD+1, GLETOP_REL);
				has_config = try_load_config_sub(conf_name, triedLocations);
				// Try one level higher as executable
				if (!has_config) {
					GLE_TOP_DIR = GLEAddRelPath(exe_name, 2, NULL);
					has_config = try_load_config_sub(conf_name, triedLocations);
				}
				// Try with absolute path
				if (!has_config) {
					GLE_TOP_DIR = GLETOP_ABS;
					has_config = try_load_config_sub(conf_name, triedLocations);
				}
			#else
				GLE_TOP_DIR = exe_name;
				StripPathComponents(&GLE_TOP_DIR, 2);
			#endif
		} else {
			// The user will see as error messege: "$GLE_TOP/some_file" not found.
			GLE_TOP_DIR = "$GLE_TOP";
		}
	} else {
		has_top = true;
		GLE_TOP_DIR = top;
	}
	StripDirSep(GLE_TOP_DIR);
	if (!has_config) {
		// Try load config file
		// -> first $GLE_TOP/glerc
		if (conf_name == "") {
			// Only update conf_name if it was not yet set
			// To make error message if glerc not found more interpretable
			conf_name = GLE_TOP_DIR + DIR_SEP + "glerc";
			if (std::find(triedLocations.begin(), triedLocations.end(), conf_name) == triedLocations.end()) {
				triedLocations.push_back(conf_name);
				has_config = try_load_config(conf_name);
			}
		}
	}
	if (!check_correct_version(conf_name, has_top, has_config, triedLocations, coll)) {
		return false;
	}
	GLEInterface* iface = GLEGetInterfacePointer();
	string uconf = iface->getUserConfigLocation();
	if (uconf != "") {
		// -> on Unix also $HOME/.glerc
		try_load_config(uconf);
	}
	// Set values for -v option
	init_installed_versions(cmdline, &coll);
	return has_config;
}