]> git.saurik.com Git - apple/file_cmds.git/blobdiff - install/xinstall.c
file_cmds-251.tar.gz
[apple/file_cmds.git] / install / xinstall.c
index 31e542dcbc88077949aa32d9d03c8f34ab07a62c..05b650093d9ef27c01cd9d38885aa0b3daedf6af 100644 (file)
@@ -31,8 +31,9 @@
  * SUCH DAMAGE.
  */
 
+#include <sys/cdefs.h>
 #ifndef lint
-static const char copyright[] =
+__used static const char copyright[] =
 "@(#) Copyright (c) 1987, 1993\n\
        The Regents of the University of California.  All rights reserved.\n";
 #endif /* not lint */
@@ -41,7 +42,7 @@ static const char copyright[] =
 #if 0
 static char sccsid[] = "From: @(#)xinstall.c   8.1 (Berkeley) 7/21/93";
 #endif
-static const char rcsid[] =
+__used static const char rcsid[] =
   "$FreeBSD: src/usr.bin/xinstall/xinstall.c,v 1.43 2001/05/30 07:08:49 ru Exp $";
 #endif /* not lint */
 
@@ -64,10 +65,12 @@ static const char rcsid[] =
 #include <unistd.h>
 #include <sysexits.h>
 #include <utime.h>
+#include <spawn.h>
 
 #ifdef __APPLE__
+#include <TargetConditionals.h>
 #include <copyfile.h>
-#endif
+#endif /* __APPLE__ */
 
 #include "pathnames.h"
 
@@ -107,7 +110,7 @@ main(argc, argv)
 {
        struct stat from_sb, to_sb;
        mode_t *set;
-       u_long fset;
+       u_long fset = 0;
        int ch, no_target;
        u_int iflags;
        char *flags, *group, *owner, *to_name;
@@ -442,6 +445,13 @@ install(from_name, to_name, fset, flags)
                        err(EX_OSERR, "%s", to_name);
        }
 
+#ifdef __APPLE__
+       /* in case mtime is modified */
+       if (!devnull && (S_ISLNK(from_sb.st_mode) || S_ISREG(from_sb.st_mode)) &&
+           fcopyfile(from_fd, to_fd, NULL, COPYFILE_XATTR) < 0) {
+               warn("%s: unable to copy extended attributes from %s", to_name, from_name);
+       }
+#endif /* __APPLE__ */
        /*
         * Preserve the timestamp of the source file if necessary.
         */
@@ -490,14 +500,14 @@ install(from_name, to_name, fset, flags)
        /*
         * If provided a set of flags, set them, otherwise, preserve the
         * flags, except for the dump flag.
-        * NFS does not support flags.  Ignore EOPNOTSUPP flags if we're just
+        * NFS does not support flags.  Ignore ENOTSUP flags if we're just
         * trying to turn off UF_NODUMP.  If we're trying to set real flags,
         * then warn if the the fs doesn't support it, otherwise fail.
         */
        if (!devnull && fchflags(to_fd,
            flags & SETFLAGS ? fset : from_sb.st_flags & ~UF_NODUMP)) {
                if (flags & SETFLAGS) {
-                       if (errno == EOPNOTSUPP)
+                       if (errno == ENOTSUP)
                                warn("%s: chflags", to_name);
                        else {
                                serrno = errno;
@@ -507,21 +517,23 @@ install(from_name, to_name, fset, flags)
                        }
                }
        }
-
-#if __APPLE__
-       {
-           if (copyfile(from_name, to_name, NULL, COPYFILE_ACL | COPYFILE_XATTR) < 0)
-           {
-               warn("%s: copyfile", to_name);
-           }
+#ifdef __APPLE__
+       /* the ACL could prevent credential/permission system calls later on... */
+       if (!devnull && (S_ISLNK(from_sb.st_mode) || S_ISREG(from_sb.st_mode)) &&
+           (fcopyfile(from_fd, to_fd, NULL, COPYFILE_ACL) < 0)) {
+               warn("%s: unable to copy ACL from %s", to_name, from_name);
        }
-#endif
+#endif /* __APPLE__ */
 
        (void)close(to_fd);
        if (!devnull)
                (void)close(from_fd);
 }
-
+#if TARGET_OS_EMBEDDED
+#define BUFFER_SIZE 128*1024
+#else  /* !TARGET_OS_EMBEDDED */
+#define BUFFER_SIZE MAXBSIZE
+#endif /* TARGET_OS_EMBEDDED */
 /*
  * compare --
  *     compare two files; non-zero means files differ
@@ -557,8 +569,8 @@ compare(int from_fd, const char *from_name, size_t from_len,
                }
        out:
                if (!done_compare) {
-                       char buf1[MAXBSIZE];
-                       char buf2[MAXBSIZE];
+                       char buf1[BUFFER_SIZE];
+                       char buf2[BUFFER_SIZE];
                        int n1, n2;
 
                        rv = 0;
@@ -661,7 +673,7 @@ copy(from_fd, from_name, to_fd, to_name, size)
 {
        register int nr, nw;
        int serrno;
-       char *p, buf[MAXBSIZE];
+       char *p, buf[BUFFER_SIZE];
        int done_copy;
 
        /* Rewind file descriptors. */
@@ -712,23 +724,21 @@ void
 strip(to_name)
        char *to_name;
 {
-       int serrno, status;
-
-       switch (fork()) {
-       case -1:
-               serrno = errno;
-               (void)unlink(to_name);
-               errno = serrno;
-               err(EX_TEMPFAIL, "fork");
-       case 0:
-               execlp("strip", "strip", to_name, NULL);
-               err(EX_OSERR, "exec(strip)");
-       default:
-               if (wait(&status) == -1 || status) {
-                       (void)unlink(to_name);
-                       exit(EX_SOFTWARE);
-                       /* NOTREACHED */
+       pid_t pid;
+       int error;
+       extern char** environ;
+       char *const argv[] = { "xcrun", "strip", "-", to_name, NULL };
+       
+       if (0 == (error = posix_spawnp(&pid, "xcrun", NULL, NULL, argv, environ))) {
+               int status = 0;
+               pid_t child = waitpid(pid, &status, 0);
+               if ((child == -1) || status) {
+                       unlink(to_name);
+                       errx(EX_SOFTWARE, "child process failed: xcrun strip - %s", to_name);
                }
+       } else {
+               errno = error;
+               err(EX_OSERR, "xcrun strip - %s", to_name);
        }
 }