mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 00:41:02 +00:00
A few NSBundle bugfixes and workaround for problem with using the pth
library in gdnc. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@20367 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
92d9bd4651
commit
ddc3ee78c2
3 changed files with 68 additions and 41 deletions
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,13 @@
|
|||
2004-11-20 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/NSBundle.m: Fix to ensure that a main bundle exists.
|
||||
Fix to get -executablePath for the main bundle to return the
|
||||
path to the executable.
|
||||
* Tools/gdnc.m: In order to avoid problems on BSD when using the pth
|
||||
library to do threading, we need to fork, close descriptors, and
|
||||
then exec the program again, since closing descriptors messes up
|
||||
the threading library.
|
||||
|
||||
2004-11-19 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Tools/pl.m: Make code conform to gnu coding standards.
|
||||
|
|
|
@ -852,8 +852,9 @@ _bundle_load_callback(Class theClass, struct objc_category *theCategory)
|
|||
the _mainBundle. Please note that we do *not* autorelease
|
||||
mainBundle, because we don't want it to be ever released. */
|
||||
_mainBundle = [self alloc];
|
||||
/* Please note that _mainBundle can perfectly well be nil. */
|
||||
_mainBundle = [_mainBundle initWithPath:path];
|
||||
/* Please note that _mainBundle should *not* be nil. */
|
||||
_mainBundle = [_mainBundle initWithPath: path];
|
||||
NSAssert(_mainBundle != nil, NSInternalInconsistencyException);
|
||||
}
|
||||
|
||||
[load_lock unlock];
|
||||
|
@ -912,7 +913,7 @@ _bundle_load_callback(Class theClass, struct objc_category *theCategory)
|
|||
|
||||
- (id) initWithPath: (NSString*)path
|
||||
{
|
||||
[super init];
|
||||
self = [super init];
|
||||
|
||||
if (!path || [path length] == 0)
|
||||
{
|
||||
|
@ -945,8 +946,12 @@ _bundle_load_callback(Class theClass, struct objc_category *theCategory)
|
|||
if (bundle_directory_readable(path) == NO)
|
||||
{
|
||||
NSDebugMLLog(@"NSBundle", @"Could not access path %@ for bundle", path);
|
||||
[self dealloc];
|
||||
return nil;
|
||||
// if this is not the main bundle ... deallocate and return.
|
||||
if (self != _mainBundle)
|
||||
{
|
||||
[self dealloc];
|
||||
return nil;
|
||||
}
|
||||
}
|
||||
|
||||
_path = [path copy];
|
||||
|
@ -1553,9 +1558,18 @@ _bundle_load_callback(Class theClass, struct objc_category *theCategory)
|
|||
_strip_after_loading = flag;
|
||||
}
|
||||
|
||||
- (NSString *)executablePath
|
||||
- (NSString *) executablePath
|
||||
{
|
||||
NSString *object, *path;
|
||||
|
||||
if (!_mainBundle)
|
||||
{
|
||||
[NSBundle mainBundle];
|
||||
}
|
||||
if (self == _mainBundle)
|
||||
{
|
||||
return _executable_path;
|
||||
}
|
||||
object = [[self infoDictionary] objectForKey: @"NSExecutable"];
|
||||
if (object == nil || [object length] == 0)
|
||||
{
|
||||
|
|
73
Tools/gdnc.m
73
Tools/gdnc.m
|
@ -1018,7 +1018,7 @@ main(int argc, char** argv, char** env)
|
|||
debugging = YES;
|
||||
}
|
||||
RELEASE(pool);
|
||||
#ifdef __MINGW__
|
||||
|
||||
if (shouldFork)
|
||||
{
|
||||
char **a = malloc((argc+2) * sizeof(char*));
|
||||
|
@ -1026,16 +1026,14 @@ main(int argc, char** argv, char** env)
|
|||
memcpy(a, argv, argc*sizeof(char*));
|
||||
a[argc] = "-f";
|
||||
a[argc+1] = 0;
|
||||
#ifdef __MINGW__
|
||||
if (_spawnv(_P_NOWAIT, argv[0], a) == -1)
|
||||
{
|
||||
fprintf(stderr, "gdnc - spawn failed - bye.\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
#else
|
||||
if (shouldFork)
|
||||
{
|
||||
is_daemon = 1;
|
||||
switch (fork())
|
||||
{
|
||||
|
@ -1057,43 +1055,48 @@ main(int argc, char** argv, char** env)
|
|||
default:
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Ensure we don't have any open file descriptors which may refer
|
||||
* to sockets bound to ports we may try to use.
|
||||
*
|
||||
* Use '/dev/null' for stdin and stdout.
|
||||
*/
|
||||
for (c = 0; c < FD_SETSIZE; c++)
|
||||
{
|
||||
if (is_daemon || (c != 2))
|
||||
/*
|
||||
* Ensure we don't have any open file descriptors which may refer
|
||||
* to sockets bound to ports we may try to use.
|
||||
*
|
||||
* Use '/dev/null' for stdin and stdout.
|
||||
*/
|
||||
for (c = 0; c < FD_SETSIZE; c++)
|
||||
{
|
||||
(void)close(c);
|
||||
if (is_daemon || (c != 2))
|
||||
{
|
||||
(void)close(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (open("/dev/null", O_RDONLY) != 0)
|
||||
{
|
||||
sprintf(ebuf, "failed to open stdin from /dev/null (%s)\n",
|
||||
strerror(errno));
|
||||
if (open("/dev/null", O_RDONLY) != 0)
|
||||
{
|
||||
sprintf(ebuf, "failed to open stdin from /dev/null (%s)\n",
|
||||
strerror(errno));
|
||||
gdnc_log(LOG_CRIT);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (open("/dev/null", O_WRONLY) != 1)
|
||||
{
|
||||
sprintf(ebuf, "failed to open stdout from /dev/null (%s)\n",
|
||||
strerror(errno));
|
||||
gdnc_log(LOG_CRIT);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (is_daemon && open("/dev/null", O_WRONLY) != 2)
|
||||
{
|
||||
sprintf(ebuf, "failed to open stderr from /dev/null (%s)\n",
|
||||
strerror(errno));
|
||||
gdnc_log(LOG_CRIT);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
execve([[[NSBundle mainBundle] executablePath] cString], a, env);
|
||||
sprintf(ebuf, "failed to exec to '%s' (%s)\n",
|
||||
argv[0], strerror(errno));
|
||||
gdnc_log(LOG_CRIT);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (open("/dev/null", O_WRONLY) != 1)
|
||||
{
|
||||
sprintf(ebuf, "failed to open stdout from /dev/null (%s)\n",
|
||||
strerror(errno));
|
||||
gdnc_log(LOG_CRIT);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (is_daemon && open("/dev/null", O_WRONLY) != 2)
|
||||
{
|
||||
sprintf(ebuf, "failed to open stderr from /dev/null (%s)\n",
|
||||
strerror(errno));
|
||||
gdnc_log(LOG_CRIT);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
#endif /* !MINGW */
|
||||
}
|
||||
|
||||
{
|
||||
#if GS_WITH_GC == 0
|
||||
|
|
Loading…
Reference in a new issue