Skip to content

Commit

Permalink
legiond: handle fscanf return
Browse files Browse the repository at this point in the history
Signed-off-by: ston <[email protected]>
  • Loading branch information
st0nie authored and MrDuartePT committed Apr 5, 2024
1 parent 151da20 commit b115039
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
10 changes: 8 additions & 2 deletions extra/service/legiond/modules/powerstate.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions extra/service/legiond/modules/powerstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit b115039

Please sign in to comment.