From: Denis Kirjanov <kirjanov@gmail.com>
To: stephen@networkplumber.org, dsahern@kernel.org
Cc: netdev@vger.kernel.org, Denis Kirjanov <kirjanov@gmail.com>
Subject: [iproute2-next] ifstat: handle fclose errors
Date: Fri, 1 Nov 2024 14:05:39 +0300 [thread overview]
Message-ID: <20241101110539.7046-1-kirjanov@gmail.com> (raw)
fclose() can fail so print an error
Signed-off-by: Denis Kirjanov <kirjanov@gmail.com>
---
misc/ifstat.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/misc/ifstat.c b/misc/ifstat.c
index faebe938..b0c1ef10 100644
--- a/misc/ifstat.c
+++ b/misc/ifstat.c
@@ -1003,7 +1003,8 @@ int main(int argc, char *argv[])
if ((tfp = fopen("/proc/uptime", "r")) != NULL) {
if (fscanf(tfp, "%ld", &uptime) != 1)
uptime = -1;
- fclose(tfp);
+ if (fclose(tfp))
+ perror("ifstat: fclose");
}
if (uptime >= 0 && time(NULL) >= stb.st_mtime+uptime) {
fprintf(stderr, "ifstat: history is aged out, resetting\n");
@@ -1035,7 +1036,8 @@ int main(int argc, char *argv[])
fprintf(stderr, "ifstat: history is stale, ignoring it.\n");
hist_db = NULL;
}
- fclose(sfp);
+ if (fclose(sfp))
+ perror("ifstat: fclose");
}
} else {
if (fd >= 0)
@@ -1064,7 +1066,8 @@ int main(int argc, char *argv[])
json_output = 0;
dump_raw_db(hist_fp, 1);
- fclose(hist_fp);
+ if (fclose(hist_fp))
+ perror("ifstat: fclose");
}
exit(0);
}
--
2.43.0
next reply other threads:[~2024-11-01 11:06 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-01 11:05 Denis Kirjanov [this message]
2024-11-03 15:56 ` [iproute2-next] ifstat: handle fclose errors Stephen Hemminger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241101110539.7046-1-kirjanov@gmail.com \
--to=kirjanov@gmail.com \
--cc=dsahern@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=stephen@networkplumber.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.