implement the 'path' option for cpu temperature
This commit is contained in:
parent
7507a3d03c
commit
4ec02bea7b
@ -229,6 +229,7 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
cfg_opt_t temp_opts[] = {
|
cfg_opt_t temp_opts[] = {
|
||||||
CFG_STR("format", "%degrees C", CFGF_NONE),
|
CFG_STR("format", "%degrees C", CFGF_NONE),
|
||||||
|
CFG_STR("path", NULL, CFGF_NONE),
|
||||||
CFG_END()
|
CFG_END()
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -361,7 +362,7 @@ int main(int argc, char *argv[]) {
|
|||||||
cfg_getint(sec, "mixer_idx"));
|
cfg_getint(sec, "mixer_idx"));
|
||||||
|
|
||||||
CASE_SEC_TITLE("cpu_temperature")
|
CASE_SEC_TITLE("cpu_temperature")
|
||||||
print_cpu_temperature_info(atoi(title), cfg_getstr(sec, "format"));
|
print_cpu_temperature_info(atoi(title), cfg_getstr(sec, "path"), cfg_getstr(sec, "format"));
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
@ -66,7 +66,7 @@ void print_ddate(const char *format);
|
|||||||
const char *get_ip_addr();
|
const char *get_ip_addr();
|
||||||
void print_wireless_info(const char *interface, const char *format_up, const char *format_down);
|
void print_wireless_info(const char *interface, const char *format_up, const char *format_down);
|
||||||
void print_run_watch(const char *title, const char *pidfile, const char *format);
|
void print_run_watch(const char *title, const char *pidfile, const char *format);
|
||||||
void print_cpu_temperature_info(int zone, const char *format);
|
void print_cpu_temperature_info(int zone, const char *path, const char *format);
|
||||||
void print_eth_info(const char *interface, const char *format_up, const char *format_down);
|
void print_eth_info(const char *interface, const char *format_up, const char *format_down);
|
||||||
void print_load();
|
void print_load();
|
||||||
void print_volume(const char *fmt, const char *device, const char *mixer, int mixer_idx);
|
void print_volume(const char *fmt, const char *device, const char *mixer, int mixer_idx);
|
||||||
|
@ -21,11 +21,14 @@ static char *thermal_zone;
|
|||||||
* returns the temperature in degree celcius.
|
* returns the temperature in degree celcius.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void print_cpu_temperature_info(int zone, const char *format) {
|
void print_cpu_temperature_info(int zone, const char *path, const char *format) {
|
||||||
const char *walk;
|
const char *walk;
|
||||||
static char buf[16];
|
static char buf[16];
|
||||||
|
|
||||||
asprintf(&thermal_zone, THERMAL_ZONE, zone);
|
if (path == NULL) {
|
||||||
|
asprintf(&thermal_zone, THERMAL_ZONE, zone);
|
||||||
|
path = thermal_zone;
|
||||||
|
}
|
||||||
|
|
||||||
for (walk = format; *walk != '\0'; walk++) {
|
for (walk = format; *walk != '\0'; walk++) {
|
||||||
if (*walk != '%') {
|
if (*walk != '%') {
|
||||||
@ -36,8 +39,8 @@ void print_cpu_temperature_info(int zone, const char *format) {
|
|||||||
if (BEGINS_WITH(walk+1, "degrees")) {
|
if (BEGINS_WITH(walk+1, "degrees")) {
|
||||||
#if defined(LINUX)
|
#if defined(LINUX)
|
||||||
long int temp;
|
long int temp;
|
||||||
if (!slurp(thermal_zone, buf, sizeof(buf)))
|
if (!slurp(path, buf, sizeof(buf)))
|
||||||
die("Could not open \"%s\"\n", thermal_zone);
|
die("Could not open \"%s\"\n", path);
|
||||||
temp = strtol(buf, NULL, 10);
|
temp = strtol(buf, NULL, 10);
|
||||||
if (temp == LONG_MIN || temp == LONG_MAX || temp <= 0)
|
if (temp == LONG_MIN || temp == LONG_MAX || temp <= 0)
|
||||||
(void)printf("?");
|
(void)printf("?");
|
||||||
@ -46,7 +49,7 @@ void print_cpu_temperature_info(int zone, const char *format) {
|
|||||||
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
||||||
int sysctl_rslt;
|
int sysctl_rslt;
|
||||||
size_t sysctl_size = sizeof(sysctl_rslt);
|
size_t sysctl_size = sizeof(sysctl_rslt);
|
||||||
if (sysctlbyname(thermal_zone, &sysctl_rslt, &sysctl_size, NULL, 0)) {
|
if (sysctlbyname(path, &sysctl_rslt, &sysctl_size, NULL, 0)) {
|
||||||
(void)printf("No thermal zone found");
|
(void)printf("No thermal zone found");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user