Ticket 182

git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@1079 3ae390bd-cb1e-0410-b409-cd5a39f66f1f
This commit is contained in:
volker
2010-01-15 21:44:04 +00:00
parent ac266e1877
commit 69fecdd3d6
3 changed files with 31 additions and 21 deletions

View File

@@ -113,18 +113,18 @@ static int parse_cpuinfo(char *oid)
size_t val_len; size_t val_len;
if (sysctlbyname(oid, NULL, &val_len, NULL, 0) != 0) { if (sysctlbyname(oid, NULL, &val_len, NULL, 0) != 0) {
error("Error %d by sysctl(%s): %s", errno, oid, strerror(errno)); error("Error %d by sysctl(%s): %s", errno, oid, strerror(errno));
return -1; return -1;
} }
if (val_len > sizeof(val_ret)) { if (val_len > sizeof(val_ret)) {
error("Error: Result of sysctl(%s) too big (%zd > %zd)!", oid, val_len, sizeof(val_ret)); error("Error: Result of sysctl(%s) too big (%zd > %zd)!", oid, val_len, sizeof(val_ret));
return -1; return -1;
} }
sysctlbyname(oid, &val_ret, &val_len, NULL, 0); sysctlbyname(oid, &val_ret, &val_len, NULL, 0);
if (val_len == sizeof(int)) { if (val_len == sizeof(int)) {
/* we got an integer instead of a string */ /* we got an integer instead of a string */
val = (int*)val_ret; val = (int *) val_ret;
snprintf(val_ret, sizeof(val_ret), "%d", *val); snprintf(val_ret, sizeof(val_ret), "%d", *val);
} }
hash_put(&CPUinfo, oid, val_ret); hash_put(&CPUinfo, oid, val_ret);
#endif #endif

View File

@@ -143,19 +143,26 @@ static void my_hwaddr(RESULT * result, RESULT * arg1)
} }
strncpy(ifreq.ifr_name, R2S(arg1), sizeof(ifreq.ifr_name)); strncpy(ifreq.ifr_name, R2S(arg1), sizeof(ifreq.ifr_name));
// if (ioctl(socknr, SIOCGIFHWADDR, &ifreq) < 0) { #ifndef __MAC_OS_X_VERSION_10_3
// if (ioctl(socknr, SIOCGIFMAC, &ifreq) < 0) { // Linux: get interface MAC address
if (ioctl(socknr, SIOCGIFHWADDR, &ifreq) < 0) {
#else
// MacOS: get interface MAC address
if (ioctl(socknr, SIOCGLIFPHYADDR, &ifreq) < 0) { if (ioctl(socknr, SIOCGLIFPHYADDR, &ifreq) < 0) {
errcount++; #endif
errcount++;
if (1 == errcount % 1000) { 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)"); error(" (skip next 1000 errors)");
} }
SetResult(&result, R_STRING, ""); SetResult(&result, R_STRING, "");
return; 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; hw = (unsigned char *) ifreq.ifr_data;
#endif
qprintf(value, sizeof(value), "%02x:%02x:%02x:%02x:%02x:%02x", qprintf(value, sizeof(value), "%02x:%02x:%02x:%02x:%02x:%02x",
*hw, *(hw + 1), *(hw + 2), *(hw + 3), *(hw + 4), *(hw + 5)); *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, ""); SetResult(&result, R_STRING, "");
return; 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; sin = (struct sockaddr_in *) &ifreq.ifr_data;
#endif
qprintf(value, sizeof(value), "%s", inet_ntoa(sin->sin_addr)); qprintf(value, sizeof(value), "%s", inet_ntoa(sin->sin_addr));
SetResult(&result, R_STRING, value); SetResult(&result, R_STRING, value);

View File

@@ -89,7 +89,7 @@ static int parse_proc_stat(void)
if (age > 0 && age <= 10) if (age > 0 && age <= 10)
return 0; return 0;
#if 0 #ifndef __MAC_OS_X_VERSION_10_3
/* Linux Kernel, /proc-filesystem */ /* Linux Kernel, /proc-filesystem */
@@ -228,18 +228,18 @@ static int parse_proc_stat(void)
/* MACH Kernel, MacOS X */ /* MACH Kernel, MacOS X */
kern_return_t err; kern_return_t err;
mach_msg_type_number_t count; mach_msg_type_number_t count;
host_info_t r_load; host_info_t r_load;
host_cpu_load_info_data_t cpu_load; host_cpu_load_info_data_t cpu_load;
char s_val[8]; char s_val[8];
r_load = &cpu_load; r_load = &cpu_load;
count = HOST_CPU_LOAD_INFO_COUNT; count = HOST_CPU_LOAD_INFO_COUNT;
err = host_statistics(mach_host_self(), HOST_CPU_LOAD_INFO, r_load, &count); err = host_statistics(mach_host_self(), HOST_CPU_LOAD_INFO, r_load, &count);
if (KERN_SUCCESS != err) { if (KERN_SUCCESS != err) {
error("Error getting cpu load"); error("Error getting cpu load");
return -1; return -1;
} }
snprintf(s_val, sizeof(s_val), "%d", cpu_load.cpu_ticks[CPU_STATE_USER]); snprintf(s_val, sizeof(s_val), "%d", cpu_load.cpu_ticks[CPU_STATE_USER]);
hash_put2("cpu", "user", s_val); hash_put2("cpu", "user", s_val);