Index: usr.bin/xinstall/xinstall.c =================================================================== --- usr.bin/xinstall/xinstall.c (revision 196085) +++ usr.bin/xinstall/xinstall.c (working copy) @@ -47,6 +47,8 @@ __FBSDID("$FreeBSD$"); #include +#include +#include #include #include #include @@ -83,6 +85,7 @@ gid_t gid; uid_t uid; int dobackup, docompare, dodir, dopreserve, dostrip, nommap, safecopy, verbose; +int is_jailed; mode_t mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; const char *suffix = BACKUP_SUFFIX; @@ -106,9 +109,11 @@ int ch, no_target; u_int iflags; char *flags; + size_t len = sizeof(int); const char *group, *owner, *to_name; iflags = 0; + is_jailed = 0; group = owner = NULL; while ((ch = getopt(argc, argv, "B:bCcdf:g:Mm:o:pSsv")) != -1) switch((char)ch) { @@ -242,6 +247,11 @@ errx(EX_USAGE, "%s and %s are the same file", *argv, to_name); } + if( sysctlbyname("security.jail.jailed", (void *)&is_jailed, + &len, NULL, 0) == -1 ) { + warn("Unable to get security.jail.jailed, assuming unjailed"); + is_jailed = 0; + } install(*argv, to_name, fset, iflags); exit(EX_OK); /* NOTREACHED */ @@ -506,6 +516,8 @@ if (flags & SETFLAGS) { if (errno == EOPNOTSUPP) warn("%s: chflags", to_name); + else if( errno == EPERM && is_jailed ) + warn("%s: chflags", to_name); else { serrno = errno; (void)unlink(to_name);