]> git.proxmox.com Git - mirror_novnc.git/commitdiff
wswrapper: fix preload path and interpose port.
authorJoel Martin <github@martintribe.org>
Thu, 16 Dec 2010 20:04:16 +0000 (14:04 -0600)
committerJoel Martin <github@martintribe.org>
Thu, 16 Dec 2010 20:04:16 +0000 (14:04 -0600)
Make path to ld preload library absolute so wswrapper works even if
path is changed before main program is executed (i.e. by the vncserver
wrapper script).

bind() was using the return value for the port number, but it's
actually the original port number that we should interpose on in the
bind() routine.

utils/wswrap
utils/wswrapper.c

index 68b9307fb0d81fe6eb26a80652e48381183479e4..565d8ed33c7de46f3e0568de1cac19564b0a7477 100755 (executable)
@@ -9,7 +9,7 @@ usage() {
 }
 
 # Parameter defaults
-mydir=$(dirname ${0})
+mydir=$(readlink -f $(dirname ${0}))
 
 # Process parameters
 #while [ "${1}" != "${1#-}" ]; do
index 0a4de4d567091670bd433e69760d878ef3ec2de3..ca4bd987c24aa79a48751c7ce074c262c879170c 100644 (file)
@@ -69,7 +69,7 @@ typedef struct {
  * matches WSWRAP_PORT, otherwise listen to the first socket fd that bind is
  * called on.
  */
-int              _WS_listen_fd  = 0;
+int              _WS_listen_fd  = -1;
 _WS_connection  *_WS_connections[65546];
 
 
@@ -560,40 +560,40 @@ int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen)
     static void * (*func)();
     struct sockaddr_in * addr_in = (struct sockaddr_in *)addr;
     char * WSWRAP_PORT, * end;
-    int fd, envport, bindport = htons(addr_in->sin_port);
+    int ret, envport, bindport = htons(addr_in->sin_port);
     if (!func) func = (void *(*)()) dlsym(RTLD_NEXT, "bind");
     DEBUG("bind(%d, _, %d) called\n", sockfd, addrlen);
 
-    fd = (int) func(sockfd, addr, addrlen);
+    ret = (int) func(sockfd, addr, addrlen);
 
     if (addr_in->sin_family != AF_INET) {
         // TODO: handle IPv6
         DEBUG("bind, ignoring non-IPv4 socket\n");
-        return fd;
+        return ret;
     }
 
     WSWRAP_PORT = getenv("WSWRAP_PORT");
     if ((! WSWRAP_PORT) || (*WSWRAP_PORT == '\0')) {
         // TODO: interpose on all sockets
         DEBUG("bind, not interposing: WSWRAP_PORT is not set\n");
-        return fd;
+        return ret;
     }
 
     envport = strtol(WSWRAP_PORT, &end, 10);
     if ((envport == 0) || (*end != '\0')) {
         MSG("bind, not interposing: WSWRAP_PORT is not a number\n");
-        return fd;
+        return ret;
     }
 
     if (envport != bindport) {
-        DEBUG("bind, not interposing on port %d\n", bindport);
-        return fd;
+        DEBUG("bind, not interposing on port: %d (fd %d)\n", bindport, sockfd);
+        return ret;
     }
 
-    MSG("bind, interposing on port: %d\n", envport);
-    _WS_listen_fd = envport;
+    MSG("bind, interposing on port: %d (fd %d)\n", envport, sockfd);
+    _WS_listen_fd = sockfd;
 
-    return fd;
+    return ret;
 }
 
 int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
@@ -605,11 +605,17 @@ int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
 
     fd = (int) func(sockfd, addr, addrlen);
 
-    if (_WS_listen_fd == 0) {
+    if (_WS_listen_fd == -1) {
         DEBUG("not interposing\n");
         return fd;
     }
 
+    if (_WS_listen_fd != sockfd) {
+        DEBUG("not interposing on fd %d\n", sockfd);
+        return fd;
+    }
+
+
     if (_WS_connections[fd]) {
         MSG("error, already interposing on fd %d\n", fd);
     } else {