socsvn commit: r253495 - soc2013/dpl/head/contrib/bzip2
dpl at FreeBSD.org
dpl at FreeBSD.org
Tue Jun 25 19:14:42 UTC 2013
Author: dpl
Date: Tue Jun 25 19:14:41 2013
New Revision: 253495
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253495
Log:
Rewrite socketpair(), and open correctly the files (only compressing).
Modified:
soc2013/dpl/head/contrib/bzip2/bzip2.c
Modified: soc2013/dpl/head/contrib/bzip2/bzip2.c
==============================================================================
--- soc2013/dpl/head/contrib/bzip2/bzip2.c Tue Jun 25 18:44:15 2013 (r253494)
+++ soc2013/dpl/head/contrib/bzip2/bzip2.c Tue Jun 25 19:14:41 2013 (r253495)
@@ -221,7 +221,7 @@
FILE *outputHandleJustInCase;
Int32 workFactor;
-#if CAPSICUM == 1
+#if CAPSICUM
int sv[2], len;
int sendfd(int, int);
@@ -1316,6 +1316,7 @@
break;
case SM_F2O:
+ inStr = fopen ( inName, "rb" );
outStr = stdout;
if ( isatty ( fileno ( stdout ) ) ) {
fprintf ( stderr,
@@ -1323,7 +1324,6 @@
progName );
fprintf ( stderr, "%s: For help, type: `%s --help'.\n",
progName, progName );
- inStr = fopen ( inName, "rb" );
if ( inStr != NULL ) fclose ( inStr );
setExit(1);
return;
@@ -1337,11 +1337,11 @@
break;
case SM_F2F:
+ inStr = fopen ( inName, "rb" );
outStr = fopen_output_safely ( outName, "wb" );
if ( outStr == NULL) {
fprintf ( stderr, "%s: Can't create output file %s: %s.\n",
progName, outName, strerror(errno) );
- inStr = fopen ( inName, "rb" );
if ( inStr != NULL ) fclose ( inStr );
setExit(1);
return;
@@ -1367,13 +1367,10 @@
}
# if CAPSICUM
- fprintf(stderr,"infd: %d\n", fileno(inStr));
infd = fileno(inStr);
- fprintf(stderr,"infd: %d\n", infd);
outfd = fileno(outStr);
- fprintf(stderr,"outfd: %d\n", outfd);
- /*cap_rights_limit(infd, CAP_READ);*/
- /*cap_rights_limit(outfd, CAP_WRITE);*/
+ cap_rights_limit(infd, CAP_READ);
+ cap_rights_limit(outfd, CAP_WRITE);
if(fclose(inStr) < 0){
fprintf ( stderr, "%s: Couldn't close inStr: %s.\n",
@@ -1388,14 +1385,18 @@
exit(exitValue);
}
- printf("About to fork()");
+ printf("About to fork()\n");
/* Pass the limited file descriptors with a unix domain socket. */
switch( forkpid = fork() ) {
+ case ( -1 ):
+ fprintf ( stderr, "%s: Couldn't fork: %s.\n", progName, strerror(errno) );
+ setExit(1);
+ exit(exitValue);
+
case ( 0 ):
- sleep(1);
printf("Child\n");
if ((infd = recvfd(sv[1])) <= 0){
- fprintf ( stderr, "%s: Couldn't get fd: %s.\n",
+ fprintf ( stderr, "%s: Couldn't get fd infd: %s.\n",
progName, strerror(errno) );
setExit(1);
exit(exitValue);
@@ -1404,7 +1405,7 @@
inStr = fdopen(infd, "rb");
if ((outfd = recvfd(sv[1])) <= 0){
- fprintf ( stderr, "%s: Couldn't get fd: %s.\n",
+ fprintf ( stderr, "%s: Couldn't get fd outfd: %s.\n",
progName, strerror(errno) );
setExit(1);
exit(exitValue);
@@ -1442,15 +1443,20 @@
# if CAPSICUM
break;
- case ( -1 ):
- fprintf ( stderr, "%s: Couldn't fork: %s.\n", progName, strerror(errno) );
- setExit(1);
- exit(exitValue);
-
default:
- sendfd(sv[0], infd);
- sendfd(sv[0], outfd);
- printf("Waiting\n");
+ printf("infd:%d, outfd:%d\n", infd, outfd);
+ if (sendfd(sv[0], infd) < 0){
+ fprintf ( stderr, "%s: Couldn't send fd infd: %s.\n",
+ progName, strerror(errno) );
+ setExit(1);
+ exit(exitValue);
+ }
+ if (sendfd(sv[0], outfd) < 0){
+ fprintf ( stderr, "%s: Couldn't send fd outfd: %s.\n",
+ progName, strerror(errno) );
+ setExit(1);
+ exit(exitValue);
+ }
wait(0);
return;
}
@@ -2105,6 +2111,17 @@
# endif
}
+# if CAPSICUM
+
+ if ( socketpair(PF_LOCAL, SOCK_STREAM, 0, sv) < 0 ){
+ fprintf (stderr, "%s: Can't create socket: %s.\n",
+ progName, strerror(errno) );
+ setExit(1);
+ exit(exitValue);
+ }
+
+# endif
+
if (opMode == OM_Z) {
if (srcMode == SM_I2O) {
compress ( NULL );
More information about the svn-soc-all
mailing list