mirror of
https://github.com/netfun2000/lcd4linux.git
synced 2026-02-27 09:44:34 +08:00
Ticket 182
git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@1079 3ae390bd-cb1e-0410-b409-cd5a39f66f1f
This commit is contained in:
@@ -113,18 +113,18 @@ static int parse_cpuinfo(char *oid)
|
||||
size_t val_len;
|
||||
|
||||
if (sysctlbyname(oid, NULL, &val_len, NULL, 0) != 0) {
|
||||
error("Error %d by sysctl(%s): %s", errno, oid, strerror(errno));
|
||||
return -1;
|
||||
error("Error %d by sysctl(%s): %s", errno, oid, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
if (val_len > sizeof(val_ret)) {
|
||||
error("Error: Result of sysctl(%s) too big (%zd > %zd)!", oid, val_len, sizeof(val_ret));
|
||||
return -1;
|
||||
error("Error: Result of sysctl(%s) too big (%zd > %zd)!", oid, val_len, sizeof(val_ret));
|
||||
return -1;
|
||||
}
|
||||
sysctlbyname(oid, &val_ret, &val_len, NULL, 0);
|
||||
if (val_len == sizeof(int)) {
|
||||
/* we got an integer instead of a string */
|
||||
val = (int*)val_ret;
|
||||
snprintf(val_ret, sizeof(val_ret), "%d", *val);
|
||||
/* we got an integer instead of a string */
|
||||
val = (int *) val_ret;
|
||||
snprintf(val_ret, sizeof(val_ret), "%d", *val);
|
||||
}
|
||||
hash_put(&CPUinfo, oid, val_ret);
|
||||
#endif
|
||||
|
||||
@@ -143,19 +143,26 @@ static void my_hwaddr(RESULT * result, RESULT * arg1)
|
||||
}
|
||||
|
||||
strncpy(ifreq.ifr_name, R2S(arg1), sizeof(ifreq.ifr_name));
|
||||
// if (ioctl(socknr, SIOCGIFHWADDR, &ifreq) < 0) {
|
||||
// if (ioctl(socknr, SIOCGIFMAC, &ifreq) < 0) {
|
||||
#ifndef __MAC_OS_X_VERSION_10_3
|
||||
// Linux: get interface MAC address
|
||||
if (ioctl(socknr, SIOCGIFHWADDR, &ifreq) < 0) {
|
||||
#else
|
||||
// MacOS: get interface MAC address
|
||||
if (ioctl(socknr, SIOCGLIFPHYADDR, &ifreq) < 0) {
|
||||
errcount++;
|
||||
#endif
|
||||
errcount++;
|
||||
if (1 == errcount % 1000) {
|
||||
error("%s: ioctl(IFHWADDR %s) failed: %s", "plugin_netinfo", ifreq.ifr_name, strerror(errno));
|
||||
error("%s: ioctl(IF_HARDW_ADDR %s) failed: %s", "plugin_netinfo", ifreq.ifr_name, strerror(errno));
|
||||
error(" (skip next 1000 errors)");
|
||||
}
|
||||
SetResult(&result, R_STRING, "");
|
||||
return;
|
||||
}
|
||||
// hw = (unsigned char *) ifreq.ifr_hwaddr.sa_data;
|
||||
#ifndef __MAC_OS_X_VERSION_10_3
|
||||
hw = (unsigned char *) ifreq.ifr_hwaddr.sa_data;
|
||||
#else
|
||||
hw = (unsigned char *) ifreq.ifr_data;
|
||||
#endif
|
||||
qprintf(value, sizeof(value), "%02x:%02x:%02x:%02x:%02x:%02x",
|
||||
*hw, *(hw + 1), *(hw + 2), *(hw + 3), *(hw + 4), *(hw + 5));
|
||||
|
||||
@@ -218,8 +225,11 @@ static void my_netmask(RESULT * result, RESULT * arg1)
|
||||
SetResult(&result, R_STRING, "");
|
||||
return;
|
||||
}
|
||||
// sin = (struct sockaddr_in *) &ifreq.ifr_netmask;
|
||||
#ifndef __MAC_OS_X_VERSION_10_3
|
||||
sin = (struct sockaddr_in *) &ifreq.ifr_netmask;
|
||||
#else
|
||||
sin = (struct sockaddr_in *) &ifreq.ifr_data;
|
||||
#endif
|
||||
qprintf(value, sizeof(value), "%s", inet_ntoa(sin->sin_addr));
|
||||
|
||||
SetResult(&result, R_STRING, value);
|
||||
|
||||
@@ -89,7 +89,7 @@ static int parse_proc_stat(void)
|
||||
if (age > 0 && age <= 10)
|
||||
return 0;
|
||||
|
||||
#if 0
|
||||
#ifndef __MAC_OS_X_VERSION_10_3
|
||||
|
||||
/* Linux Kernel, /proc-filesystem */
|
||||
|
||||
@@ -228,18 +228,18 @@ static int parse_proc_stat(void)
|
||||
|
||||
/* MACH Kernel, MacOS X */
|
||||
|
||||
kern_return_t err;
|
||||
mach_msg_type_number_t count;
|
||||
host_info_t r_load;
|
||||
host_cpu_load_info_data_t cpu_load;
|
||||
char s_val[8];
|
||||
kern_return_t err;
|
||||
mach_msg_type_number_t count;
|
||||
host_info_t r_load;
|
||||
host_cpu_load_info_data_t cpu_load;
|
||||
char s_val[8];
|
||||
|
||||
r_load = &cpu_load;
|
||||
count = HOST_CPU_LOAD_INFO_COUNT;
|
||||
err = host_statistics(mach_host_self(), HOST_CPU_LOAD_INFO, r_load, &count);
|
||||
if (KERN_SUCCESS != err) {
|
||||
error("Error getting cpu load");
|
||||
return -1;
|
||||
error("Error getting cpu load");
|
||||
return -1;
|
||||
}
|
||||
snprintf(s_val, sizeof(s_val), "%d", cpu_load.cpu_ticks[CPU_STATE_USER]);
|
||||
hash_put2("cpu", "user", s_val);
|
||||
|
||||
Reference in New Issue
Block a user