Xinqi Bao's Git
projects
/
slstatus.git
/ commitdiff
summary
|
log
|
commit
|
diff
|
tree
raw
|
patch
|
inline
| side by side (from parent 1:
b51721c
)
return n/a instead of exiting if a specific value cannot be read
author
Daniel Walter <
[email protected]
>
Thu, 10 Mar 2016 12:09:24 +0000
(13:09 +0100)
committer
Daniel Walter <
[email protected]
>
Thu, 10 Mar 2016 12:09:24 +0000
(13:09 +0100)
slstatus.c
patch
|
blob
|
history
diff --git
a/slstatus.c
b/slstatus.c
index
369c6ff
..
3297e1d
100644
(file)
--- a/
slstatus.c
+++ b/
slstatus.c
@@
-79,7
+79,7
@@
get_battery()
/* open battery now file */
if (!(fp = fopen(batterynowfile, "r"))) {
fprintf(stderr, "Error opening battery file.");
/* open battery now file */
if (!(fp = fopen(batterynowfile, "r"))) {
fprintf(stderr, "Error opening battery file.");
-
exit(1
);
+
return smprintf("n/a"
);
}
/* read value */
}
/* read value */
@@
-91,7
+91,7
@@
get_battery()
/* open battery full file */
if (!(fp = fopen(batteryfullfile, "r"))) {
fprintf(stderr, "Error opening battery file.");
/* open battery full file */
if (!(fp = fopen(batteryfullfile, "r"))) {
fprintf(stderr, "Error opening battery file.");
-
exit(1
);
+
return smprintf("n/a"
);
}
/* read value */
}
/* read value */
@@
-117,7
+117,7
@@
get_cpu_temperature()
/* open temperature file */
if (!(fp = fopen(tempfile, "r"))) {
fprintf(stderr, "Could not open temperature file.\n");
/* open temperature file */
if (!(fp = fopen(tempfile, "r"))) {
fprintf(stderr, "Could not open temperature file.\n");
-
exit(1
);
+
return smprintf("n/a"
);
}
/* extract temperature */
}
/* extract temperature */
@@
-141,7
+141,7
@@
get_cpu_usage()
/* open stat file */
if (!(fp = fopen("/proc/stat","r"))) {
fprintf(stderr, "Error opening stat file.");
/* open stat file */
if (!(fp = fopen("/proc/stat","r"))) {
fprintf(stderr, "Error opening stat file.");
-
exit(1
);
+
return smprintf("n/a"
);
}
/* read values */
}
/* read values */
@@
-156,7
+156,7
@@
get_cpu_usage()
/* open stat file */
if (!(fp = fopen("/proc/stat","r"))) {
fprintf(stderr, "Error opening stat file.");
/* open stat file */
if (!(fp = fopen("/proc/stat","r"))) {
fprintf(stderr, "Error opening stat file.");
-
exit(1
);
+
return smprintf("n/a"
);
}
/* read values */
}
/* read values */
@@
-183,8
+183,8
@@
get_datetime()
/* get time in format */
time(&tm);
if(!strftime(buf, bufsize, timeformat, localtime(&tm))) {
/* get time in format */
time(&tm);
if(!strftime(buf, bufsize, timeformat, localtime(&tm))) {
- fprintf(stderr, "Strftime failed.\n");
-
exit(1
);
+
fprintf(stderr, "Strftime failed.\n");
+
return smprintf("n/a"
);
}
/* return time */
}
/* return time */
@@
-202,7
+202,7
@@
get_ram_usage()
/* open meminfo file */
if (!(fp = fopen("/proc/meminfo", "r"))) {
fprintf(stderr, "Error opening meminfo file.");
/* open meminfo file */
if (!(fp = fopen("/proc/meminfo", "r"))) {
fprintf(stderr, "Error opening meminfo file.");
-
exit(1
);
+
return smprintf("n/a"
);
}
/* read the values */
}
/* read the values */
@@
-283,7
+283,7
@@
get_wifi_signal()
/* open wifi file */
if(!(fp = fopen(path, "r"))) {
fprintf(stderr, "Error opening wifi operstate file.");
/* open wifi file */
if(!(fp = fopen(path, "r"))) {
fprintf(stderr, "Error opening wifi operstate file.");
-
exit(1
);
+
return smprintf("n/a"
);
}
/* read the status */
}
/* read the status */
@@
-294,13
+294,13
@@
get_wifi_signal()
/* check if interface down */
if(strcmp(status, "up\n") != 0){
/* check if interface down */
if(strcmp(status, "up\n") != 0){
- return
"n/a"
;
+ return
smprintf("n/a")
;
}
/* open wifi file */
if (!(fp = fopen("/proc/net/wireless", "r"))) {
fprintf(stderr, "Error opening wireless file.");
}
/* open wifi file */
if (!(fp = fopen("/proc/net/wireless", "r"))) {
fprintf(stderr, "Error opening wireless file.");
-
exit(1
);
+
return smprintf("n/a"
);
}
/* extract the signal strength */
}
/* extract the signal strength */