Fixing install (Was: Re: [Fwd: How To Recover From Missing /lib/libc.so.7?])

Mel Flynn mel.flynn+fbsd.current at mailing.thruhere.net
Sat Aug 8 00:03:02 UTC 2009


On Friday 07 August 2009 11:14:54 Ed Schouten wrote:
> * Ed Schouten <ed at 80386.nl> wrote:
> > * Chris Ruiz <yr.retarded at gmail.com> wrote:
> > > You must specify NO_FSCHG= when you installworld on an unupgraded ZFS
> > > filesystem, otherwise you will lose libc.so.7!  I'll spare you the
> > > details on why this happens.
> >
> > Which is because our install(1) is stupid enough to delete the resulting
> > binary if it can't add the schg flag. We should really change this
> > behaviour.
>
> It looks like there are actually two bugs:
>
> - install(1) does check for EOPNOTSUPP, while ZFS seems to return
>   EINVAL. This is probably a ZFS bug.
> - Inside jails, (un)setting schg is not permitted and returns EPERM. We
>   should change the VFS to return EOPNOTSUPP or install(1) to allow
>   EPERM as well.
>
> It's a bit late, but I think it would be nice to have this fixed before
> 8.0.

Perhaps the second case only if jailed? EPERM is also given when the running 
user doesn't have permission and I'd rather have things bail out sooner then 
later. Patch attached for this.
-- 
Mel
-------------- next part --------------
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 <sys/param.h>
+#include <sys/types.h>
+#include <sys/sysctl.h>
 #include <sys/mman.h>
 #include <sys/mount.h>
 #include <sys/stat.h>
@@ -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);


More information about the freebsd-current mailing list