Magic symlinks redux
Luigi Rizzo
rizzo at iet.unipi.it
Fri Aug 22 09:21:59 UTC 2008
On Fri, Aug 22, 2008 at 01:54:29AM +0200, Ivan Voras wrote:
> I was reading about new things in NetBSD, and one thing caught my
> attention: per-user /tmp. See
> http://www.feyrer.de/NetBSD/bx/blosxom.cgi/nb_20080714_0251.html for
> example.
>
> Google says that a discussion about magic symlinks happens every now and
> then in FreeBSD but nothing really gets done. I found this
> implementation which looks like it's for 7.0:
>
> http://butcher.heavennet.ru/patches/kernel/magiclinks/
interestingly simple.
Question - is the process' ENV easily available in this part
of the kernel, so one could in principle use environment variables
as replacement strings ?
Some comments on the code in the above patch:
+ readability it might be improved a bit:
e.g. I don't see why uma_{zalloc|zfree} are hidden behind macros,
nor why symlynk_magic() isn't simply called as
if (vfs_magiclinks)
symlink_magic(td, cp, &linklen);
as it cannot fail as implemented;
also, the whole MATCH/SUBSTITUTE macros are not particularly
readable -- i understand one needs macros to implement sizeof("somestring")
correctly, but apart from a wrapper I believe the core of these two
blocks should be implemented by functions (possibly inline) with
MATCH() returning the match length so one doesn't need to replicate
the string parameter in SUBSTITUTE();
+ correctness --
1. termchar is not reset to '/' if a match is not found
2. what is the intended behaviour when the replacement string overflows
the buffer ?
+ efficiency of symlink_magic() might be improved too:
e.g. the function could do a quick check for the presence of @ and return
without allocation/deallocation if not found;
getcredhostname() (and similar routines) could be called so that
they write directly to tmp, without the need for
allocating an in-stack buffer
cheers
luigi
More information about the freebsd-arch
mailing list