diff --git a/ChangeLog b/ChangeLog index 4e1e8ddce..9ec1a348a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2000-04-18 Adam Fedor + + * base/configure.in: add a test to see whether a symlink + '/proc/self/exe' exists + * base/Headers/gnustep/base/config.h.in: Add a definition for the + test result + * base/Source/NSBundle.m: Move the discovery of the process' + executable file to +initialize; add code to discover it from + /proc, if possible (patches from Jonathan Gapen + ) + 2000-04-18 Richard Frith-Macdonald * Documentation/gsdoc/NSCountedSet.gsdoc: Method descriptions fleshed diff --git a/Headers/gnustep/base/config.h.in b/Headers/gnustep/base/config.h.in index a151fc426..6844a77a8 100644 --- a/Headers/gnustep/base/config.h.in +++ b/Headers/gnustep/base/config.h.in @@ -36,6 +36,9 @@ /* Define if your Lib C defines program_invocation_name */ #undef HAVE_PROGRAM_INVOCATION_NAME +/* Define if your system has a /proc/self/exe symlink to the executable */ +#undef HAVE_PROC_FS_EXE_LINK + /* The number of bytes in a double. */ #undef SIZEOF_DOUBLE diff --git a/Source/NSBundle.m b/Source/NSBundle.m index 1403fba1f..adce3eaa9 100644 --- a/Source/NSBundle.m +++ b/Source/NSBundle.m @@ -73,6 +73,9 @@ typedef enum { static NSBundle* _mainBundle = nil; static NSMapTable* _bundles = NULL; +/* Keep the path to the executable file for finding the main bundle. */ +static NSString *_executable_path; + /* * An empty strings file table for use when localization files can't be found. */ @@ -252,6 +255,7 @@ _bundle_load_callback(Class theClass, Category *theCategory) { NSMutableString *system; NSString *str; + char *output; if ((str = [env objectForKey: @"GNUSTEP_TARGET_DIR"]) != nil) gnustep_target_dir = RETAIN(str); @@ -275,6 +279,18 @@ _bundle_load_callback(Class theClass, Category *theCategory) mutableCopy]); [system appendString: @"/Libraries"]; +#ifdef HAVE_PROC_FS_EXE_LINK + _executable_path = [[NSFileManager defaultManager] + pathContentOfSymbolicLinkAtPath: @"/proc/self/exe"]; +#else + _executable_path = + [[[NSProcessInfo processInfo] arguments] objectAtIndex: 0]; + output = objc_find_executable([_executable_path cString]); + NSAssert(output, NSInternalInconsistencyException); + _executable_path = [NSString stringWithCString: output]; + OBJC_FREE(output); +#endif + _gnustep_bundle = RETAIN([NSBundle bundleWithPath: system]); } } @@ -309,17 +325,10 @@ _bundle_load_callback(Class theClass, Category *theCategory) [load_lock lock]; if ( !_mainBundle ) { - char *output; NSString *path, *s; - path = [[[NSProcessInfo processInfo] arguments] objectAtIndex: 0]; - output = objc_find_executable([path cString]); - NSAssert(output, NSInternalInconsistencyException); - path = [NSString stringWithCString: output]; - OBJC_FREE(output); - /* Strip off the name of the program */ - path = [path stringByDeletingLastPathComponent]; + path = [_executable_path stringByDeletingLastPathComponent]; /* The executable may not lie in the main bundle directory so we need to chop off the extra subdirectories, the library diff --git a/acconfig.h b/acconfig.h index 01f0474e8..54a69d0a1 100644 --- a/acconfig.h +++ b/acconfig.h @@ -126,3 +126,6 @@ /* Define if your Lib C defines program_invocation_name */ #undef HAVE_PROGRAM_INVOCATION_NAME + +/* Define if your system has a /proc/self/exe symlink to the executable */ +#undef HAVE_PROC_FS_EXE_LINK diff --git a/configure b/configure index 880e98e7e..2f2a501f7 100755 --- a/configure +++ b/configure @@ -4163,6 +4163,23 @@ else sys_proc_fs=no; echo "$ac_t""no" 1>&6 fi +# Linux (and others?) /proc contains a symlink to the executable +# file from which the process loaded its code. This can be used +# by NSBundle.m to locate the main bundle. +if test $sys_proc_fs = yes; then + echo $ac_n "checking link to executable in /proc""... $ac_c" 1>&6 +echo "configure:4172: checking link to executable in /proc" >&5 + if test -L /proc/self/exe; then + cat >> confdefs.h <<\EOF +#define HAVE_PROC_FS_EXE_LINK 1 +EOF + + echo "$ac_t""yes" 1>&6 + else + echo "$ac_t""no" 1>&6 + fi +fi + #-------------------------------------------------------------------- # Tools for making a DLL. diff --git a/configure.in b/configure.in index 6ec6b5623..6a6721b24 100644 --- a/configure.in +++ b/configure.in @@ -652,6 +652,19 @@ else sys_proc_fs=no; AC_MSG_RESULT(no) fi +# Linux (and others?) /proc contains a symlink to the executable +# file from which the process loaded its code. This can be used +# by NSBundle.m to locate the main bundle. +if test $sys_proc_fs = yes; then + AC_MSG_CHECKING(link to executable in /proc) + if test -L /proc/self/exe; then + AC_DEFINE(HAVE_PROC_FS_EXE_LINK) + AC_MSG_RESULT(yes) + else + AC_MSG_RESULT(no) + fi +fi + #-------------------------------------------------------------------- # Tools for making a DLL.