From 3066195d79f5f24f99483d29e2489a91c9251d73 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Wed, 27 Dec 2017 13:09:25 +0100 Subject: Loop.cpp: some reformatting/simplification/FIXMEs (partially) fixes ArcticaProject/nx-libs#612 --- nxcomp/src/Loop.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'nxcomp/src') diff --git a/nxcomp/src/Loop.cpp b/nxcomp/src/Loop.cpp index e84896e36..e922b55a5 100644 --- a/nxcomp/src/Loop.cpp +++ b/nxcomp/src/Loop.cpp @@ -3861,7 +3861,8 @@ void SetupDisplaySocket(int &addr_family, sockaddr *&addr, #ifdef __APPLE__ - if ((strncasecmp(display, "/tmp/launch", 11) == 0) || (strncasecmp(display, "/private/tmp/com.apple.launchd", 30) == 0)) + if ((strncasecmp(display, "/tmp/launch", 11) == 0) || + (strncasecmp(display, "/private/tmp/com.apple.launchd", 30) == 0)) { nxinfo << "Loop: Using launchd service on socket '" << display << "'.\n" << std::flush; @@ -3934,19 +3935,24 @@ void SetupDisplaySocket(int &addr_family, sockaddr *&addr, // fall back to Unix domain socket file. #ifdef __linux__ - int testSocketFD; - testSocketFD = socket(addr_family, SOCK_STREAM, PF_UNSPEC); + int testSocketFD = socket(addr_family, SOCK_STREAM, PF_UNSPEC); + // this name cannot be changed as it is defined this way by the + // local X server int len = sprintf(unixSocketName + 1, "/tmp/.X11-unix/X%d", xPort); unixSocketName[0] = '\0'; sockaddr_un *xServerAddrABSTRACT = new sockaddr_un; memset(xServerAddrABSTRACT, 0, sizeof(struct sockaddr_un)); xServerAddrABSTRACT -> sun_family = AF_UNIX; + // FIXME: ensure sun_path can hold len+1 bytes! memcpy(xServerAddrABSTRACT -> sun_path, unixSocketName, len+1); - addr_length = len +3; + // FIXME: comment why + 3? + addr_length = len + 3; - int ret = connect(testSocketFD, (struct sockaddr *) xServerAddrABSTRACT, addr_length); + int ret = connect(testSocketFD, + (struct sockaddr *) xServerAddrABSTRACT, + addr_length); close(testSocketFD); if (ret == 0) { -- cgit v1.2.3