From owner-freebsd-arch@FreeBSD.ORG Fri Aug 22 09:21:59 2008 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9890B1065688; Fri, 22 Aug 2008 09:21:59 +0000 (UTC) (envelope-from luigi@onelab2.iet.unipi.it) Received: from onelab2.iet.unipi.it (onelab2.iet.unipi.it [131.114.9.129]) by mx1.freebsd.org (Postfix) with ESMTP id 5C7D68FC16; Fri, 22 Aug 2008 09:21:59 +0000 (UTC) (envelope-from luigi@onelab2.iet.unipi.it) Received: by onelab2.iet.unipi.it (Postfix, from userid 275) id 055937308B; Fri, 22 Aug 2008 11:04:49 +0200 (CEST) Date: Fri, 22 Aug 2008 11:04:49 +0200 From: Luigi Rizzo To: Ivan Voras Message-ID: <20080822090448.GB57441@onelab2.iet.unipi.it> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.3i Cc: freebsd-arch@freebsd.org Subject: Re: Magic symlinks redux X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 22 Aug 2008 09:21:59 -0000 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