diff options
author | John Ankarstr\xf6m <john@ankarstrom.se> | 2021-06-05 01:53:33 +0200 |
---|---|---|
committer | John Ankarstr\xf6m <john@ankarstrom.se> | 2021-06-05 01:53:33 +0200 |
commit | 80d4cb1aff77499aabc2c8b150182a7727f972ce (patch) | |
tree | 9524f0f64803a057f5e5df9d4853518f1be38231 | |
parent | b28bc03767fd22dafea845aa4a23f295a6335182 (diff) | |
download | xbattext-80d4cb1aff77499aabc2c8b150182a7727f972ce.tar.gz |
xbattext.c: Die on ioctl error
-rw-r--r-- | xbattext.c | 15 |
1 files changed, 5 insertions, 10 deletions
@@ -44,8 +44,6 @@ /* low battery level */ #define ALERT 30 -void update(XtPointer, XtIntervalId *); - /* resources */ struct res { XmFontList font_list; @@ -82,12 +80,14 @@ enum { /* application state */ Arg wargs[10]; char *s; -int apmfd, alerting, charging; +int alerting, apmfd, charging, i; struct apm_power_info info; Widget toplevel, label; XmString xms; XtAppContext app_context; +void update(XtPointer, XtIntervalId *); + /* program start */ int main(int argc, char* argv[]) @@ -127,19 +127,14 @@ main(int argc, char* argv[]) void update(XtPointer client_data, XtIntervalId *t) { - int i; - /* reset temporary variables */ i = 0; change = SET_NONE; /* get battery info */ memset(&info, 0, sizeof(info)); - if (ioctl(apmfd, APM_IOC_GETPOWER, &info) == -1) { - fprintf(stderr, "ioctl APM_IOC_GETPOWER failed\n"); - sprintf(s, "?"); - goto end; - } + if (ioctl(apmfd, APM_IOC_GETPOWER, &info) == -1) + err(1, "ioctl"); /* put battery status into label */ sprintf(s, "%d%%", info.battery_life); |