* | Inspire Internet Relay Chat Daemon |
* +------------------------------------+
*
- * InspIRCd: (C) 2002-2008 InspIRCd Development Team
- * See: http://www.inspircd.org/wiki/index.php/Credits
+ * InspIRCd: (C) 2002-2009 InspIRCd Development Team
+ * See: http://wiki.inspircd.org/Credits
*
* This program is free but copyrighted software; see
* the file COPYING for details.
return rv;
}
-char * strtok_r(char *_String, const char *_Control, char **_Context)
-{
- unsigned char *str;
- const unsigned char *ctl = (const unsigned char*)_Control;
- unsigned char map[32];
-
- if (_Context == 0 || !_Control)
- return 0;
-
- if (!(_String != NULL || *_Context != NULL))
- return 0;
-
- memset(map, 0, 32);
-
- do {
- map[*ctl >> 3] |= (1 << (*ctl & 7));
- } while (*ctl++);
-
- /* If string is NULL, set str to the saved
- * pointer (i.e., continue breaking tokens out of the string
- * from the last strtok call) */
- if (_String != NULL)
- {
- str = (unsigned char*)_String;
- }
- else
- {
- str = (unsigned char*)*_Context;
- }
-
- /* Find beginning of token (skip over leading delimiters). Note that
- * there is no token iff this loop sets str to point to the terminal
- * null (*str == 0) */
- while ((map[*str >> 3] & (1 << (*str & 7))) && *str != 0)
- {
- str++;
- }
-
- _String = (char*)str;
-
- /* Find the end of the token. If it is not the end of the string,
- * put a null there. */
- for ( ; *str != 0 ; str++ )
- {
- if (map[*str >> 3] & (1 << (*str & 7)))
- {
- *str++ = 0;
- break;
- }
- }
-
- /* Update context */
- *_Context = (char*)str;
-
- /* Determine if a token has been found. */
- if (_String == (char*)str)
- {
- return NULL;
- }
- else
- {
- return _String;
- }
-}
-
void setcolor(int color_code)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color_code);
return 1;
}
-/*void IPC::Check()
-{
- if (hIPCPipe == INVALID_HANDLE_VALUE)
- return;
-
- DWORD bytes;
- DWORD action;
-
- BOOL res = ReadFile(hIPCPipe, &action, sizeof(DWORD), &bytes, 0);
- if (!res)
- {
- if (GetLastError() != ERROR_SEM_TIMEOUT)
- Instance->Logs->Log("win32",DEFAULT, "IPC Pipe Error %u: %s", GetLastError(), dlerror());
- return;
- }
-
- switch (action)
- {
- case IPC_MESSAGE_REHASH:
- Instance->Rehash("due to IPC message");
- break;
-
- case IPC_MESSAGE_DIE:
- Instance->Exit(0);
- break;
-
- case IPC_MESSAGE_RESTART:
- Instance->Restart("IPC_MESSAGE_RESTART received by mailslot.");
- break;
- }
-}*/
-
-
/* These three functions were created from looking at how ares does it
* (...and they look far tidier in C++)
*/
int getcpu()
{
HRESULT hres;
+ int cpu = -1;
/* Use WQL, similar to SQL, to construct a query that lists the cpu usage and pid of all processes */
IEnumWbemClassObject* pEnumerator = NULL;
- hres = pSvc->ExecQuery(bstr_t("WQL"),
- bstr_t("Select PercentProcessorTime,IDProcess from Win32_PerfFormattedData_PerfProc_Process"),
- WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, NULL, &pEnumerator);
-
- /* Query didn't work */
- if (FAILED(hres))
- return -1;
- IWbemClassObject *pclsObj = NULL;
- ULONG uReturn = 0;
-
- /* Iterate the query results */
- while (pEnumerator)
- {
- VARIANT vtProp;
- /* Next item */
- HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn);
+ BSTR Language = SysAllocString(L"WQL");
+ BSTR Query = SysAllocString(L"Select PercentProcessorTime,IDProcess from Win32_PerfFormattedData_PerfProc_Process");
- /* No more items left */
- if (uReturn == 0)
- break;
+ hres = pSvc->ExecQuery(Language, Query, WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, NULL, &pEnumerator);
- /* Find process ID */
- hr = pclsObj->Get(L"IDProcess", 0, &vtProp, 0, 0);
- if (!FAILED(hr))
+ /* Query didn't work */
+ if (!FAILED(hres))
+ {
+ IWbemClassObject *pclsObj = NULL;
+ ULONG uReturn = 0;
+
+ /* Iterate the query results */
+ while (pEnumerator)
{
- /* Matches our process ID? */
- if (vtProp.uintVal == GetCurrentProcessId())
+ VARIANT vtProp;
+ /* Next item */
+ HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn);
+
+ /* No more items left */
+ if (uReturn == 0)
+ break;
+
+ /* Find process ID */
+ hr = pclsObj->Get(L"IDProcess", 0, &vtProp, 0, 0);
+ if (!FAILED(hr))
{
- VariantClear(&vtProp);
- /* Get CPU percentage for this process */
- hr = pclsObj->Get(L"PercentProcessorTime", 0, &vtProp, 0, 0);
- if (!FAILED(hr))
+ /* Matches our process ID? */
+ if (vtProp.uintVal == GetCurrentProcessId())
{
- /* Deal with wide string ickyness. Who in their right
- * mind puts a number in a bstrVal wide string item?!
- */
VariantClear(&vtProp);
- int cpu = 0;
- std::wstringstream out(vtProp.bstrVal);
- out >> cpu;
- pEnumerator->Release();
- pclsObj->Release();
- return cpu;
+ /* Get CPU percentage for this process */
+ hr = pclsObj->Get(L"PercentProcessorTime", 0, &vtProp, 0, 0);
+ if (!FAILED(hr))
+ {
+ /* Deal with wide string ickyness. Who in their right
+ * mind puts a number in a bstrVal wide string item?!
+ */
+ VariantClear(&vtProp);
+ cpu = 0;
+ std::wstringstream out(vtProp.bstrVal);
+ out >> cpu;
+ break;
+ }
}
}
}
+
+ pEnumerator->Release();
+ pclsObj->Release();
}
- pEnumerator->Release();
- pclsObj->Release();
- return -1;
+
+ SysFreeString(Language);
+ SysFreeString(Query);
+
+ return cpu;
}