socsvn commit: r253280 - soc2013/dpl/head/contrib/bzip2

dpl at FreeBSD.org dpl at FreeBSD.org
Thu Jun 20 11:40:38 UTC 2013


Author: dpl
Date: Thu Jun 20 11:40:38 2013
New Revision: 253280
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253280

Log:
  Switch to socketpair(2).
  

Modified:
  soc2013/dpl/head/contrib/bzip2/bzip2.c

Modified: soc2013/dpl/head/contrib/bzip2/bzip2.c
==============================================================================
--- soc2013/dpl/head/contrib/bzip2/bzip2.c	Thu Jun 20 09:55:53 2013	(r253279)
+++ soc2013/dpl/head/contrib/bzip2/bzip2.c	Thu Jun 20 11:40:38 2013	(r253280)
@@ -222,7 +222,7 @@
 Int32   workFactor;
 
 #ifdef CAPSICUM
-int s, s2, len;
+int sv[2], len;
 struct sockaddr_un sock, remoteSock;
 char *sockPath = "/tmp/bzip2";
 #endif
@@ -981,7 +981,7 @@
    IntNative fh;
    fh = open(name, O_WRONLY|O_CREAT|O_EXCL, S_IWUSR|S_IRUSR);
 /*#  ifdef CAPSICUM*/
-   /*cap_rights_limit(fh, CAP_WRITE);*/
+   cap_rights_limit(fh, CAP_WRITE);
 /*#  endif*/
    if (fh == -1) return NULL;
    fp = fdopen(fh, mode);
@@ -1245,7 +1245,7 @@
    if ( srcMode != SM_I2O ){
 #	ifdef CAPSICUM
 		 infd = open( inName, O_RDONLY );
-		 /*cap_rights_limit(infd, CAP_READ);*/
+		 cap_rights_limit(infd, CAP_READ);
          inStr = fdopen ( infd, "rb" );
 #	else
 		 infd = NULL;
@@ -1322,6 +1322,7 @@
    /* Pass the limited file descriptors with a unix domain socket. */
    switch( forkpid = rfork(RFPROC | RFCFDG) ) {
       case ( 0 ):
+	   /* revmsg() the FDs */
 		if (cap_enter() < 0) {
 		   fprintf ( stderr, "%s: Couldn't enter capability mode: %s.\n", 
 							  progName, strerror(errno) );
@@ -1355,9 +1356,6 @@
          exit(1);
 
 	  default:
-         listen(s, 2);
-		 len = sizeof(struct sockaddr_un);
-		 accept(s, (struct sockaddr *) &remoteSock, &len);
 		 /* Send the two FDs */
          wait(NULL);
          if ( -1 == unlink(sock.sun_path) && errno != ENOENT ){
@@ -2032,21 +2030,11 @@
    sock.sun_family = PF_LOCAL;
    strncpy(sock.sun_path, sockPath, sizeof(sock.sun_path));
    
-   if ( (s = socket(PF_LOCAL, SOCK_STREAM, 0)) == -1 ){
+   if ( socketpair(PF_LOCAL, SOCK_STREAM, 0, sv) == -1 ){
       fprintf ( stderr, "%s: Can't create socket: %s.\n", progName, strerror(errno) );
 	  exit(1);
    }
 
-   if ( -1 == unlink(sock.sun_path) && errno != ENOENT ){
-      fprintf ( stderr, "%s: Can't unlink socket: %s.\n", progName, strerror(errno) );
-      exit(1);
-   }
-
-   if ( (s = bind(s, (struct sockaddr *) &sock, SUN_LEN( &sock ) )) == -1 ){
-	  fprintf ( stderr, "%s: Can't bind socket: %s.\n", progName, strerror(errno) );
-	  exit(1);
-   }
-
    /* XXX - Factorize code here */
    /*if (srcMode == SM_I2O) {*/
       /*if (opMode == OM_Z )*/


More information about the svn-soc-all mailing list