On Tue, Aug 28, 2012 at 4:44 AM, Roland Mainz <roland.ma...@nrubsig.org> wrote:
> Attached (as "astksh_fs_at_emulation003.diff.txt") is the 3rd
> prototype patch which adds a POSIX |*at()|-emulation (e.g.
> |openat()|&&co.) to libast. This is mainly the same patch as the
> "astksh_fs_at_emulation002.diff.txt" with minor fixes so that all
> three compile modes { native OS |*at()|, |*at()|-emulation using
> /dev/fd/, |*at()|-emulation using |fchdir()| } work properly
> Notes:
> - Tested with ast-@(ksh|open).2012-08-24
> - The code will currently only work on 64bit plattforms since it
> assumes |stat()|&co. == |stat64()|&co.
> - The emulation #defines calls like |stat()|&co. to |fstatat()|&co.
> and then calls the matching |ast_stat()|&co. emulation. This was done
> to test the emulation and emulation overhead... to use a platform's
> native |*at()|-calls remove |#define AST_TEST_AT_EMULATION 1| from
> src/lib/libast/features/fcntl.c
> - Currently |openat()| itself is not emulated... I didn't find a
> usefull way to #define |openat()| to |ast_openat()| with CPP using the
> full arguments in the CPP macro (the problem is that |open()| and
> |openat()| are varargs functions... they may take a |mode_t|
> argument... or not). Any tips how to fix that very welcome
> - |utimesat()| emulation is now included... but not used (yet)
> - some applications _may_ fail if they do something like #define
> fchdir() or #define chdir() ... these functions or cpp macros MUST
> redirect to |ast_fchdir()|, |ast_chdir()| and |ast_close()| since the
> |*at()|-emulation "remembers" the last fd used to do some
> optimisations. If
> |ast_fchdir()|, |ast_chdir()| and |ast_close()| are bypassed then this
> "remembered" fd is likely "stale" and might cause subtle failures.
> This is not a bug.
> - libshell uses the libshell's |Shell_t->pwdfd| directory handle via
> |#define AST_AT_GET_FDCWD (shp->pwdfd)| in
> src/cmd/ksh93/include/defs.h ... note that this had to be overridden
> in src/cmd/ksh93/bltins/test.c, src/cmd/ksh93/edit/history.c,
> src/cmd/ksh93/sh/io.c and src/cmd/ksh93/sh/nvtype.c because there are
> functions which use file APIs without having a variable |shp| pointing
> to the |Shell_t|
> ToDo:
> - Add proper headers instead of stuffing everything into fcntl.c
> - Code cleanup
> - Add |readlinkat()| and |symlinkat()| (yeah yeah, I missed that...
> sorry... ;-( )
> - Add emulation mode selection: Either use native |*at()| API or {
> /dev/fd/, /proc/self/fd/ or use |fchdir()| } (in that order)
> - Feedback from Glenn whether he likes it
> - Fix src/cmd/ksh93/ to have a |shp| in every function which uses file APIs

I will have a closer look at the emulation next week. IMO it'll be
nice if you could provide the missing emulations (symlinkat,
readlinkat) and make sure that you define your own AT_FDCWD if the
system doesn't have one. We may want to talk about the license too
(preferably one which is compatible to Eclipse1.0, 2-clause BSD and
GPL/LGPL), because the code is very useful for many other projects out
there. The only other emulation-like API for f*at() is in GNU
coreutils and their code is neither very clean nor has it a suitable
license (GPL3.0) for anything except GPL3.0.

ast-developers mailing list

Reply via email to