diff --git a/extra/service/legiond/modules/powerstate.c b/extra/service/legiond/modules/powerstate.c index 4ed71a2..fb16f40 100644 --- a/extra/service/legiond/modules/powerstate.c +++ b/extra/service/legiond/modules/powerstate.c @@ -9,12 +9,18 @@ extern int get_powerstate() FILE *fp; fp = fopen(ac_path, "r"); int state; - fscanf(fp, "%d", &state); + if (fscanf(fp, "%d", &state)!=1){ + printf("failed to get AC status\n"); + return P_ERROR_AC; + } fclose(fp); fp = fopen(profile_path, "r"); char profile[30]; - fscanf(fp, "%s", profile); + if (fscanf(fp, "%s", profile)!=1){ + printf("failed to get power_profile\n"); + return P_ERROR_PROFILE; + } fclose(fp); if (MATCH(profile, "quiet")) { if (state) { diff --git a/extra/service/legiond/modules/powerstate.h b/extra/service/legiond/modules/powerstate.h index 37792a7..5a9ce7e 100644 --- a/extra/service/legiond/modules/powerstate.h +++ b/extra/service/legiond/modules/powerstate.h @@ -9,6 +9,9 @@ #define P_BAT_BP 5 #define P_AC_P 6 +#define P_ERROR_PROFILE -1 +#define P_ERROR_AC -2 + #define ac_path "/sys/class/power_supply/ADP0/online" #define profile_path "/sys/firmware/acpi/platform_profile"