}
if (uptime >= 0 && time(NULL) >= stb.st_mtime+uptime) {
fprintf(stderr, "ifstat: history is aged out, resetting\n");
- ftruncate(fileno(hist_fp), 0);
+ if (ftruncate(fileno(hist_fp), 0))
+ perror("ifstat: ftruncate");
}
}
}
if (!no_update) {
- ftruncate(fileno(hist_fp), 0);
+ if (ftruncate(fileno(hist_fp), 0))
+ perror("ifstat: ftruncate");
rewind(hist_fp);
json_output = 0;
char buf[FGETS_BUF_SIZE];
rewind(lf->fp);
- fgets(buf, sizeof(buf)-1, lf->fp);
+ if (!fgets(buf, sizeof(buf)-1, lf->fp))
+ return -1;
return __lnstat_scan_fields(lf, buf);
}
}
if (uptime >= 0 && time(NULL) >= stb.st_mtime+uptime) {
fprintf(stderr, "nstat: history is aged out, resetting\n");
- ftruncate(fileno(hist_fp), 0);
+ if (ftruncate(fileno(hist_fp), 0) < 0)
+ perror("nstat: ftruncate");
}
}
dump_incr_db(stdout);
}
if (!no_update) {
- ftruncate(fileno(hist_fp), 0);
+ if (ftruncate(fileno(hist_fp), 0) < 0)
+ perror("nstat: ftruncate");
rewind(hist_fp);
json_output = 0;
snprintf(tmp, sizeof(tmp), "%s/%d/stat",
root, pid);
if ((fp = fopen(tmp, "r")) != NULL) {
- fscanf(fp, "%*d (%[^)])", p);
+ if (fscanf(fp, "%*d (%[^)])", p) < 1)
+ ; /* ignore */
fclose(fp);
}
}
cnt = sizeof(*s)/sizeof(int);
- fgets(buf, sizeof(buf), fp);
+ if (!fgets(buf, sizeof(buf), fp)) {
+ fclose(fp);
+ return -1;
+ }
while(fgets(buf, sizeof(buf), fp) != NULL) {
int i;
for (i=0; i<sizeof(slabstat_ids)/sizeof(slabstat_ids[0]); i++) {
if ((fp = net_unix_open()) == NULL)
return -1;
- fgets(buf, sizeof(buf)-1, fp);
+ if (!fgets(buf, sizeof(buf)-1, fp)) {
+ fclose(fp);
+ return -1;
+ }
if (memcmp(buf, "Peer", 4) == 0)
newformat = 1;
if ((fp = net_netlink_open()) == NULL)
return -1;
- fgets(buf, sizeof(buf)-1, fp);
+ if (!fgets(buf, sizeof(buf)-1, fp)) {
+ fclose(fp);
+ return -1;
+ }
while (fgets(buf, sizeof(buf)-1, fp)) {
sscanf(buf, "%llx %d %d %x %d %d %llx %d",