socsvn commit: r253561 - in soc2013/dpl/head: contrib/bzip2 usr.bin/bzip2

dpl at FreeBSD.org dpl at FreeBSD.org
Wed Jun 26 21:14:28 UTC 2013


Author: dpl
Date: Wed Jun 26 21:14:28 2013
New Revision: 253561
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253561

Log:
  Reimplemented sendfd and recvfd, now I know _where_ it breaks, but not why.
  

Modified:
  soc2013/dpl/head/contrib/bzip2/bzip2.c
  soc2013/dpl/head/usr.bin/bzip2/Makefile

Modified: soc2013/dpl/head/contrib/bzip2/bzip2.c
==============================================================================
--- soc2013/dpl/head/contrib/bzip2/bzip2.c	Wed Jun 26 20:39:07 2013	(r253560)
+++ soc2013/dpl/head/contrib/bzip2/bzip2.c	Wed Jun 26 21:14:28 2013	(r253561)
@@ -230,58 +230,72 @@
 int
 sendfd(int s, int fd)
 {
-   char buf[1] = { 0 };
-   struct iovec iov;
-   iov.iov_base = buf;
-   iov.iov_len = 1;
-   
-   struct msghdr msg;
-   char cms[CMSG_SPACE(sizeof(int))];
-   bzero(&msg, sizeof msg);
-   msg.msg_iov = &iov;
-   msg.msg_iovlen = 1;
-   msg.msg_control = (caddr_t)cms;
-   msg.msg_controllen = CMSG_LEN(sizeof(int));
-   
-   struct cmsghdr *cmsg;
-   cmsg = CMSG_FIRSTHDR(&msg);
-   cmsg->cmsg_len = CMSG_LEN(sizeof(int));
-   cmsg->cmsg_level = SOL_SOCKET;
-   cmsg->cmsg_type = SCM_RIGHTS;
-   memcpy(CMSG_DATA(cmsg), &fd, sizeof(int));
-   
-   printf("sendfd fd: %d\n", fd);
-   if((sendmsg(s, &msg, 0)) != (int)iov.iov_len)
-      return -1;
-   return 0;
+	printf("sendfd on socket:%d fd:%d\n",s,fd);
+    struct {
+		struct cmsghdr h;
+		int fd;
+    } buffer;
+
+    struct msghdr msg;
+    char buf = 0;
+    struct iovec io;
+    struct cmsghdr *cmsg;
+
+    io.iov_base = &buf;
+    io.iov_len = 1;
+
+	bzero(&msg, sizeof msg);
+    msg.msg_iov = &io;
+    msg.msg_iovlen = 1;
+    msg.msg_control = &buffer;
+    msg.msg_controllen = sizeof(struct cmsghdr) + sizeof(int);
+
+    cmsg = CMSG_FIRSTHDR(&msg);
+    cmsg->cmsg_len = msg.msg_controllen;
+    cmsg->cmsg_level = SOL_SOCKET;
+    cmsg->cmsg_type = SCM_RIGHTS;
+	printf("Gotten this far\n");
+	/* Something breaks here */
+	memcpy(CMSG_DATA(cmsg), fd, sizeof(int));
+	if(sendmsg(s, &msg, 0) < 0)
+		return -1;
+	else
+		return 0;
 }
 
 int
 recvfd(int s)
 {
-   int fd;
-   struct cmsghdr *cmsg;
-   
-   char buf[1] = { 0 };
-   struct iovec iov;
-   iov.iov_base = buf;
-   iov.iov_len = 1;
-   
-   struct msghdr msg;
-   char cms[CMSG_SPACE(sizeof(int))];
-   msg.msg_name = 0;
-   msg.msg_namelen = 0;
-   msg.msg_iov = &iov;
-   msg.msg_iovlen = 1;
-   msg.msg_control = (caddr_t)cms;
-   msg.msg_controllen = sizeof cms;
-   
-   if((recvmsg(s, &msg, 0)) <= 0)
-      return -1;
-   cmsg = CMSG_FIRSTHDR(&msg);
-   memcpy(&fd, CMSG_DATA(cmsg), sizeof(int));
-   printf("recvfd fd: %d\n", fd);
-   return fd;
+	printf("recvfd on socket: %d\n",s);
+    struct {
+		struct cmsghdr h;
+		int fd;
+    } buffer;
+    char buf = 0;
+    struct iovec io;
+    struct msghdr msg;
+    struct cmsghdr *cmsg;
+
+    io.iov_base = &buf;
+    io.iov_len = 1;
+
+	bzero(&msg, sizeof msg);
+    msg.msg_iov = &io;
+    msg.msg_iovlen = 1;
+    msg.msg_control = &buffer;
+    msg.msg_controllen = sizeof(struct cmsghdr) + sizeof(int);
+
+    cmsg = CMSG_FIRSTHDR(&msg);
+    cmsg->cmsg_len = msg.msg_controllen;
+    cmsg->cmsg_level = SOL_SOCKET;
+    cmsg->cmsg_type = SCM_RIGHTS;
+	/* Something breaks here */
+	memcpy(CMSG_DATA(cmsg), -1, sizeof(int));
+	printf("is this -1? %d", (int)CMSG_DATA(cmsg));
+    
+    if(recvmsg(s, &msg, 0) < 0)
+		return -1 ;
+    return ((int *)CMSG_DATA(cmsg));
 }
 #endif
 
@@ -1387,7 +1401,7 @@
       exit(exitValue);
    }
 
-   printf("About to fork()\n");
+   printf("fork()\n");
    /* Pass the limited file descriptors with a unix domain socket. */
    switch( forkpid = fork() ) {
 	  case ( -1 ):
@@ -1396,20 +1410,25 @@
          exit(exitValue);
 
       case ( 0 ):
-		 printf("Child\n");
-         if ((infd = recvfd(sv[1])) <= 0){
+         if ((close(sv[0])) < 0){
+            fprintf ( stderr, "%s: Couldn't close fd: %s.\n", 
+                            progName, strerror(errno) );
+            setExit(1);
+            exit(exitValue);
+         }
+		 printf("About to recv infd\n");
+         if ((infd = recvfd(sv[1])) < 0){
             fprintf ( stderr, "%s: Couldn't get infd: %s.\n", 
                             progName, strerror(errno) );
             setExit(1);
             exit(exitValue);
-          }
-
-         if ((outfd = recvfd(sv[1])) <= 0){
+         }
+         if ((outfd = recvfd(sv[1])) < 0){
             fprintf ( stderr, "%s: Couldn't get outfd: %s.\n", 
                             progName, strerror(errno) );
             setExit(1);
             exit(exitValue);
-          }
+         }
 	     printf("Child: infd:%d, outfd:%d\n", infd, outfd);
          inStr = fdopen(infd, "rb");
          outStr = fdopen(outfd, "wb");
@@ -1445,6 +1464,12 @@
 
 	  default:
 	     printf("Parent: infd:%d, outfd:%d\n", infd, outfd);
+         if ((close(sv[1])) < 0){
+            fprintf ( stderr, "%s: Couldn't close fd: %s.\n", 
+                            progName, strerror(errno) );
+            setExit(1);
+            exit(exitValue);
+         }
          if (sendfd(sv[0], infd) < 0){
             fprintf ( stderr, "%s: Couldn't send infd: %s.\n", 
                             progName, strerror(errno) );

Modified: soc2013/dpl/head/usr.bin/bzip2/Makefile
==============================================================================
--- soc2013/dpl/head/usr.bin/bzip2/Makefile	Wed Jun 26 20:39:07 2013	(r253560)
+++ soc2013/dpl/head/usr.bin/bzip2/Makefile	Wed Jun 26 21:14:28 2013	(r253561)
@@ -5,6 +5,9 @@
 
 PROG=	bzip2
 CFLAGS+= -D_FILE_OFFSET_BITS=64
+#TODO: Delete this.
+CFLAGS+= -fno-color-diagnostics
+CFLAGS+= -g
 
 WARNS?=	3
 


More information about the svn-soc-all mailing list