netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [iproute2-next] ifstat: handle fclose errors
@ 2024-11-01 11:05 Denis Kirjanov
  2024-11-03 15:56 ` Stephen Hemminger
  0 siblings, 1 reply; 2+ messages in thread
From: Denis Kirjanov @ 2024-11-01 11:05 UTC (permalink / raw)
  To: stephen, dsahern; +Cc: netdev, Denis Kirjanov

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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [iproute2-next] ifstat: handle fclose errors
  2024-11-01 11:05 [iproute2-next] ifstat: handle fclose errors Denis Kirjanov
@ 2024-11-03 15:56 ` Stephen Hemminger
  0 siblings, 0 replies; 2+ messages in thread
From: Stephen Hemminger @ 2024-11-03 15:56 UTC (permalink / raw)
  To: Denis Kirjanov; +Cc: dsahern, netdev

On Fri,  1 Nov 2024 14:05:39 +0300
Denis Kirjanov <kirjanov@gmail.com> wrote:

> fclose() can fail so print an error
> 
> Signed-off-by: Denis Kirjanov <kirjanov@gmail.com>

I am not convinced this is worth the effort, especially
for files that are /proc.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-11-03 15:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-01 11:05 [iproute2-next] ifstat: handle fclose errors Denis Kirjanov
2024-11-03 15:56 ` Stephen Hemminger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).