* sysdeps/mach/hurd/dl-origin.c (_dl_get_origin): Use _hurd_init_filename if LD_ORIGIN_PATH is not defined. --- sysdeps/mach/hurd/dl-origin.c | 33 +++++++++++++++++++++++++++++---- 1 files changed, 29 insertions(+), 4 deletions(-)
diff --git a/sysdeps/mach/hurd/dl-origin.c b/sysdeps/mach/hurd/dl-origin.c index 8761937..bd5bc64 100644 --- a/sysdeps/mach/hurd/dl-origin.c +++ b/sysdeps/mach/hurd/dl-origin.c @@ -13,39 +13,64 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with the GNU C Library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ #include <stdlib.h> #include <string.h> #include <sys/param.h> #include <ldsodefs.h> +#include <hurd.h> #include <dl-dst.h> const char * _dl_get_origin (void) { char *result = (char *) -1; - /* We use the environment variable LD_ORIGIN_PATH. If it is set make - a copy and strip out trailing slashes. */ + const char *src = NULL; + size_t len; + + /* We use either the file name retreived from the exec server at + startup, or the environment variable LD_ORIGIN_PATH (which takes + precedence). */ if (GLRO(dl_origin_path) != NULL) { - size_t len = strlen (GLRO(dl_origin_path)); + src = GLRO(dl_origin_path); + len = strlen (src); + } + else if (_hurd_init_filename[0] != '\0') + { + char *end = strrchr(_hurd_init_filename, '/'); + if (end != NULL) + { + src = _hurd_init_filename; + len = end - src; + } + else + { + src = "."; + len = 1; + } + } + + /* If one of them is set, make a copy and strip out trailing slashes. */ + if (src != NULL) + { result = (char *) malloc (len + 1); if (result == NULL) result = (char *) -1; else { - char *cp = __mempcpy (result, GLRO(dl_origin_path), len); + char *cp = __mempcpy (result, src, len); while (cp > result + 1 && cp[-1] == '/') --cp; *cp = '\0'; } } return result; } -- 1.7.5.4