diff options
author | Connor Lane Smith <cls@lubutu.com> | 2011-08-25 22:24:06 +0100 |
---|---|---|
committer | Michael Stapelberg <michael@stapelberg.de> | 2011-08-25 23:27:10 +0200 |
commit | cc1457c4f0f4cccb8bec326dd0bb13082ac806e6 (patch) | |
tree | c6489bc574d7624fb3d48487293e842f4261bfb8 /src/print_cpu_temperature.c | |
parent | 67ad80f0050fba9c1a57a70d1a277925805ed560 (diff) |
make modules more resilient to failure
Diffstat (limited to 'src/print_cpu_temperature.c')
-rw-r--r-- | src/print_cpu_temperature.c | 11 |
1 files changed, 6 insertions, 5 deletions
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); } |