diff mbox series

[iproute2-next] ifstat: handle fclose errors

Message ID 20241101110539.7046-1-kirjanov@gmail.com (mailing list archive)
State Rejected
Delegated to: David Ahern
Headers show
Series [iproute2-next] ifstat: handle fclose errors | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Denis Kirjanov Nov. 1, 2024, 11:05 a.m. UTC
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(-)

Comments

Stephen Hemminger Nov. 3, 2024, 3:56 p.m. UTC | #1
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.
diff mbox series

Patch

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);
 }