Skip to contentSkip to conversation

ctrl: Fix fd leak in ctrl_listen()

PATCH Applied Stephen Hemminger 2 participants 4 messages Feb 8, 2024 – Feb 9, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/3 ctrl: Fix fd leak in ctrl_listen()

From: Maks Mishin <[email protected]>

Use the same pattern for handling rtnl_listen() errors that is used across other iproute2 commands. All other commands exit with status of 2 if rtnl_listen fails.

---
 genl/ctrl.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
genl/ctrl.c +3 -2
index bae73a54bc37..72a9b01302cf 100644
@@ -334,8 +334,9 @@ static int ctrl_listen(int argc, char **argv)
 	}
 
 	if (rtnl_listen(&rth, print_ctrl, (void *) stdout) < 0)
-		return -1;
-
+		exit(2);
+	
+	rtnl_close(&rth);	
 	return 0;
 }
 
Signature · 1 line
2.43.0
#1 lore raw

PATCH 2/3 ip: detect errors in netconf monitor mode

If rtnl_listen() returns error while looking for netconf events, then exit with status of 2 as other iproute2 monitor actions do.

---
 ip/ipnetconf.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
ip/ipnetconf.c +2 -1
index 9ae6c45e7fd1..a0c7e051bac5 100644
@@ -193,7 +193,8 @@ static int do_show(int argc, char **argv)
 			perror("Can not send request");
 			exit(1);
 		}
-		rtnl_listen(&rth, print_netconf, stdout);
+		if (rtnl_listen(&rth, print_netconf, stdout) < 0)
+			exit(2);
 	} else {
 		rth.flags = RTNL_HANDLE_F_SUPPRESS_NLERR;
 dump:
Signature · 1 line
2.43.0
#2 lore raw

PATCH 3/3 ip: detect rtnl_listen errors while monitoring netns

In reply to Stephen Hemminger

If rtnl_listen detects error (such as netlink socket EOF), then exit with status 2 like other iproute2 monitor commands.

---
 ip/ipnetns.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
ip/ipnetns.c +2 -1
index 0ae46a874a0c..594b2ef15d0c 100644
@@ -96,7 +96,8 @@ static int ipnetns_have_nsid(void)
 			close(fd);
 			return 0;
 		}
-		rtnl_listen(&rth, ipnetns_accept_msg, NULL);
+		if (rtnl_listen(&rth, ipnetns_accept_msg, NULL) < 0)
+			exit(2);
 		close(fd);
 	}
 
Signature · 1 line
2.43.0
#3 lore raw
In reply to Stephen Hemminger
This series was applied to iproute2/iproute2.git (main) by Stephen Hemminger <[email protected]>:

Hello:

This series was applied to iproute2/iproute2.git (main) by Stephen Hemminger <[email protected]>:

Quoted 10 lines · On Thu, 8 Feb 2024 09:26:27 -0800 you wrote:

From: Maks Mishin <[email protected]>

Use the same pattern for handling rtnl_listen() errors that is used across other iproute2 commands. All other commands exit with status of 2 if rtnl_listen fails.

[...]

Here is the summary with links:
- [iproute2,1/3] ctrl: Fix fd leak in ctrl_listen()

    https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=f4dc6a784f6e
  - [iproute2,2/3] ip: detect errors in netconf monitor mode
    https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=00e8a64dac3b
  - [iproute2,3/3] ip: detect rtnl_listen errors while monitoring netns
    https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=8f340a075138

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html