]> git.openfabrics.org - ~shefty/librdmacm.git/commitdiff
support for debug prints
authorSean Hefty <sean.hefty@intel.com>
Wed, 8 Aug 2012 04:30:48 +0000 (21:30 -0700)
committerSean Hefty <sean.hefty@intel.com>
Wed, 8 Aug 2012 04:33:33 +0000 (21:33 -0700)
src/preload.c

index 53f8543266ebe673b15807e16fcbdf9ccee8c283..83cf471e595db0d188acb685e0c25325c8e7c1ed 100644 (file)
@@ -48,6 +48,8 @@
 #include <netinet/tcp.h>
 #include <unistd.h>
 #include <semaphore.h>
+#include <stdio.h>
+#include <sys/syscall.h>
 
 #include <rdma/rdma_cma.h>
 #include <rdma/rdma_verbs.h>
@@ -98,6 +100,8 @@ static int rq_size;
 static int sq_inline;
 static int fork_support;
 
+static FILE *fout;
+
 enum fd_type {
        fd_normal,
        fd_rsocket,
@@ -286,6 +290,7 @@ static void init_preload(void)
        rs.getsockopt = dlsym(RTLD_DEFAULT, "rgetsockopt");
        rs.fcntl = dlsym(RTLD_DEFAULT, "rfcntl");
 
+       fout = fopen("rs-out.txt", "w+");
        getenv_options();
        init = 1;
 out:
@@ -391,6 +396,8 @@ int socket(int domain, int type, int protocol)
        if (index < 0)
                return index;
 
+       fprintf(fout, "%d socket - %d\n", syscall(SYS_gettid), index);
+       fflush(fout);
        recursive = 1;
        ret = rsocket(domain, type, protocol);
        recursive = 0;
@@ -405,6 +412,9 @@ int socket(int domain, int type, int protocol)
                        fd_store(index, ret, fd_rsocket);
                        set_rsocket_options(ret);
                }
+               fprintf(fout, "%d socket - %d fd %d type %d\n",
+                               syscall(SYS_gettid), index, ret, fd_gett(index));
+               fflush(fout);
                return index;
        }
        fd_close(index, &ret);
@@ -432,6 +442,8 @@ int accept(int socket, struct sockaddr *addr, socklen_t *addrlen)
        enum fd_type type;
 
        type = fd_get(socket, &fd);
+       fprintf(fout, "%d accept fd %d\n", syscall(SYS_gettid), socket);
+       fflush(fout);
        if (type == fd_rsocket || type == fd_fork) {
                index = fd_open();
                if (index < 0)
@@ -444,6 +456,8 @@ int accept(int socket, struct sockaddr *addr, socklen_t *addrlen)
                        return ret;
                }
 
+               fprintf(fout, "%d accept fd %d new fd %d\n", syscall(SYS_gettid), socket, index);
+               fflush(fout);
                fd_store(index, ret, type);
                return index;
        } else {
@@ -465,6 +479,8 @@ static int fork_active(int socket, const struct sockaddr *addr, socklen_t addrle
        long flags;
 
        fd = fd_getd(socket);
+       fprintf(fout, "%d fork_active - %d fd %d\n", syscall(SYS_gettid), socket, fd);
+       fflush(fout);
        flags = real.fcntl(fd, F_GETFL);
        real.fcntl(fd, F_SETFL, 0);
        ret = real.connect(fd, addr, addrlen);
@@ -495,6 +511,8 @@ static void fork_passive(int socket)
        uint32_t msg;
 
        fd_get(socket, &sfd);
+       fprintf(fout, "%d fork_passive - %d fd %d\n", syscall(SYS_gettid), socket, sfd);
+       fflush(fout);
 
        len = sizeof sin6;
        ret = real.getsockname(sfd, (struct sockaddr *) &sin6, &len);
@@ -527,11 +545,17 @@ static void fork_passive(int socket)
        ret = rlisten(lfd, 1);
        if (ret)
                goto lclose;
+       fprintf(fout, "%d fork_passive - %d listening for fork\n", syscall(SYS_gettid), socket);
+       fflush(fout);
 
        msg = 0;
        len = real.write(sfd, &msg, sizeof msg);
        if (len != sizeof msg)
+       {
+               fprintf(fout, "%d fork_passive - %d write failed\n", syscall(SYS_gettid), socket);
+               fflush(fout);
                goto lclose;
+       }
 
        dfd = raccept(lfd, NULL, NULL);
        if (dfd < 0) {
@@ -547,6 +571,8 @@ static void fork_passive(int socket)
        real.shutdown(sfd, SHUT_RDWR);
        real.close(sfd);
        fd_store(socket, dfd, fd_rsocket);
+       fprintf(fout, "%d fork_passive success - %d new fd %d\n", syscall(SYS_gettid), socket, dfd);
+       fflush(fout);
 
 lclose:
        rclose(lfd);
@@ -924,6 +950,7 @@ int dup2(int oldfd, int newfd)
        int ret;
 
        init_preload();
+       fprintf(fout, "%d dup2 %d -> %d\n", syscall(SYS_gettid), oldfd, newfd);
        oldfdi = idm_lookup(&idm, oldfd);
        if (oldfdi && oldfdi->type == fd_fork)
                fork_passive(oldfd);
@@ -968,12 +995,18 @@ int __fxstat64(int ver, int socket, struct stat64 *buf)
 {
        int fd, ret;
 
+       init_preload();
+       fprintf(fout, "%d fxstat64 socket %d - fd %d type %d\n",
+                       syscall(SYS_gettid), socket, fd_getd(socket), fd_gett(socket));
        if (fd_get(socket, &fd) == fd_rsocket) {
                ret = real.fxstat64(ver, socket, buf);
+               fprintf(fout, "%d fxstat64 - rsocket %d\n", syscall(SYS_gettid), ret);
                if (!ret)
                        buf->st_mode = (buf->st_mode & ~S_IFMT) | __S_IFSOCK;
        } else {
                ret = real.fxstat64(ver, fd, buf);
+               fprintf(fout, "%d fxstat64 - normal %d\n", syscall(SYS_gettid), ret);
        }
+       fflush(fout);
        return ret;
 }