mainBundle patch fix

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@6482 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Adam Fedor 2000-04-18 21:34:59 +00:00
parent 83f27a1170
commit c5fb445c87
6 changed files with 64 additions and 8 deletions

View file

@ -1,3 +1,14 @@
2000-04-18 Adam Fedor <fedor@gnu.org>
* 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
<jagapen@whitewater.chem.wisc.edu>)
2000-04-18 Richard Frith-Macdonald <rfm@gnu.org>
* Documentation/gsdoc/NSCountedSet.gsdoc: Method descriptions fleshed

View file

@ -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

View file

@ -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

View file

@ -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

17
configure vendored
View file

@ -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.

View file

@ -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.