static char *wifi_essid(const char *iface);
static char *kernel_release(void);
static void sighandler(const int signo);
-static void usage(void);
+static void usage(int);
char *argv0;
char concat[];
fgets(buf, sizeof(buf), fp);
fclose(fp);
- datastart = strstr(buf, concat);
- if (datastart != NULL) {
- datastart = strstr(buf, ":");
- sscanf(datastart + 1, " %*d %d %*d %*d %*d %*d %*d %*d %*d %*d", &perc);
+ if ((datastart = strstr(buf, concat)) == NULL) {
+ return smprintf("%s", UNKNOWN_STR);
}
+ datastart = (datastart+(strlen(iface)+1));
+ sscanf(datastart + 1, " %*d %d %*d %*d %*d %*d %*d %*d %*d %*d", &perc);
return smprintf("%d%%", perc);
}
memset(&wreq, 0, sizeof(struct iwreq));
wreq.u.essid.length = IW_ESSID_MAX_SIZE+1;
- sprintf(wreq.ifr_name, iface);
+ snprintf(wreq.ifr_name, sizeof(wreq.ifr_name), "%s", iface);
+
if (sockfd == -1) {
warn("Failed to get ESSID for interface %s", iface);
return smprintf("%s", UNKNOWN_STR);
}
static void
-usage(void)
+usage(int eval)
{
- fprintf(stderr, "usage: %s [-dhov]\n", argv0);
- exit(1);
+ fprintf(stderr, "usage: %s [-d] [-o] [-v] [-h]\n", argv0);
+ exit(eval);
}
int
case 'v':
printf("slstatus %s (C) 2016 slstatus engineers\n", VERSION);
return 0;
+ case 'h':
+ usage(0);
default:
- usage();
+ usage(1);
} ARGEND
if (dflag && oflag) {
- usage();
+ usage(1);
}
if (dflag && daemon(1, 1) < 0) {
err(1, "daemon");
element = smprintf("%s", UNKNOWN_STR);
warnx("Failed to format output");
}
- if (strlcat(status_string, element, sizeof(status_string)) >= sizeof(status_string))
+ if (strlcat(status_string, element, sizeof(status_string)) >= sizeof(status_string)) {
warnx("Output too long");
+ }
free(res);
free(element);
}
printf("%s\n", status_string);
}
- /*
- * subtract delay time spend in function
- * calls from the actual global delay time
- */
if ((UPDATE_INTERVAL - delay) <= 0) {
delay = 0;
continue;