Re: Runtime detection of EA support
Denis Corbin <[email protected]> Wed, 04 Jul 2007 18:48:15 +0200
| Newsgroups | gmane.comp.sysutils.backup.dar.general |
|---|---|
| Message-ID | <[email protected]> |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Dave Vasilevsky wrote:
> Hi,
Hello Dave,
>
> I've been distributing binaries of dar for Mac OS X[1], and there's
> an annoying problem: I have to distribute two versions. One version
> supports extended attributes but only runs on new versions of OS X.
> The second version can run on old versions but doesn't support EAs.
> It occurred to me that this problem could be fixed by building with
> compile-time EA support, but dynamically checking for getxattr/
> setxattr/etc at runtime--if they're not present, then dar can turn
> off EA support.
>
> This is certainly useful for OS X, since one binary will work on
> every system. It's only a little useful on Linux. I imagine that if
> somebody uses dar with compile-time EA support on an old version of
> Linux without EA support, they'll get an error. Probably a link error
> if dar links dynamically to libattr; or ENOSYS for the missing
> syscall if they build dar statically. Both of these conditions could
> be avoided if we load libattr at runtime. Then we can give a sensible
> error message on failure, and after that we can stop trying to call
> the xattr functions over and over, since we know they will fail.
>
> The simplest way to do this is to change all the '#ifdef EA_SUPPORT'
> into a runtime check, eg:
>
> if (have_ea_support()) {
> read_ea(name, val, filter);
> } else {
> val.clear();
> }
>
> When we're using runtime detection, have_ea_support() will do the
> platform-specific checking for support, and loading any needed libs.
> If runtime detection is disabled, we can just turn have_ea_support()
> into a teeny inline function[2], which GCC should optimize out.
>
>
> Does this sound like a good idea? Any comments? I'll be glad to do
> most of the implementation. I'm not sure if my computer supports
> older versions of Linux without EA support, so I may need help
> testing for that case.
My first concern is portability. Dar does not only work under Linux and
MacOS, but also under Windows, Solaris, FreeBSD, NetBSD, AIX and several
other unixes. I am not aware of a portable way to dynamically load a
library at execution time once the process has been ran. Yes, so far dar
supports dynamic linking in a portable manner thanks to libtool (i.e.:
linking is done at the time of the execution before the process start
its execution, and the linking must succeed for the process to exist).
My second concern is that even under Linux, I don't known how to make
such an on-fly dynamic linking with a third party library. I guess this
is not possible, as a process cannot modify its own code segment (?).
>
> Dave
>
>
> [1] http://vasi.dyndns.org:3128/files/ports/dar/
> [2] Eg: inline static bool have_ea_support() { return true; }
>
Regards,
Denis.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFGi89PpC5CI8gYGlIRAhT9AKDCgav/HEMaS5a/wWN9YkFIARAwIgCgvJ4r
FkZvzVl5t9N3El9Mr4oslB4=
=kOaV
-----END PGP SIGNATURE-----
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/