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

dpl at FreeBSD.org dpl at FreeBSD.org
Fri Jul 5 22:02:03 UTC 2013


Author: dpl
Date: Fri Jul  5 22:02:02 2013
New Revision: 254192
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=254192

Log:
  Start adapting stat,lstat and utime to be used with fds, fstatat() and futimes()
  

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

Modified: soc2013/dpl/head/contrib/bzip2/bzip2.c
==============================================================================
--- soc2013/dpl/head/contrib/bzip2/bzip2.c	Fri Jul  5 21:41:05 2013	(r254191)
+++ soc2013/dpl/head/contrib/bzip2/bzip2.c	Fri Jul  5 22:02:02 2013	(r254192)
@@ -75,8 +75,9 @@
 #   include <sys/times.h>
 
 #   define PATH_SEP   '/'
-#   define MY_LSTAT   lstat
-#   define MY_STAT    stat
+#   define MY_LSTAT   fstatat
+#   define MY_STAT    fstatat
+#   define MY_STATS    stat
 #   define MY_S_ISREG  S_ISREG
 #   define MY_S_ISDIR  S_ISDIR
 
@@ -223,8 +224,8 @@
 Int32   workFactor;
 
 #if CAPSICUM
-#define IN_FILENO fileno(outStr)
-#define OUT_FILENO fileno(inStr)
+#define IN_FILENO fileno(inStr)
+#define OUT_FILENO fileno(outStr)
 void limitfd(int);
 FILE  *inStr;
 FILE  *outStr;
@@ -678,24 +679,21 @@
 void
 limitfd(int fd)
 {
-   cap_rights_t rights = 0;
+   cap_rights_t rights;
 
-   if (fd == IN_FILENO)
-      rights |= CAP_READ;
-   else if (fd == OUT_FILENO)
-      rights |= CAP_WRITE;
+   if (fd == OUT_FILENO)
+      rights = CAP_READ|CAP_FSTAT|CAP_WRITE|CAP_FCHMOD|CAP_FCHOWN|CAP_FUTIMES;
+   else if (fd == IN_FILENO)
+      rights = CAP_WRITE|CAP_READ|CAP_FSTAT;
    else if (fd == STDERR_FILENO)
-      rights |= CAP_WRITE;
-   else
-      abort();
-/*
+      rights = CAP_WRITE;
+
    if (cap_rights_limit(fd, rights) < 0 && errno != ENOSYS){
       fprintf ( stderr, "%s: Couldn't limit rights for descriptor %d: %s.\n", 
          progName, fd, strerror(errno));
       setExit(1);
       exit(exitValue);
    }
-*/
 }
 #endif
 
@@ -732,7 +730,7 @@
 void cleanUpAndFail ( Int32 ec )
 {
    IntNative     retVal;
-   struct MY_STAT statBuf;
+   struct MY_STATS statBuf;
 
    if ( srcMode == SM_F2F 
       && opMode != OM_TEST
@@ -1023,12 +1021,12 @@
   if in doubt, return True
 --*/
 static 
-Bool notAStandardFile ( Char* name )
+Bool notAStandardFile (int fd )
 {
    IntNative     i;
-   struct MY_STAT statBuf;
+   struct MY_STATS statBuf;
 
-   i = MY_LSTAT ( name, &statBuf );
+   i = MY_LSTAT ( fd, &statBuf );
    if (i != 0) return True;
    if (MY_S_ISREG(statBuf.st_mode)) return False;
    return True;
@@ -1040,12 +1038,12 @@
   rac 11/21/98 see if file has hard links to it
 --*/
 static 
-Int32 countHardLinks ( Char* name )
+Int32 countHardLinks ( int fd )
 {  
    IntNative     i;
    struct MY_STAT statBuf;
 
-   i = MY_LSTAT ( name, &statBuf );
+   i = MY_LSTAT ( fd, &statBuf );
    if (i != 0) return 0;
    return (statBuf.st_nlink - 1);
 }
@@ -1241,7 +1239,7 @@
        return;
      }
    }
-   if ( srcMode == SM_F2F && !forceOverwrite && notAStandardFile ( inName )) {
+   if ( srcMode == SM_F2F && !forceOverwrite && notAStandardFile ( IN_FILENO )) {
      if (noisy)
      fprintf ( stderr, "%s: Input file %s is not a normal file.\n",
             progName, inName );
@@ -1259,7 +1257,7 @@
      }
    }
    if ( srcMode == SM_F2F && !forceOverwrite &&
-      (n=countHardLinks ( inName )) > 0) {
+      (n=countHardLinks ( IN_FILENO )) > 0) {
      fprintf ( stderr, "%s: Input file %s has %d other link%s.\n",
             progName, inName, n, n > 1 ? "s" : "" );
      setExit(1);
@@ -1350,17 +1348,15 @@
       wait(NULL);
       return;
    } else if (forkpid == 0){
-      limitfd(fileno(inStr));
-      limitfd(fileno(outStr));
+      limitfd(IN_FILENO));
+      limitfd(OUT_FILENO);
       limitfd(STDERR_FILENO);
-/*
-      if (cap_enter() < 0){
+      if (cap_enter() < 0 && errno != ENOSYS){
          fprintf ( stderr, "%s: Couldn't enter capability mode: %s.\n", 
             progName, strerror(errno) );
          setExit(1);
          exit(exitValue);
       }
-*/
 #     endif
       /*--- Now the input and output handles are sane.  Do the Biz. ---*/
       outputHandleJustInCase = outStr;
@@ -1451,7 +1447,7 @@
        return;
      }
    }
-   if ( srcMode == SM_F2F && !forceOverwrite && notAStandardFile ( inName )) {
+   if ( srcMode == SM_F2F && !forceOverwrite && notAStandardFile ( IN_FILENO )) {
      if (noisy)
      fprintf ( stderr, "%s: Input file %s is not a normal file.\n",
             progName, inName );
@@ -1476,7 +1472,7 @@
      }
    }
    if ( srcMode == SM_F2F && !forceOverwrite &&
-      (n=countHardLinks ( inName ) ) > 0) {
+      (n=countHardLinks ( IN_FILENO ) ) > 0) {
      fprintf ( stderr, "%s: Input file %s has %d other link%s.\n",
             progName, inName, n, n > 1 ? "s" : "" );
      setExit(1);
@@ -1559,17 +1555,16 @@
       wait(NULL);
       return;
    } else if (forkpid == 0){
-      limitfd(fileno(inStr));
-      limitfd(fileno(outStr));
+      limitfd(IN_FILENO);
+      limitfd(OUT_FILENO);
       limitfd(STDERR_FILENO);
-/*
-      if (cap_enter() < 0){
+      if (cap_enter() < 0 && errno != ENOSYS){
          fprintf ( stderr, "%s: Couldn't enter capability mode: %s.\n", 
             progName, strerror(errno) );
          setExit(1);
          exit(exitValue);
+
       }
-*/
 #     endif
       /*--- Now the input and output handles are sane.  Do the Biz. ---*/
       outputHandleJustInCase = outStr;


More information about the svn-soc-all mailing list