Browse Source

send_cmd() retrun value bugfix + minor debug changes

Joseph Henry 9 years ago
parent
commit
a421e31dd5
4 changed files with 12 additions and 11 deletions
  1. 4 4
      make-linux.mk
  2. 2 3
      netcon/Intercept.c
  3. 2 0
      netcon/NetconEthernetTap.cpp
  4. 4 4
      netcon/common.inc.c

+ 4 - 4
make-linux.mk

@@ -105,10 +105,10 @@ netcon: $(OBJS)
 	ln -sf zerotier-netcon-service zerotier-cli
 	ln -sf zerotier-netcon-service zerotier-idtool
 
-#install-intercept:
-#	cp libzerotierintercept.so /lib/libzerotierintercept.so
-#	ln -sf /lib/libzerotierintercept.so /lib/libzerotierintercept
-#	/usr/bin/install -c netcon/zerotier-intercept /usr/bin
+install-intercept:
+	cp libzerotierintercept.so /lib/libzerotierintercept.so
+	ln -sf /lib/libzerotierintercept.so /lib/libzerotierintercept
+	/usr/bin/install -c netcon/zerotier-intercept /usr/bin
 
 #uninstall-intercept:
 #	rm -r /lib/libzerotierintercept.so

+ 2 - 3
netcon/Intercept.c

@@ -138,7 +138,7 @@ static void checkpid()
     return;
 
   if (thispid != getpid()) {
-    printf("clone/fork detected. re-initializing this instance.\n");
+    dwr(MSG_DEBUG, "checkpid(): clone/fork detected. Re-initializing this instance.\n");
     set_up_intercept();
     fdret_sock = init_service_connection();
     thispid = getpid();
@@ -216,12 +216,11 @@ static int send_cmd(int rpc_fd, char *cmd)
 #endif
   /* Combine command flag+payload with RPC metadata */
   memcpy(&metabuf[IDX_PAYLOAD], cmd, PAYLOAD_SZ);
-  usleep(1000);
+  usleep(100000);
   int n_write = write(rpc_fd, &metabuf, BUF_SZ);
   if(n_write < 0){
     dwr(MSG_DEBUG,"Error writing command to service (CMD = %d)\n", cmd[0]);
     errno = 0;
-    return -1;
   }
 
   int ret = ERR_OK;

+ 2 - 0
netcon/NetconEthernetTap.cpp

@@ -848,6 +848,8 @@ err_t NetconEthernetTap::nc_accept(void *arg, struct tcp_pcb *newpcb, err_t err)
 	dwr(MSG_DEBUG, " nc_accept(): socketpair = {%d, %d}\n", fds[0], fds[1]);
 	int send_fd = tap->_phy.getDescriptor(conn->rpcSock);
 
+dwr(MSG_DEBUG, "nc_accept(): sending %d via %d\n", fds[1], listening_fd);
+
 	if(sock_fd_write(listening_fd, fds[1]) < 0){
 		dwr(MSG_ERROR, " nc_accept(%d): error writing signal byte (listen_fd = %d, perceived_fd = %d)\n", listening_fd, send_fd, fds[1]);
   		return -1;

+ 4 - 4
netcon/common.inc.c

@@ -39,9 +39,9 @@
 #include <fcntl.h>
 
 
-#define DEBUG_LEVEL 0
+#define DEBUG_LEVEL 4
 
-#define MSG_WARNING     0
+#define MSG_WARNING     4
 #define MSG_ERROR       1 // Errors
 #define MSG_INFO        2 // Information which is generally useful to any user
 #define MSG_DEBUG       3 // Information which is only useful to someone debugging
@@ -171,7 +171,7 @@ static ssize_t sock_fd_read(int sock, void *buf, ssize_t bufsize, int *fd)
     msg.msg_controllen = sizeof(cmsgu.control);
     size = recvmsg (sock, &msg, 0);
     if (size < 0) {
-      perror ("recvmsg");
+      dwr(MSG_DEBUG, "sock_fd_read(): recvmsg: Error\n");
       return -1;
     }
     cmsg = CMSG_FIRSTHDR(&msg);
@@ -190,7 +190,7 @@ static ssize_t sock_fd_read(int sock, void *buf, ssize_t bufsize, int *fd)
   } else {
     size = read (sock, buf, bufsize);
     if (size < 0) {
-      perror("read");
+      dwr(MSG_DEBUG, "sock_fd_read(): read: Error\n");
       return -1;
     }
   }