diff options
Diffstat (limited to 'sysdeps/unix')
-rw-r--r-- | sysdeps/unix/sysv/linux/dl-origin.c | 53 | ||||
-rw-r--r-- | sysdeps/unix/sysv/linux/kernel-features.h | 7 |
2 files changed, 41 insertions, 19 deletions
diff --git a/sysdeps/unix/sysv/linux/dl-origin.c b/sysdeps/unix/sysv/linux/dl-origin.c index a7fa53e..5dacec6 100644 --- a/sysdeps/unix/sysv/linux/dl-origin.c +++ b/sysdeps/unix/sysv/linux/dl-origin.c @@ -1,5 +1,5 @@ /* Find path of executable. - Copyright (C) 1998, 1999, 2000, 2002, 2004 Free Software Foundation, Inc. + Copyright (C) 1998-2000, 2002, 2004, 2008 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998. @@ -35,30 +35,32 @@ const char * _dl_get_origin (void) { +#ifndef __ASSUME_AT_EXECFN char linkval[PATH_MAX]; - char *result; +#endif + char *str; + char *result = (char *) -1l; int len; - INTERNAL_SYSCALL_DECL (err); - len = INTERNAL_SYSCALL (readlink, err, 3, "/proc/self/exe", linkval, - sizeof (linkval)); - if (! INTERNAL_SYSCALL_ERROR_P (len, err) && len > 0 && linkval[0] != '[') + str = GLRO(dl_execfn); +#ifndef __ASSUME_AT_EXECFN + if (str == NULL) { - /* We can use this value. */ - assert (linkval[0] == '/'); - while (len > 1 && linkval[len - 1] != '/') - --len; - result = (char *) malloc (len + 1); - if (result == NULL) - result = (char *) -1; - else if (len == 1) - memcpy (result, "/", 2); - else - *((char *) __mempcpy (result, linkval, len - 1)) = '\0'; + INTERNAL_SYSCALL_DECL (err); + + len = INTERNAL_SYSCALL (readlink, err, 3, "/proc/self/exe", linkval, + sizeof (linkval)); + if (! INTERNAL_SYSCALL_ERROR_P (len, err) + && len > 0 && linkval[0] != '[') + str = linkval; } else +#endif + len = strlen (str); + +#ifndef __ASSUME_AT_EXECFN + if (str == NULL) { - result = (char *) -1; /* We use the environment variable LD_ORIGIN_PATH. If it is set make a copy and strip out trailing slashes. */ if (GLRO(dl_origin_path) != NULL) @@ -76,6 +78,21 @@ _dl_get_origin (void) } } } + else +#endif + { + /* We can use this value. */ + assert (str[0] == '/'); + while (len > 1 && str[len - 1] != '/') + --len; + result = (char *) malloc (len + 1); + if (result == NULL) + result = (char *) -1; + else if (len == 1) + memcpy (result, "/", 2); + else + *((char *) __mempcpy (result, str, len - 1)) = '\0'; + } return result; } diff --git a/sysdeps/unix/sysv/linux/kernel-features.h b/sysdeps/unix/sysv/linux/kernel-features.h index 01baab0..5b41429 100644 --- a/sysdeps/unix/sysv/linux/kernel-features.h +++ b/sysdeps/unix/sysv/linux/kernel-features.h @@ -1,6 +1,6 @@ /* Set flags signalling availability of kernel features based on given kernel version number. - Copyright (C) 1999-2006, 2007 Free Software Foundation, Inc. + Copyright (C) 1999-2006, 2007, 2008 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -492,3 +492,8 @@ #if __LINUX_KERNEL_VERSION >= 0x020618 # define __ASSUME_ADJ_OFFSET_SS_READ 1 #endif + +/* Support for AT_EXECFN was added in 2.6.27. */ +#if __LINUX_KERNEL_VERSION >= 0x02061b +# define __ASSUME_AT_EXECFN 1 +#endif |