Runtime detection of EA support

Dave Vasilevsky <[email protected]> Mon, 2 Jul 2007 16:54:43 -0400
Newsgroups gmane.comp.sysutils.backup.dar.general
Message-ID <[email protected]>
Hi,

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.

Dave


[1] http://vasi.dyndns.org:3128/files/ports/dar/
[2] Eg: inline static bool have_ea_support() { return true; }


-------------------------------------------------------------------------
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/