Attached is a patch for the current sane-backends git, which fixes several problems with the handling of the SANE_CONFIG_DIR environment variable. In particular, the problems were:
-) backends/dll.c did not use SANE_CONFIG_DIR at all when searching for dll.d/, but always only looked at the $prefix/etc/sane.d/dll.d/ path (i.e. PATH_SANE_CONFIG_DIR as used in the ./configure call). This made development of third-party backends quite cumbersome, if you also needed a working global installation without your not-yet-working backend. In particular, you could not have your own configuration to test just one backend, as the global dll.d/ directory was used no matter what. The only solution was to install a complete sane-backends to the same prefix as your third-party backend. -) in sanei/sane_config.c there was code like: static const char *dir_list; FILE * sanei_config_open (const char *filename) { char result[PATH_MAX]; [...] if (!dir_list) { [...] dir_list = result; } /* use dir_list */ [...] } Of course, on the next call to sanei_config_open, dir_list will still be set to something non-NULL, but point to the invalid "result" local variable of the previous call. Similar problems happened with dir_list = getenv ("SANE_CONFIG_DIR"); which was also later pointing to an invalid string... In all these cases, of course a strdup was missing. The attached patch fixes those and also adds a function sanei_config_get_paths to obtain all configuration pathes (from env var SANE_CONFIG_DIR and default paths). Since that functionality is needed in sanei/sane_config.c as well as in backend/dll.c, I figured I could just create one public helper function to return the same config pathes for all use cases... Although sanei_config_get_paths should never return NULL (except when it runs out of memory), I still check the returned pointer whenever it's called. What's the stance of the sane project on such cases? Shall one always check the return value, or assume it is valid, because when out of memory the application will crash anyway? The git commit msg: Fix SANE_CONFIG_DIR handling, use it for dll.d/; Add sanei_config_get_paths * include/sane/sanei_config.h sanei/sanei_config.c: Add function sanei_config_get_paths to obtain all configuration pathes (from env var SANE_CONFIG_DIR and default paths); fix pointers to invalid/freed strings when SANE_CONFIG_DIR is set * backend/dll.c: When searching for the dll.d/ directory, also use the SANE_CONFIG_DIR env variable. Cheers, Reinhold -- ------------------------------------------------------------------ Reinhold Kainhofer, reinhold at kainhofer.com, http://reinhold.kainhofer.com/ * Financial & Actuarial Math., Vienna Univ. of Technology, Austria * http://www.fam.tuwien.ac.at/, DVR: 0005886 * LilyPond, Music typesetting, http://www.lilypond.org -------------- next part -------------- A non-text attachment was scrubbed... Name: 0001-Fix-SANE_CONFIG_DIR-handling-use-it-for-dll.d-Add-sa.patch Type: text/x-patch Size: 7096 bytes Desc: not available URL: <http://lists.alioth.debian.org/pipermail/sane-devel/attachments/20100903/5acca3ca/attachment.bin>