On Mon, Apr 11, 2011 at 3:26 PM, Michael Thayer <[email protected]> wrote: > On Mon, 2011-04-11 at 12:08 +0200, Damjan Jovanovic wrote: >> Most *nix applications hardcode their installation prefix at compile >> time, so you'd have to have exactly the same $HOME as the account >> under which an RPM was compiled for that to work. >> >> This is not an issue that can really be fixed portably: argv[0] is >> unreliable, POSIX has no API like GetModuleHandle() and >> GetModulePath() on Windows, /proc/self/exe is Linux-only and can only >> be used for application, while searching the lines in /proc/self/maps >> for an internal symbol is the only method available to a library to >> discover its own path, only works on Linux, and is obscure and unknown >> to the vast majority of developers. > Convention says that argv[0] should point to the executable. If you are > going to modify an application anyway to support runtime prefix > discovery why not just make that a requirement (maybe with a default > path as a fallback) and let it be the caller's problem if they don't set > argv[0] as they should. (Let's not discuss setuid here!) > > Regards, > > Michael
argv[0] doesn't work for libraries and isn't that easy even in non-setuid cases (you need to check for relative paths, then search $PATH, and convert relative paths to absolute). Alternatively why don't we add an API to POSIX for querying your own path? dladdr() already semi-works in special cases (-rdynamic), on OSs where it's available. Damjan _______________________________________________ xdg mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/xdg
