- add many return value checks and error-messages for system-calls
- fix memory-leak when reading tcp-connection stats
This commit is contained in:
parent
81d79d6568
commit
4437aea144
|
@ -43,6 +43,7 @@
|
|||
#include <pdh.h>
|
||||
#include <pdhmsg.h>
|
||||
#include <lmcons.h>
|
||||
#include <lmerr.h>
|
||||
#include <lmwksta.h>
|
||||
#include <lmapibuf.h>
|
||||
|
||||
|
@ -129,7 +130,7 @@ static HQUERY pdhQueryHandle = 0;
|
|||
// *****************************************************************
|
||||
|
||||
// local function protos
|
||||
void initPerfKeyList(void);
|
||||
static void initPerfKeyList(void);
|
||||
|
||||
static void placePerfKeysFromReg(const PerfKey key, unsigned int index1,
|
||||
unsigned int index2);
|
||||
|
@ -147,25 +148,26 @@ void gkrellm_sys_main_init(void)
|
|||
WSADATA wsdata;
|
||||
int err;
|
||||
|
||||
// initialize winsock
|
||||
if (_GK.debug_level & DEBUG_SYSDEP)
|
||||
printf("Starting Winsock\n");
|
||||
err = WSAStartup(MAKEWORD(1,1), &wsdata);
|
||||
if (err != 0 && _GK.debug_level & DEBUG_SYSDEP)
|
||||
printf("Starting Winsock failed with error code %i\n", err);
|
||||
|
||||
if (pdhQueryHandle == 0)
|
||||
if (err != 0)
|
||||
{
|
||||
if (_GK.debug_level & DEBUG_SYSDEP)
|
||||
printf("Opening Pdh");
|
||||
printf("Starting Winsock failed with error code %i\n", err);
|
||||
return;
|
||||
}
|
||||
|
||||
if (_GK.debug_level & DEBUG_SYSDEP)
|
||||
printf("Opening Pdh\n");
|
||||
status = PdhOpenQuery(NULL, 0, &pdhQueryHandle);
|
||||
if (status != ERROR_SUCCESS)
|
||||
if (status != ERROR_SUCCESS || pdhQueryHandle == 0)
|
||||
{
|
||||
if (_GK.debug_level & DEBUG_SYSDEP)
|
||||
printf("Opening Pdh failed with error code %ld\n", status);
|
||||
pdhQueryHandle = 0;
|
||||
}
|
||||
}
|
||||
// get perflib localized key names
|
||||
initPerfKeyList();
|
||||
|
||||
// do this once
|
||||
info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
|
||||
|
@ -176,37 +178,19 @@ void gkrellm_sys_main_init(void)
|
|||
|
||||
// initialize call back structure for plugins
|
||||
win32_init_callbacks();
|
||||
|
||||
// get perflib localized key names
|
||||
initPerfKeyList();
|
||||
}
|
||||
|
||||
|
||||
void gkrellm_sys_main_cleanup(void)
|
||||
{
|
||||
int i;
|
||||
#if defined(WIN32_CLIENT)
|
||||
NOTIFYICONDATA nid;
|
||||
|
||||
// remove system tray icon
|
||||
nid.cbSize = sizeof(NOTIFYICONDATA);
|
||||
nid.hWnd = GDK_WINDOW_HWND(gkrellm_get_top_window()->window);
|
||||
nid.uID = 1;
|
||||
Shell_NotifyIcon(NIM_DELETE, &nid);
|
||||
|
||||
if (_GK.withdrawn)
|
||||
{
|
||||
// remove from bluebox slit
|
||||
/*HWND slitHwnd = FindWindowEx(NULL, NULL, "BControl", "BSlitWindow");
|
||||
if (slitHwnd != NULL)
|
||||
{
|
||||
SendMessage(slitHwnd, BM_SLITMESSAGE, BSM_DELETEWINDOW, (LPARAM) GDK_WINDOW_HWND(gkrellm_get_top_window()->window));
|
||||
}
|
||||
RemoveProp(GDK_WINDOW_HWND(gkrellm_get_top_window()->window), "BSlitControl");
|
||||
SetParent(GDK_WINDOW_HWND(gkrellm_get_top_window()->window), NULL);
|
||||
if (_GK.debug_level & DEBUG_SYSDEP)
|
||||
printf("Removing from slit\n");*/
|
||||
//SetWindowPos(0, m_nLeft, m_nTop, m_nWidth, m_nHeight, SWP_NOZORDER);
|
||||
}
|
||||
#endif // WIN32_CLIENT
|
||||
|
||||
if (_GK.debug_level & DEBUG_SYSDEP)
|
||||
|
@ -219,10 +203,6 @@ void gkrellm_sys_main_cleanup(void)
|
|||
Sleep(500);
|
||||
}
|
||||
|
||||
// stop performance gathering
|
||||
if (_GK.debug_level & DEBUG_SYSDEP)
|
||||
printf("Stopping perfomance monitoring.\n");
|
||||
|
||||
// Close PDH query-handle
|
||||
if (_GK.debug_level & DEBUG_SYSDEP)
|
||||
printf("Closing Pdh\n");
|
||||
|
@ -245,17 +225,23 @@ void gkrellm_sys_main_cleanup(void)
|
|||
static void win32_read_proc_stat(void)
|
||||
{
|
||||
static gint data_read_tick = -1;
|
||||
|
||||
if (data_read_tick == gkrellm_get_timer_ticks()) /* One read per tick */
|
||||
return;
|
||||
|
||||
data_read_tick = gkrellm_get_timer_ticks();
|
||||
if (pdhQueryHandle == 0)
|
||||
return;
|
||||
|
||||
if (pdhQueryHandle != 0)
|
||||
if (_GK.debug_level & DEBUG_SYSDEP)
|
||||
{
|
||||
status = PdhCollectQueryData(pdhQueryHandle);
|
||||
printf("Collecting PDH query data\n");
|
||||
}
|
||||
|
||||
status = PdhCollectQueryData(pdhQueryHandle);
|
||||
if (status != ERROR_SUCCESS)
|
||||
{
|
||||
printf("Collecting PDH query data failed with status %ld\n",
|
||||
status);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -370,25 +356,34 @@ typedef struct {
|
|||
} SharedData;
|
||||
|
||||
|
||||
static int ReadMBMSharedData(void);
|
||||
static int ReadSFSharedData(void);
|
||||
static gboolean ReadMBMSharedData(void);
|
||||
static gboolean ReadSFSharedData(void);
|
||||
|
||||
|
||||
static int ReadSharedData(void)
|
||||
static gboolean ReadSharedData(void)
|
||||
{
|
||||
printf("ReadSharedData()\n");
|
||||
static gint sens_data_read_tick = -1;
|
||||
static gboolean sens_data_valid = FALSE;
|
||||
|
||||
// try getting data from MBM
|
||||
if (ReadMBMSharedData() == 1)
|
||||
{
|
||||
// and try SpeedFan in case MBM is absent
|
||||
return ReadSFSharedData();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
if (sens_data_read_tick == gkrellm_get_timer_ticks()) /* One read per tick */
|
||||
return sens_data_valid;
|
||||
sens_data_read_tick = gkrellm_get_timer_ticks();
|
||||
|
||||
if (_GK.debug_level & DEBUG_SYSDEP)
|
||||
printf("Reading MBM or SpeedFan data\n");
|
||||
|
||||
// Try getting data from MBM
|
||||
sens_data_valid = ReadMBMSharedData();
|
||||
|
||||
// Try SpeedFan in case MBM is absent
|
||||
if (!sens_data_valid)
|
||||
sens_data_valid = ReadSFSharedData();
|
||||
|
||||
return sens_data_valid;
|
||||
} // ReadSharedData()
|
||||
|
||||
|
||||
static int ReadMBMSharedData(void)
|
||||
static gboolean ReadMBMSharedData(void)
|
||||
{
|
||||
SharedData *ptr;
|
||||
SharedSensor *sens;
|
||||
|
@ -398,13 +393,13 @@ static int ReadMBMSharedData(void)
|
|||
|
||||
hSData=OpenFileMapping(FILE_MAP_READ, FALSE, "$M$B$M$5$S$D$");
|
||||
if (hSData == 0)
|
||||
return 1;
|
||||
return FALSE;
|
||||
|
||||
ptr = (SharedData *)MapViewOfFile(hSData, FILE_MAP_READ, 0, 0, 0);
|
||||
if (ptr == 0)
|
||||
{
|
||||
CloseHandle(hSData);
|
||||
return 1;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
totalCount = 0;
|
||||
|
@ -419,11 +414,8 @@ static int ReadMBMSharedData(void)
|
|||
for (j = 0; j < totalCount; j++)
|
||||
{
|
||||
sens = &(ptr->sdSensor[j]);
|
||||
|
||||
switch (sens->ssType)
|
||||
{
|
||||
case stUnknown:
|
||||
break;
|
||||
case stTemperature:
|
||||
temperatures[tempCount] = sens->ssCurrent;
|
||||
++tempCount;
|
||||
|
@ -436,17 +428,13 @@ static int ReadMBMSharedData(void)
|
|||
fans[fanCount] = sens->ssCurrent;
|
||||
++fanCount;
|
||||
break;
|
||||
case stMhz:
|
||||
break;
|
||||
case stPercentage:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
UnmapViewOfFile(ptr);
|
||||
CloseHandle(hSData);
|
||||
|
||||
return 0;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
@ -474,7 +462,8 @@ typedef struct
|
|||
} SFSharedMemory;
|
||||
#pragma pack(pop)
|
||||
|
||||
static int ReadSFSharedData(void)
|
||||
|
||||
static gboolean ReadSFSharedData(void)
|
||||
{
|
||||
SFSharedMemory *ptr;
|
||||
HANDLE hSData;
|
||||
|
@ -482,13 +471,13 @@ static int ReadSFSharedData(void)
|
|||
|
||||
hSData = OpenFileMapping(FILE_MAP_READ, FALSE, TEXT("SFSharedMemory_ALM"));
|
||||
if (hSData == 0)
|
||||
return 1;
|
||||
return FALSE;
|
||||
|
||||
ptr = (SFSharedMemory *)MapViewOfFile(hSData, FILE_MAP_READ, 0, 0, 0);
|
||||
if (ptr == 0)
|
||||
{
|
||||
CloseHandle(hSData);
|
||||
return 1;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
tempCount = min(NrTemperature, ptr->NumTemps);
|
||||
|
@ -505,71 +494,48 @@ static int ReadSFSharedData(void)
|
|||
|
||||
UnmapViewOfFile(ptr);
|
||||
CloseHandle(hSData);
|
||||
return 0;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/* ======================================================================== */
|
||||
|
||||
|
||||
gboolean gkrellm_sys_sensors_get_voltage(gchar *device_name, gint id,
|
||||
gint iodev, gint inter, gfloat *volt)
|
||||
{
|
||||
|
||||
if (iodev < NrVoltage && iodev >= 0) {
|
||||
if (ReadSharedData() == 1) {
|
||||
*volt = 0;
|
||||
if (iodev < 0 || iodev >= NrVoltage)
|
||||
return FALSE;
|
||||
if (ReadSharedData() == FALSE)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
*volt = voltages[iodev];
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
else {
|
||||
*volt = 0;
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
gboolean gkrellm_sys_sensors_get_fan(gchar *device_name, gint id,
|
||||
gint iodev, gint inter, gfloat *fan)
|
||||
{
|
||||
|
||||
if (iodev < NrFan && iodev >= 0) {
|
||||
if (ReadSharedData() == 1) {
|
||||
*fan = 0;
|
||||
if (iodev >= NrFan || iodev < 0)
|
||||
return FALSE;
|
||||
if (ReadSharedData() == FALSE)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
*fan = fans[iodev];
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
else {
|
||||
*fan = 0;
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
gboolean gkrellm_sys_sensors_get_temperature(gchar *device_name, gint id,
|
||||
gint iodev, gint inter, gfloat *temp)
|
||||
{
|
||||
|
||||
if (iodev < NrTemperature && iodev >= 0) {
|
||||
if (ReadSharedData() == 1) {
|
||||
*temp = 0;
|
||||
if (iodev >= NrTemperature || iodev < 0)
|
||||
return FALSE;
|
||||
if (ReadSharedData() == FALSE)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
*temp = temperatures[iodev];
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
else {
|
||||
*temp = 0;
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
gboolean gkrellm_sys_sensors_init(void)
|
||||
{
|
||||
|
@ -579,45 +545,47 @@ gboolean gkrellm_sys_sensors_init(void)
|
|||
if (_GK.debug_level & DEBUG_SYSDEP)
|
||||
printf("Initializing sensors.\n");
|
||||
|
||||
{
|
||||
//TODO: determine number of sensors at startup? This could cause
|
||||
// user confusion in case mbm/speedfan is started after gkrellm
|
||||
tempCount = 0;
|
||||
voltCount = 0;
|
||||
fanCount = 0;
|
||||
|
||||
for (i = 0; i < NrTemperature; i++)
|
||||
{
|
||||
sprintf(buf, "Temp %i", i);
|
||||
gkrellm_sensors_add_sensor(SENSOR_TEMPERATURE, NULL, buf,
|
||||
tempCount, tempCount, 0,
|
||||
1, 0, NULL, buf);
|
||||
//TODO: i18n?
|
||||
snprintf(buf, sizeof(buf), "Temp %i", i);
|
||||
gkrellm_sensors_add_sensor(SENSOR_TEMPERATURE, NULL, buf, tempCount,
|
||||
tempCount, 0, 1, 0, NULL, buf);
|
||||
++tempCount;
|
||||
}
|
||||
|
||||
for (i = 0; i < NrVoltage; i++)
|
||||
{
|
||||
sprintf(buf, "Volt %i", i);
|
||||
gkrellm_sensors_add_sensor(SENSOR_VOLTAGE, NULL, buf,
|
||||
voltCount, voltCount, 0,
|
||||
1, 0, NULL, buf);
|
||||
snprintf(buf, sizeof(buf), "Volt %i", i);
|
||||
gkrellm_sensors_add_sensor(SENSOR_VOLTAGE, NULL, buf, voltCount,
|
||||
voltCount, 0, 1, 0, NULL, buf);
|
||||
++voltCount;
|
||||
}
|
||||
|
||||
for (i = 0; i < NrFan; i++)
|
||||
{
|
||||
sprintf(buf, "Fan %i", i);
|
||||
gkrellm_sensors_add_sensor(SENSOR_FAN, NULL, buf,
|
||||
fanCount, fanCount, 0,
|
||||
1, 0, NULL, buf);
|
||||
snprintf(buf, sizeof(buf), "Fan %i", i);
|
||||
gkrellm_sensors_add_sensor(SENSOR_FAN, NULL, buf, fanCount, fanCount,
|
||||
0, 1, 0, NULL, buf);
|
||||
++fanCount;
|
||||
}
|
||||
}
|
||||
|
||||
if (_GK.debug_level & DEBUG_SYSDEP)
|
||||
printf("Initialized sensors for %i temps, %i volts, %i fans.\n", tempCount, voltCount, fanCount);
|
||||
{
|
||||
printf("Initialized sensors for %i temps, %i volts and %i fans.\n",
|
||||
tempCount, voltCount, fanCount);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/* ===================================================================== */
|
||||
/* CPU monitor interface */
|
||||
/* ===================================================================== */
|
||||
|
@ -635,19 +603,38 @@ void gkrellm_sys_cpu_read_data(void)
|
|||
DWORD type;
|
||||
PDH_FMT_COUNTERVALUE value;
|
||||
int i;
|
||||
gulong userInt = 0, idleInt = 0, sysInt = 0;
|
||||
gulong userInt = 0;
|
||||
gulong idleInt = 0;
|
||||
gulong sysInt = 0;
|
||||
|
||||
if (pdhQueryHandle == 0)
|
||||
return;
|
||||
|
||||
win32_read_proc_stat();
|
||||
|
||||
if (pdhQueryHandle != 0)
|
||||
{
|
||||
for (i = 0; i < numCPUs; i++)
|
||||
{
|
||||
status = PdhGetFormattedCounterValue(cpuUserCounter[i], PDH_FMT_LONG, &type, &value);
|
||||
userInt = (status != 0 ? 0 : value.longValue);
|
||||
if (status != ERROR_SUCCESS)
|
||||
{
|
||||
printf("Getting PDH-counter (cpu user time) failed with status %ld\n", status);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
userInt = value.longValue;
|
||||
}
|
||||
|
||||
status = PdhGetFormattedCounterValue(cpuSysCounter[i], PDH_FMT_LONG, &type, &value);
|
||||
sysInt = (status != 0 ? 0 : value.longValue);
|
||||
if (status != ERROR_SUCCESS)
|
||||
{
|
||||
printf("Getting PDH-counter (cpu sys time) failed with status %ld\n", status);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
sysInt = value.longValue;
|
||||
}
|
||||
|
||||
// user time defined as total - system
|
||||
userInt -= sysInt;
|
||||
|
@ -661,7 +648,6 @@ void gkrellm_sys_cpu_read_data(void)
|
|||
gkrellm_cpu_assign_data(i, user[i], 0/*nice[i]*/, sys[i], idle[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
gboolean gkrellm_sys_cpu_init(void)
|
||||
|
@ -684,7 +670,7 @@ gboolean gkrellm_sys_cpu_init(void)
|
|||
if (numCPUs > MAX_CPU)
|
||||
numCPUs = MAX_CPU;
|
||||
|
||||
if (pdhQueryHandle != 0)
|
||||
if (pdhQueryHandle != 0 && perfKeyList[CpuStart] != NULL && perfKeyList[CpuTime] != NULL)
|
||||
{
|
||||
for (i = 0; i < numCPUs; i++)
|
||||
{
|
||||
|
@ -727,22 +713,38 @@ void gkrellm_sys_net_read_data(void)
|
|||
DWORD type;
|
||||
PDH_FMT_COUNTERVALUE value;
|
||||
|
||||
if (pdhQueryHandle == 0)
|
||||
return;
|
||||
|
||||
win32_read_proc_stat();
|
||||
|
||||
if (pdhQueryHandle != 0)
|
||||
{
|
||||
for (i = 0; i < numAdapters; i++)
|
||||
{
|
||||
status = PdhGetFormattedCounterValue(netRecCounter[i], PDH_FMT_LONG, &type, &value);
|
||||
if (status != ERROR_SUCCESS)
|
||||
{
|
||||
printf("Getting PDH-counter (net recv counter) failed with status %ld\n", status);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
rx[i] += value.longValue / _GK.update_HZ;
|
||||
}
|
||||
|
||||
status = PdhGetFormattedCounterValue(netSendCounter[i], PDH_FMT_LONG, &type, &value);
|
||||
if (status != ERROR_SUCCESS)
|
||||
{
|
||||
printf("Getting PDH-counter (net send counter) failed with status %ld\n", status);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
tx[i] += value.longValue / _GK.update_HZ;
|
||||
}
|
||||
|
||||
gkrellm_net_assign_data(netName[i], rx[i], tx[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void gkrellm_sys_net_check_routes(void)
|
||||
{
|
||||
|
@ -879,6 +881,7 @@ gchar * gkrellm_sys_disk_name_from_device(gint device_number, gint unit_number,
|
|||
{
|
||||
static gchar name[32];
|
||||
|
||||
//TODO: i18n?
|
||||
sprintf(name, "Disk%s", diskName[device_number]);
|
||||
*order = device_number;
|
||||
return name;
|
||||
|
@ -896,31 +899,42 @@ void gkrellm_sys_disk_read_data(void)
|
|||
*/
|
||||
DWORD type;
|
||||
PDH_FMT_COUNTERVALUE value;
|
||||
double readInt = 0, writeInt = 0;
|
||||
double readInt = 0;
|
||||
double writeInt = 0;
|
||||
int i;
|
||||
|
||||
if (pdhQueryHandle == 0)
|
||||
return;
|
||||
|
||||
win32_read_proc_stat();
|
||||
|
||||
if (pdhQueryHandle != 0)
|
||||
for (i = 0; i < numDisks; i++)
|
||||
{
|
||||
for (i = 0; i < numDisks; i++) {
|
||||
status = PdhGetFormattedCounterValue(diskReadCounter[i], PDH_FMT_DOUBLE, &type, &value);
|
||||
if (status != ERROR_SUCCESS)
|
||||
{
|
||||
printf("Getting PDH-counter (disk read cnt) failed with status %ld\n", status);
|
||||
return;
|
||||
}
|
||||
readInt = value.doubleValue / _GK.update_HZ;
|
||||
|
||||
status = PdhGetFormattedCounterValue(diskWriteCounter[i], PDH_FMT_DOUBLE, &type, &value);
|
||||
if (status != ERROR_SUCCESS)
|
||||
{
|
||||
printf("Getting PDH-counter (disk write cnt) failed with status %ld\n", status);
|
||||
return;
|
||||
}
|
||||
writeInt = value.doubleValue / _GK.update_HZ;
|
||||
|
||||
diskread[i] += readInt;
|
||||
diskwrite[i] += writeInt;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < numDisks; i++)
|
||||
{
|
||||
//gkrellm_disk_assign_data_nth(i, diskread[i], diskwrite[i]);
|
||||
gkrellm_disk_assign_data_by_device(i, 0,
|
||||
diskread[i], diskwrite[i], FALSE);
|
||||
gkrellm_disk_assign_data_by_device(i, 0, diskread[i], diskwrite[i],
|
||||
FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1021,24 +1035,36 @@ gboolean gkrellm_sys_disk_init(void)
|
|||
|
||||
void gkrellm_sys_proc_read_data(void)
|
||||
{
|
||||
static gulong last_n_forks = 0;
|
||||
static gfloat fload = 0;
|
||||
|
||||
DWORD type;
|
||||
PDH_FMT_COUNTERVALUE value;
|
||||
gint n_running = 0, n_processes = 0;
|
||||
gulong n_forks = 0;
|
||||
static gulong last_n_forks = 0;
|
||||
gulong new_forks;
|
||||
static gfloat fload = 0;
|
||||
gfloat a;
|
||||
|
||||
if (pdhQueryHandle == 0)
|
||||
return;
|
||||
|
||||
win32_read_proc_stat();
|
||||
|
||||
if (pdhQueryHandle != 0) {
|
||||
status = PdhGetFormattedCounterValue(processCounter, PDH_FMT_LONG, &type, &value);
|
||||
if (status != ERROR_SUCCESS)
|
||||
{
|
||||
printf("Getting PDH-counter (process cnt) failed with status %ld\n", status);
|
||||
return;
|
||||
}
|
||||
n_processes = value.longValue;
|
||||
|
||||
status = PdhGetFormattedCounterValue(threadCounter, PDH_FMT_LONG, &type, &value);
|
||||
n_forks = value.longValue;
|
||||
if (status != ERROR_SUCCESS)
|
||||
{
|
||||
printf("Getting PDH-counter (thread cnt) failed with status %ld\n", status);
|
||||
return;
|
||||
}
|
||||
n_forks = value.longValue;
|
||||
|
||||
n_running = n_processes;
|
||||
|
||||
|
@ -1070,18 +1096,19 @@ void gkrellm_sys_proc_read_data(void)
|
|||
|
||||
void gkrellm_sys_proc_read_users(void)
|
||||
{
|
||||
gint n_users = 0;
|
||||
gint n_users = 1;
|
||||
DWORD entriesRead;
|
||||
DWORD totalEntries;
|
||||
LPBYTE ptr;
|
||||
NET_API_STATUS err;
|
||||
NET_API_STATUS nerr;
|
||||
|
||||
err = NetWkstaUserEnum(NULL, 0, &ptr, MAX_PREFERRED_LENGTH, &entriesRead, &totalEntries, NULL);
|
||||
if (_GK.debug_level & DEBUG_SYSDEP)
|
||||
printf("Getting number of logged in users.\n");
|
||||
|
||||
if (err != 0 && err != ERROR_MORE_DATA)
|
||||
n_users = 1;
|
||||
else
|
||||
n_users = totalEntries;
|
||||
nerr = NetWkstaUserEnum(NULL, 0, &ptr, MAX_PREFERRED_LENGTH, &entriesRead,
|
||||
&totalEntries, NULL);
|
||||
if (nerr == NERR_Success)
|
||||
n_users = entriesRead;
|
||||
|
||||
NetApiBufferFree(ptr);
|
||||
|
||||
|
@ -1094,16 +1121,16 @@ gboolean gkrellm_sys_proc_init(void)
|
|||
if (_GK.debug_level & DEBUG_SYSDEP)
|
||||
printf("Initializing process monitor.\n");
|
||||
|
||||
if (pdhQueryHandle != 0)
|
||||
{
|
||||
if (pdhQueryHandle == 0)
|
||||
return FALSE;
|
||||
|
||||
if (_GK.debug_level & DEBUG_SYSDEP)
|
||||
printf("Adding %s as process monitor.\n", perfKeyList[NumProcesses]);
|
||||
printf("Adding '%s' as process monitor.\n", perfKeyList[NumProcesses]);
|
||||
status = PdhAddCounter(pdhQueryHandle, perfKeyList[NumProcesses], 0, &processCounter);
|
||||
|
||||
if (_GK.debug_level & DEBUG_SYSDEP)
|
||||
printf("Adding %s as thread monitor.\n", perfKeyList[NumThreads]);
|
||||
printf("Adding '%s' as thread monitor.\n", perfKeyList[NumThreads]);
|
||||
status = PdhAddCounter(pdhQueryHandle, perfKeyList[NumThreads], 0, &threadCounter);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -1143,14 +1170,6 @@ void gkrellm_sys_mem_read_data(void)
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void gkrellm_sys_swap_read_data(void)
|
||||
{
|
||||
SYSTEM_INFO si;
|
||||
|
@ -1205,11 +1224,11 @@ void gkrellm_sys_swap_read_data(void)
|
|||
gkrellm_swap_assign_data(swapTotal, swapUsed, swapIn, swapOut);
|
||||
}
|
||||
|
||||
|
||||
gboolean gkrellm_sys_mem_init(void)
|
||||
{
|
||||
if (_GK.debug_level & DEBUG_SYSDEP)
|
||||
printf("Initialized Memory monitor.\n");
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -1227,31 +1246,34 @@ void gkrellm_sys_battery_read_data(void)
|
|||
{
|
||||
gboolean available, on_line, charging;
|
||||
gint percent, time_left;
|
||||
|
||||
SYSTEM_POWER_STATUS power;
|
||||
|
||||
GetSystemPowerStatus(&power);
|
||||
|
||||
if ((power.BatteryFlag & L_NO_BATTERY) == L_NO_BATTERY || (power.BatteryFlag & L_UNKNOWN) == L_UNKNOWN)
|
||||
if ( (power.BatteryFlag & L_NO_BATTERY) == L_NO_BATTERY
|
||||
|| (power.BatteryFlag & L_UNKNOWN) == L_UNKNOWN
|
||||
)
|
||||
{
|
||||
available = FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
available = TRUE;
|
||||
}
|
||||
|
||||
on_line = ((power.ACLineStatus & L_ON_LINE) == L_ON_LINE) ? TRUE : FALSE;
|
||||
charging= ((power.BatteryFlag & L_CHARGING) == L_CHARGING) ? TRUE : FALSE;
|
||||
|
||||
time_left = power.BatteryLifeTime;
|
||||
|
||||
percent = power.BatteryLifePercent;
|
||||
|
||||
gkrellm_battery_assign_data(0, available, on_line, charging, percent, time_left);
|
||||
}
|
||||
|
||||
|
||||
gboolean gkrellm_sys_battery_init()
|
||||
{
|
||||
if (_GK.debug_level & DEBUG_SYSDEP)
|
||||
printf("Initialized Battery monitor.\n");
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -1272,7 +1294,7 @@ void eject_win32_cdrom(gchar *device)
|
|||
char buf[25];
|
||||
DWORD numBytes;
|
||||
|
||||
if (!device || strlen(device) <= 0)
|
||||
if (!device || strlen(device) == 0)
|
||||
return;
|
||||
|
||||
sprintf(buf, "\\\\.\\%c:", device[0]);
|
||||
|
@ -1291,14 +1313,13 @@ void eject_win32_cdrom(gchar *device)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
gboolean gkrellm_sys_fs_init(void)
|
||||
{
|
||||
if (_GK.debug_level & DEBUG_SYSDEP)
|
||||
printf("Initializing file system monitor.\n");
|
||||
|
||||
gkrellm_fs_mounting_unsupported();
|
||||
gkrellm_fs_setup_eject(NULL, NULL, eject_win32_cdrom, NULL);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -1321,13 +1342,13 @@ void gkrellm_sys_fs_get_fsusage(gpointer fs, gchar *dir)
|
|||
total = EnlargedUnsignedDivide(totalBytes, 1024, 0);
|
||||
freeCaller = EnlargedUnsignedDivide(freeAvailableToCaller, 1024, 0);
|
||||
free = EnlargedUnsignedDivide(freeBytes, 1024, 0);
|
||||
|
||||
// fs, blocks, avail, free, size
|
||||
gkrellm_fs_assign_fsusage_data(fs, total, freeCaller, free, 1024);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("GetDiskFreeSpaceEx() failed on drive %c: with error %d\n", *dir, err);
|
||||
// may happen on cd/dvd drives, ignore for now
|
||||
//printf("GetDiskFreeSpaceEx() failed on drive %c:, error %d\n", *dir, err);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1336,30 +1357,29 @@ void gkrellm_sys_fs_get_mounts_list(void)
|
|||
{
|
||||
char buf[1024];
|
||||
char* drive;
|
||||
|
||||
GetLogicalDriveStrings(1024, buf);
|
||||
for (drive = buf; *drive != 0; drive += lstrlen(drive) + 1)
|
||||
{
|
||||
// dir, dev, type
|
||||
if (strcmp("A:\\", drive) != 0 && strcmp("a:\\", drive) != 0 &&
|
||||
strcmp("B:\\", drive) != 0 && strcmp("b:\\", drive) != 0)
|
||||
strcmp("B:\\", drive) != 0 && strcmp("b:\\", drive) != 0
|
||||
)
|
||||
{
|
||||
gkrellm_fs_add_to_mounts_list(drive, drive, "");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void gkrellm_sys_fs_get_fstab_list(void)
|
||||
{
|
||||
char buf[1024];
|
||||
char* drive;
|
||||
|
||||
GetLogicalDriveStrings(1024, buf);
|
||||
for (drive = buf; *drive != 0; drive += lstrlen(drive) + 1)
|
||||
{
|
||||
// dir, dev, type, opt
|
||||
if (strcmp("A:\\", drive) != 0 && strcmp("a:\\", drive) != 0 &&
|
||||
strcmp("B:\\", drive) != 0 && strcmp("b:\\", drive) != 0)
|
||||
strcmp("B:\\", drive) != 0 && strcmp("b:\\", drive) != 0
|
||||
)
|
||||
{
|
||||
if (_GK.debug_level & DEBUG_SYSDEP)
|
||||
printf("Adding fstab %s\n", drive);
|
||||
|
@ -1377,6 +1397,7 @@ gboolean gkrellm_sys_inet_init(void)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
void gkrellm_sys_inet_read_tcp_data(void)
|
||||
{
|
||||
PMIB_TCPTABLE pTcpTable = NULL;
|
||||
|
@ -1384,7 +1405,9 @@ void gkrellm_sys_inet_read_tcp_data(void)
|
|||
|
||||
// Make an initial call to GetTcpTable to
|
||||
// get the necessary size into the dwSize variable
|
||||
if (GetTcpTable(NULL, &dwTableSize, FALSE) == ERROR_INSUFFICIENT_BUFFER)
|
||||
if (GetTcpTable(NULL, &dwTableSize, FALSE) == ERROR_INSUFFICIENT_BUFFER
|
||||
&& dwTableSize > 0
|
||||
)
|
||||
{
|
||||
pTcpTable = (MIB_TCPTABLE *)malloc(dwTableSize);
|
||||
|
||||
|
@ -1409,7 +1432,7 @@ void gkrellm_sys_inet_read_tcp_data(void)
|
|||
gkrellm_inet_log_tcp_port_data(&tcp);
|
||||
}
|
||||
}
|
||||
GlobalFree(pTcpTable);
|
||||
free(pTcpTable);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1429,38 +1452,53 @@ time_t gkrellm_sys_uptime_read_uptime(void)
|
|||
if (pdhQueryHandle != 0)
|
||||
{
|
||||
status = PdhGetFormattedCounterValue(uptimeCounter, PDH_FMT_LONG, &type, &value);
|
||||
if (status != ERROR_SUCCESS)
|
||||
{
|
||||
printf("Getting PDH-counter (uptime) failed with status %ld\n", status);
|
||||
return (time_t)0;
|
||||
}
|
||||
l = value.longValue;
|
||||
}
|
||||
|
||||
return (time_t) l;
|
||||
}
|
||||
|
||||
|
||||
gboolean gkrellm_sys_uptime_init(void)
|
||||
{
|
||||
if (_GK.debug_level & DEBUG_SYSDEP)
|
||||
printf("Initializing uptime monitor.\n");
|
||||
|
||||
if (pdhQueryHandle != 0)
|
||||
{
|
||||
if (pdhQueryHandle == 0)
|
||||
return FALSE;
|
||||
|
||||
status = PdhAddCounter(pdhQueryHandle, perfKeyList[Uptime], 0, &uptimeCounter);
|
||||
if (status != ERROR_SUCCESS)
|
||||
{
|
||||
printf("Adding PDH-counter (uptime) failed with status %ld\n", status);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/* ===================================================================== */
|
||||
/* hostname interface */
|
||||
/* ===================================================================== */
|
||||
|
||||
gchar *gkrellm_sys_get_host_name(void)
|
||||
{
|
||||
static gboolean have_it = FALSE;
|
||||
static gboolean host_name_fetched = FALSE;
|
||||
|
||||
if (!have_it)
|
||||
if (!host_name_fetched)
|
||||
{
|
||||
char buf[128];
|
||||
int err;
|
||||
|
||||
if (_GK.debug_level & DEBUG_SYSDEP)
|
||||
printf("Retrieving host name.\n");
|
||||
|
||||
err = gethostname(buf, sizeof(buf));
|
||||
|
||||
if (err != 0)
|
||||
|
@ -1468,15 +1506,12 @@ gchar *gkrellm_sys_get_host_name(void)
|
|||
else
|
||||
hostname = g_strdup(buf);
|
||||
|
||||
if (_GK.debug_level & DEBUG_SYSDEP)
|
||||
printf("Retrieving host name.\n");
|
||||
|
||||
have_it = TRUE;
|
||||
host_name_fetched = TRUE;
|
||||
}
|
||||
|
||||
return hostname;
|
||||
}
|
||||
|
||||
|
||||
/* ===================================================================== */
|
||||
/* System name interface */
|
||||
/* ===================================================================== */
|
||||
|
@ -1551,9 +1586,16 @@ gboolean gkrellm_sys_sensors_mbmon_supported(void)
|
|||
/* ===================================================================== */
|
||||
|
||||
|
||||
void initPerfKeyList(void)
|
||||
static void initPerfKeyList(void)
|
||||
{
|
||||
printf("initPerfKeyList();\n");
|
||||
int i;
|
||||
for (i = 0; i < PerfKeysSize; i++)
|
||||
{
|
||||
perfKeyList[i] = NULL;
|
||||
}
|
||||
|
||||
if (pdhQueryHandle == 0)
|
||||
return;
|
||||
|
||||
placePerfKeysFromReg(NumProcesses , 2 , 248);
|
||||
placePerfKeysFromReg(NumThreads , 2 , 250);
|
||||
|
@ -1590,17 +1632,18 @@ static void placePerfKeysFromReg(const PerfKey key, unsigned int index1, unsigne
|
|||
if (stat == ERROR_SUCCESS)
|
||||
{
|
||||
_tcsncat(buf, perfName, 512);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("could not find perflib index %d in registry\n", index2);
|
||||
}
|
||||
|
||||
placePerfKey(key, buf);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("could not find perflib index %d in registry\n", index2);
|
||||
placePerfKey(key, NULL);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Could not find perflib index %d in registry\n", index1);
|
||||
placePerfKey(key, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1629,12 +1672,12 @@ static void placePerfKeyFromReg(const PerfKey key, unsigned int index,
|
|||
{
|
||||
_tcsncat(buf, suffix, 512);
|
||||
}
|
||||
|
||||
placePerfKey(key, buf);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("could not find index %d in registry\n", index);
|
||||
placePerfKey(key, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1642,19 +1685,24 @@ static void placePerfKeyFromReg(const PerfKey key, unsigned int index,
|
|||
static void placePerfKey(const PerfKey key, const TCHAR* value)
|
||||
{
|
||||
size_t strSize;
|
||||
|
||||
if (((int)key > -1) && ((int)key < PerfKeysSize))
|
||||
{
|
||||
free(perfKeyList[key]);
|
||||
if (value != NULL)
|
||||
{
|
||||
strSize = _tcsclen(value);
|
||||
perfKeyList[key] = malloc(sizeof(TCHAR) * strSize + 1);
|
||||
_tcscpy(perfKeyList[key], value);
|
||||
|
||||
printf("perfKeyList[ %d ] = '%s'\n", key, perfKeyList[key]);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Invalid placement for key %d and value %s\n", key, value);
|
||||
perfKeyList[key] = NULL;
|
||||
}
|
||||
//printf("perfKeyList[ %d ] = '%s'\n", key, perfKeyList[key]);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Invalid placement for key %d; value was '%s'\n", key, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1831,4 +1879,3 @@ if (addr != NULL)
|
|||
addr->s_addr = htonl(val);
|
||||
return (1);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue