From b1150395c17fc74477fadeb6c7a53842cfbd6079 Mon Sep 17 00:00:00 2001 From: ston Date: Fri, 5 Apr 2024 00:26:35 +0800 Subject: [PATCH] legiond: handle fscanf return Signed-off-by: ston --- extra/service/legiond/modules/powerstate.c | 10 ++++++++-- extra/service/legiond/modules/powerstate.h | 3 +++ 2 files changed, 11 insertions(+), 2 deletions(-) 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"