netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH iproute2] ifstat: handle unlink return value
@ 2024-02-21 12:04 Denis Kirjanov
  2024-02-29  0:51 ` Stephen Hemminger
  0 siblings, 1 reply; 2+ messages in thread
From: Denis Kirjanov @ 2024-02-21 12:04 UTC (permalink / raw)
  To: stephen; +Cc: netdev, Denis Kirjanov

Print an error message if we can't remove the history file

Signed-off-by: Denis Kirjanov <dkirjanov@suse.de>
---
 misc/ifstat.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/misc/ifstat.c b/misc/ifstat.c
index 18171a2c..5dede111 100644
--- a/misc/ifstat.c
+++ b/misc/ifstat.c
@@ -938,7 +938,9 @@ int main(int argc, char *argv[])
 				 getuid());
 
 	if (reset_history)
-		unlink(hist_name);
+		if (unlink(hist_name) < 0)
+			fprintf(stderr, "Cannot remove history file \"%s\": %s\n",
+				hist_name, strerror(errno));
 
 	if (!ignore_history || !no_update) {
 		struct stat stb;
-- 
2.30.2


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

* Re: [PATCH iproute2] ifstat: handle unlink return value
  2024-02-21 12:04 [PATCH iproute2] ifstat: handle unlink return value Denis Kirjanov
@ 2024-02-29  0:51 ` Stephen Hemminger
  0 siblings, 0 replies; 2+ messages in thread
From: Stephen Hemminger @ 2024-02-29  0:51 UTC (permalink / raw)
  To: Denis Kirjanov; +Cc: netdev, Denis Kirjanov

On Wed, 21 Feb 2024 07:04:24 -0500
Denis Kirjanov <kirjanov@gmail.com> wrote:

> Print an error message if we can't remove the history file
> 
> Signed-off-by: Denis Kirjanov <dkirjanov@suse.de>
> ---

Good idea, but would like the output and result to look like
the other errors in ifstat about history file. Something like:

diff --git a/misc/ifstat.c b/misc/ifstat.c
index 767cedd4aa47..72901097e6c2 100644
--- a/misc/ifstat.c
+++ b/misc/ifstat.c
@@ -937,8 +937,10 @@ int main(int argc, char *argv[])
                                 "%s/.%s_ifstat.u%d", P_tmpdir, stats_type,
                                 getuid());
 
-       if (reset_history)
-               unlink(hist_name);
+       if (reset_history && unlink(hist_name) < 0) {
+               perror("ifstat: unlink history file");
+               exit(-1);
+       }
 
        if (!ignore_history || !no_update) {
                struct stat stb;

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

end of thread, other threads:[~2024-02-29  0:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-21 12:04 [PATCH iproute2] ifstat: handle unlink return value Denis Kirjanov
2024-02-29  0:51 ` 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).