From cc1457c4f0f4cccb8bec326dd0bb13082ac806e6 Mon Sep 17 00:00:00 2001 From: Connor Lane Smith Date: Thu, 25 Aug 2011 22:24:06 +0100 Subject: make modules more resilient to failure --- src/print_cpu_temperature.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/print_cpu_temperature.c') diff --git a/src/print_cpu_temperature.c b/src/print_cpu_temperature.c index 3bc4636..8c343c2 100644 --- a/src/print_cpu_temperature.c +++ b/src/print_cpu_temperature.c @@ -41,7 +41,7 @@ void print_cpu_temperature_info(int zone, const char *path, const char *format) #if defined(LINUX) long int temp; if (!slurp(path, buf, sizeof(buf))) - die("Could not open \"%s\"\n", path); + goto error; temp = strtol(buf, NULL, 10); if (temp == LONG_MIN || temp == LONG_MAX || temp <= 0) (void)printf("?"); @@ -50,15 +50,16 @@ void print_cpu_temperature_info(int zone, const char *path, const char *format) #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) int sysctl_rslt; size_t sysctl_size = sizeof(sysctl_rslt); - if (sysctlbyname(path, &sysctl_rslt, &sysctl_size, NULL, 0)) { - (void)printf("No thermal zone found"); - return; - } + if (sysctlbyname(path, &sysctl_rslt, &sysctl_size, NULL, 0)) + goto error; (void)printf("%d.%d", TZ_KELVTOC(sysctl_rslt)); #endif walk += strlen("degrees"); } } + return; +error: #endif + (void)fputs("Cannot read temperature\n", stderr); } -- cgit v1.2.3