Skip to contentSkip to conversation

shared/mainloop: Use connect() instead of bind() for sd_notify

PATCH Applied Guillem Jover 2 participants 2 messages Dec 14, 2019 – Dec 16, 2019 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 shared/mainloop: Use connect() instead of bind() for sd_notify

We are the client, so we should be using connect(2) instead of bind(2), otherwise when using non-abstract Unix sockets we will get an error that the address is already in use.

This breaks the notify support in dpkg's start-stop-daemon.

---
 src/shared/mainloop-notify.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/shared/mainloop-notify.c +1 -1
index 89a880006..1de714a0e 100644
@@ -91,7 +91,7 @@ void mainloop_notify_init(void)
 	if (addr.sun_path[0] == '@')
 		addr.sun_path[0] = '\0';
 
-	if (bind(notify_fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
+	if (connect(notify_fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
 		close(notify_fd);
 		notify_fd = -1;
 		return;
Signature · 1 line
2.24.1.658.g99f4b37f93
maintainer Applied
#1 lore raw

Hi Guillem,

Quoted 25 lines · Guillem Jover

We are the client, so we should be using connect(2) instead of bind(2),
otherwise when using non-abstract Unix sockets we will get an error that
the address is already in use.

This breaks the notify support in dpkg's start-stop-daemon.

---
 src/shared/mainloop-notify.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/shared/mainloop- renamed from src/shared/mainloop-notify.c +0 -0

notify.c
index 89a880006..1de714a0e 100644

src/shared/mainloop-notify.c +1 -1
@@ -91,7 +91,7 @@ void mainloop_notify_init(void)
 	if (addr.sun_path[0] == '@')
 		addr.sun_path[0] = '\0';
 
-	if (bind(notify_fd, (struct sockaddr *) &addr, sizeof(addr)) <
 0) {
+	if (connect(notify_fd, (struct sockaddr *) &addr, sizeof(addr))
 < 0) {
 		close(notify_fd);

src/shared/mainloop-notify.c void mainloop_notify_init(void) · line 97

Quoted 2 lines
src/shared/mainloop-notify.c +0 -0
 		notify_fd = -1;
 		return;

Applied, thanks.