Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 22 Jan 2012 21:45:10 +0100
From:      Jilles Tjoelker <jilles@stack.nl>
To:        cliftonr@volcano.org
Cc:        freebsd-stable@freebsd.org
Subject:   Re: GENERIC make buildkernel error / fails - posix_fadvise
Message-ID:  <20120122204510.GA33235@stack.nl>
In-Reply-To: <74dee0a775b93db4771f4de96eaf86c2@volcano.org>
References:  <20120111161110.4258969c.rpclark@tds.net> <CAN-pd=cPY=Eg1RintaBx6GAon3FsLm-X0h6yvSBxzq=EZ5ukbg@mail.gmail.com> <20120112200843.2a348d2f.rpclark@tds.net> <4F0F8E6F.8000909@FreeBSD.org> <74dee0a775b93db4771f4de96eaf86c2@volcano.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, Jan 22, 2012 at 01:00:46PM -0600, cliftonr@volcano.org wrote:
> On 12.01.2012 15:52, Doug Barton wrote:
> >>> chflags -R noschg /usr/obj/usr
> >>> rm -rf /usr/obj/usr

> > It's much faster to do:

> > /bin/rm -rf ${obj}/* 2> /dev/null || /bin/chflags -R 0 ${obj}/* &&
> > /bin/rm -rf ${obj}/*

> If I could just add one thing here, for those who might be tempted
> to immediately cut and paste that elegant command line:

> Consider, how does that command evaluate if the shell variable "obj"
> is not set, and you're running that literal string as root?

> A: You will very systematically wipe your entire server, starting
> at the root, and doing a second pass to get any protected files you
> missed.

> I'd recommend something safer like approximately this (untested):

>    if ["X${obj}" != "X" -a -d ${obj}]; then cd ${obj} && (rest of cmds); 
> fi

> Sorry for the wasted bandwidth, for those to whom it was obvious,
> but anybody who has ever had to clean up after a junior admin's
> attempt to do something a little too clever will appreciate why I'm
> posting this.

An easier way is to replace the first ${obj} with ${obj:?}, causing an
error if obj is unset or null.

One limitation is that it does not work with (t)csh.

> On the efficiency front, for the core file deletion operators, I've
> had good results with this trick (requires Perl and makes use of
> its implicit-operand idioms):

>    find ${obj} | perl -nle unlink

> If rm had an option to take files from standard input, or if
> there's another program I'm not aware of which does this, it
> could serve as the right-hand side of this.

This does not handle all possible characters in filenames, such as a
newline. The perlrun manpage suggests something with find's -print0
primary. Alternatively, use find's -unlink primary.

-- 
Jilles Tjoelker



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20120122204510.GA33235>