Source: libqb
Version: 0.17.2.real-4
Severity: normal
Tags: patch
Usertags: linux

Hi,

Currently libqb FTBFS on linux-amd64 for test ipc.test, when applying
the attached patch, fix_ipc_setup_bug.patch. (in fact the unpatched
version FTBFS with gcc-4.9.1-16).

This patch fixes writing of the *.sun_path socket names to become
non-zero for bind() and connect().
The previous race condition is back for the ipc_stress_connections_us
test. Adding the unlink statement solves this problem (unknown how,
since res=-1 due to ENOENT: No such file or directory.)

The patch, rules1.patch removes the named sockets created during the ipc
test to enable successive builds. Otherwise the build fails with:
EADDRINUSE Address already in use (seems like the randomization in
creating these names does not work from build to build)  These removals
can probably be placed somewhere in check_ipc.c, but is placed in
debian/rules for now.

Thanks!
--- a/rules.orig	2015-09-23 10:41:56.000000000 +0200
+++ b/debian/rules	2015-11-01 22:44:38.983596438 +0100
@@ -20,6 +20,10 @@
 %:
 	dh $@ --with autoreconf,autotools_dev --fail-missing --link-doc=libqb0
 
+override_dh_auto_clean:
+# clean out tests/{qb-,}test_ipc_* sockets from old build if present
+	-rm tests/qb-test_ipc_* tests/test_ipc_*
+
 override_dh_autoreconf:
 	dh_autoreconf ./autogen.sh
 
Index: libqb-0.17.2.real/lib/ipc_setup.c
===================================================================
--- libqb-0.17.2.real.orig/lib/ipc_setup.c
+++ libqb-0.17.2.real/lib/ipc_setup.c
@@ -283,7 +283,7 @@ qb_ipcc_stream_sock_connect(const char *
 #endif
 
 #if defined(QB_LINUX) || defined(QB_CYGWIN)
-	snprintf(address.sun_path + 1, UNIX_PATH_MAX - 1, "%s", socket_name);
+	snprintf(address.sun_path, sizeof(address.sun_path), "%s", socket_name);
 #else
 	snprintf(address.sun_path, sizeof(address.sun_path), "%s/%s", SOCKETDIR,
 		 socket_name);
@@ -395,7 +395,7 @@ qb_ipcs_us_publish(struct qb_ipcs_servic
 
 	qb_util_log(LOG_INFO, "server name: %s", s->name);
 #if defined(QB_LINUX) || defined(QB_CYGWIN)
-	snprintf(un_addr.sun_path + 1, UNIX_PATH_MAX - 1, "%s", s->name);
+	snprintf(un_addr.sun_path, sizeof(un_addr.sun_path), "%s", s->name);
 #else
 	{
 		struct stat stat_out;
Index: libqb-0.17.2.real/lib/ipc_socket.c
===================================================================
--- libqb-0.17.2.real.orig/lib/ipc_socket.c
+++ libqb-0.17.2.real/lib/ipc_socket.c
@@ -51,7 +51,7 @@ set_sock_addr(struct sockaddr_un *addres
 #endif
 
 #if defined(QB_LINUX) || defined(QB_CYGWIN)
-	snprintf(address->sun_path + 1, UNIX_PATH_MAX - 1, "%s", socket_name);
+	snprintf(address->sun_path, sizeof(address->sun_path), "%s", socket_name);
 #else
 	snprintf(address->sun_path, sizeof(address->sun_path), "%s/%s", SOCKETDIR,
 		 socket_name);
@@ -82,6 +82,8 @@ qb_ipc_dgram_sock_setup(const char *base
 #if !(defined(QB_LINUX) || defined(QB_CYGWIN))
 	res = unlink(local_address.sun_path);
 #endif
+	/* Note: This makes the race go away even if res=-1 due to ENOENT */
+	res = unlink(local_address.sun_path);
 	res = bind(request_fd, (struct sockaddr *)&local_address,
 		   sizeof(local_address));
 	if (res < 0) {

Reply via email to