Can't start X twice

Petr Salinger Petr.Salinger at t-systems.cz
Mon Nov 7 21:07:07 UTC 2005


> > #if defined(BSD44SOCKETS) && !defined(Lynx)
> >     sockname.sun_len = strlen(sockname.sun_path);
> >     namelen = SUN_LEN(&sockname);
> > #else
> >     namelen = strlen(sockname.sun_path) + sizeof(sockname.sun_family);
> > #endif
> 
> The horror!  HasBSD44Sockets strikes again!
> 
> Sorry, can't help.  I never figured out the problem before.  I'd also point to
> #187391 for the discussion about sun_len being different on GNU/Hurd than on
> GNU/Linux, which might help or might be entirely unrelated.

The problem is a different definition of struct sockaddr_un.

BSD43, Linux:
struct sockaddr_un {
        unsigned short sun_family; 
        char sun_path[108]; 
}


BSD44:

struct sockaddr_un {
	unsigned char sun_len;
        unsigned char sun_family; 
        char sun_path[108];                           
} 

int bind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen);
int connect(int  sockfd,  const  struct sockaddr *serv_addr, socklen_t  addrlen);

FreeBSD kernel 5.4 and 6.0 tries to be compatible with older source code
and at least in connect(), bind() ignores value in the field sun_len.
It uses only the value addrlen from function in system call.

Unfortunately, the code computes the whole name length as

namelen = strlen(sockname.sun_path) + sizeof(sockname.sun_family);
instead of portable
namelen = strlen(sockname.sun_path) + offsetof(struct sockaddr_un, sun_path);

Therefore, it would be sufficient to correct calculation with sun_path in 
whole xorg-x11. Moreover, it is mainly correct, only 2 files need fix.

ok	programs/xdm/prngc.c
ok	programs/xdm/xdmcp.c
ok	programs/xdm/netaddr.c
patch	lib/dps/csconndi.c
patch	lib/xtrans/Xtranssock.c
ok	lib/xtrans/Xtranstli.c
ok	lib/xtrans/Xtranslcl.c
ok	lib/xtrans/Xtransutil.c
ok	extras/Mesa/src/glx/mini/miniglx_events.c	

The (enclosed) patch is straightforward, but I can't test it.


Petr


--- lib/dps/csconndi.c~ 2005-11-07 20:59:23.000000000 +0000
+++ lib/dps/csconndi.c  2005-11-07 20:59:23.000000000 +0000
@@ -506,7 +506,7 @@
     sprintf (unaddr.sun_path, "%s_%d", CSDPS_UNIX_PATH, port);
 
     addr = (struct sockaddr *) &unaddr;
-    addrlen = strlen(unaddr.sun_path) + sizeof(unaddr.sun_family);
+    addrlen = strlen(unaddr.sun_path) + offsetof(struct sockaddr_un, sun_path));
 
     /*
      * Open the network connection.


--- lib/xtrans/Xtranssock.c~    2005-11-07 21:02:32.000000000 +0000
+++ lib/xtrans/Xtranssock.c     2005-11-07 21:02:32.000000000 +0000
@@ -1092,7 +1092,7 @@
     sockname.sun_len = strlen(sockname.sun_path);
     namelen = SUN_LEN(&sockname);
 #else
-    namelen = strlen(sockname.sun_path) + sizeof(sockname.sun_family);
+    namelen = strlen(sockname.sun_path) + offsetof(struct sockaddr_un, sun_path);
 #endif
 
     unlink (sockname.sun_path);
@@ -1975,7 +1975,7 @@
     sockname.sun_len = strlen (sockname.sun_path);
     namelen = SUN_LEN (&sockname);
 #else
-    namelen = strlen (sockname.sun_path) + sizeof (sockname.sun_family);
+    namelen = strlen (sockname.sun_path) + offsetof(struct sockaddr_un, sun_path);
 #endif
 
 
@@ -1989,7 +1989,7 @@
        return TRANS_CONNECT_FAILED;
     }
     old_namelen = strlen (old_sockname.sun_path) +
-       sizeof (old_sockname.sun_family);
+       offsetof(struct sockaddr_un, sun_path);
 #endif
 





More information about the Glibc-bsd-devel mailing list