aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lowbat.12
-rw-r--r--lowbat.c12
2 files changed, 9 insertions, 5 deletions
diff --git a/lowbat.1 b/lowbat.1
index cc73f18..38b53a9 100644
--- a/lowbat.1
+++ b/lowbat.1
@@ -1,4 +1,4 @@
-.TH LOWBAT 1 lowbat\-1.2
+.TH LOWBAT 1 lowbat\-1.2.1
.SH NAME
lowbat - A minimal battery level monitor daemon, written in C
.SH DESCRIPTION
diff --git a/lowbat.c b/lowbat.c
index b5fb665..b56f40b 100644
--- a/lowbat.c
+++ b/lowbat.c
@@ -21,7 +21,7 @@ static char batteries[MAX_BATTERIES][MAX_PSU_NAME_LEN];
static unsigned int num_batteries;
static FILE *fp;
static char prop_path[MAX_PROP_PATH_LEN];
-static enum StatusSymbols { UNKNOWN = '?', CHARGING = '+', DISCHARGING = '-', NOT_CHARGING = '=', FULL = '=' };
+enum StatusSymbols { UNKNOWN = '?', CHARGING = '+', DISCHARGING = '-', NOT_CHARGING = '=', FULL = '=' };
// functions
void load_installed_batteries() {
@@ -60,7 +60,8 @@ void load_installed_batteries() {
fprintf(stderr, "maximum number of batteries (8) exceeded\n");
exit(EXIT_FAILURE);
}
- strncpy(batteries[num_batteries], entry->d_name, MAX_PSU_NAME_LEN);
+ memcpy(batteries[num_batteries], entry->d_name, MAX_PSU_NAME_LEN);
+ batteries[num_batteries][MAX_PSU_NAME_LEN-1] = '\0';
num_batteries++;
break;
}
@@ -86,11 +87,14 @@ void read_prop(char *psu, char *prop, char *fmt, void *out) {
snprintf(prop_path, MAX_PROP_PATH_LEN, PSUPATH "/%s/%s", psu, prop);
if ((fp = fopen(prop_path, "r")) != NULL) {
- fscanf(fp, fmt, out);
+ if (fscanf(fp, fmt, out) != 1) {
+ fprintf(stderr, "failed to scan property %s with format '%s'\n", fmt, prop_path);
+ exit(EXIT_FAILURE);
+ }
fclose(fp);
}
else {
- fprintf(stderr, "failed to read fmt '%s' from property %s\n", fmt, prop_path);
+ fprintf(stderr, "failed to open %s\n", prop_path);
exit(EXIT_FAILURE);
}
}