summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: b9a2b65)
raw | patch | inline | side by side (parent: b9a2b65)
author | Florian Forster <octo@collectd.org> | |
Tue, 19 Sep 2017 06:16:42 +0000 (08:16 +0200) | ||
committer | Florian Forster <octo@collectd.org> | |
Tue, 19 Sep 2017 06:16:42 +0000 (08:16 +0200) |
This is only touching the Linux code, though.
src/uptime.c | patch | blob | history |
diff --git a/src/uptime.c b/src/uptime.c
index ed0dfd10ffd1f4d500be6f52b3612b6709a2e2f4..8b83cf9be9f7def6ebc15bec94d912f5cbe14000 100644 (file)
--- a/src/uptime.c
+++ b/src/uptime.c
*/
#if KERNEL_LINUX
- double uptime_seconds;
- int ret;
- FILE *fh;
-
- ret = 0;
-
- fh = fopen(UPTIME_FILE, "r");
-
+ FILE *fh = fopen(UPTIME_FILE, "r");
if (fh == NULL) {
char errbuf[1024];
ERROR("uptime plugin: Cannot open " UPTIME_FILE ": %s",
return -1;
}
- ret = fscanf(fh, "%lf", &uptime_seconds);
-
- fclose(fh);
-
- /* loop done, check if no value has been found/read */
- if (ret != 1) {
+ double uptime_seconds = 0.0;
+ if (fscanf(fh, "%lf", &uptime_seconds) != 1) {
ERROR("uptime plugin: No value read from " UPTIME_FILE "");
+ fclose(fh);
return -1;
}
+ fclose(fh);
+
if (uptime_seconds == 0.0) {
ERROR("uptime plugin: uptime read from " UPTIME_FILE ", "
"but it is zero!");