* 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 */
#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 */
#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"
{
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;
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.
*/
/*
* 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;
}
}
}
-
-#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
}
out:
if (!done_compare) {
- char buf1[MAXBSIZE];
- char buf2[MAXBSIZE];
+ char buf1[BUFFER_SIZE];
+ char buf2[BUFFER_SIZE];
int n1, n2;
rv = 0;
{
register int nr, nw;
int serrno;
- char *p, buf[MAXBSIZE];
+ char *p, buf[BUFFER_SIZE];
int done_copy;
/* Rewind file descriptors. */
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);
}
}