mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 00:41:02 +00:00
fix exception for bad launch path
This commit is contained in:
parent
46c5917d5f
commit
83e67957bc
2 changed files with 33 additions and 30 deletions
|
@ -3,6 +3,7 @@
|
|||
* Source/NSTask.m: bugfix for testing a running task ... the task may
|
||||
still be running after a -terminate has been sent to it, until we have
|
||||
been able to check for the termination status of the actual subprocess.
|
||||
Fix for exception raised during launching.
|
||||
|
||||
2025-02-28 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
|
|
|
@ -222,7 +222,6 @@ pty_slave(const char* name)
|
|||
#endif
|
||||
|
||||
@interface NSTask (Private)
|
||||
- (NSString *) _fullLaunchPath;
|
||||
- (void) _collectChild;
|
||||
- (void) _notifyOfTermination;
|
||||
- (void) _terminatedChild: (int)status reason: (NSTaskTerminationReason)reason;
|
||||
|
@ -926,19 +925,20 @@ pty_slave(const char* name)
|
|||
- (BOOL) launchAndReturnError: (NSError **)error
|
||||
{
|
||||
NSFileManager *mgr = [NSFileManager defaultManager];
|
||||
NSString *cwd;
|
||||
NSDictionary *info;
|
||||
NSString *path;
|
||||
BOOL ok;
|
||||
|
||||
ASSIGN(_launchingThread, [NSThread currentThread]);
|
||||
|
||||
cwd = [self currentDirectoryPath];
|
||||
if (NO == [mgr fileExistsAtPath: cwd isDirectory: &ok])
|
||||
path = [self currentDirectoryPath];
|
||||
if (NO == [mgr fileExistsAtPath: path isDirectory: &ok])
|
||||
{
|
||||
if (error)
|
||||
{
|
||||
NSDictionary *info = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
@"does not exist", NSLocalizedDescriptionKey,
|
||||
cwd, NSFilePathErrorKey,
|
||||
path, NSFilePathErrorKey,
|
||||
nil];
|
||||
*error = [NSError errorWithDomain: NSCocoaErrorDomain
|
||||
code: NSFileNoSuchFileError
|
||||
|
@ -951,25 +951,46 @@ pty_slave(const char* name)
|
|||
if (error)
|
||||
{
|
||||
*error = [NSError _systemError: ENOTDIR];
|
||||
[*error _setObject: cwd forKey: NSFilePathErrorKey];
|
||||
[*error _setObject: path forKey: NSFilePathErrorKey];
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
if (NO == [mgr isExecutableFileAtPath: cwd])
|
||||
if (NO == [mgr isExecutableFileAtPath: path])
|
||||
{
|
||||
if (error)
|
||||
{
|
||||
*error = [NSError _systemError: EACCES];
|
||||
[*error _setObject: cwd forKey: NSFilePathErrorKey];
|
||||
[*error _setObject: path forKey: NSFilePathErrorKey];
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
if (nil == _launchPath)
|
||||
{
|
||||
info = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
@"task has no launch path set", NSLocalizedDescriptionKey, nil];
|
||||
*error = [NSError errorWithDomain: NSCocoaErrorDomain
|
||||
code: 0
|
||||
userInfo: info];
|
||||
return NO;
|
||||
}
|
||||
if (nil == (path = [self validatedLaunchPath]))
|
||||
{
|
||||
info = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
@"task has invalid launch path", NSLocalizedDescriptionKey,
|
||||
_launchPath, NSFilePathErrorKey,
|
||||
nil];
|
||||
*error = [NSError errorWithDomain: NSCocoaErrorDomain
|
||||
code: 0
|
||||
userInfo: info];
|
||||
return NO;
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (NSURL *) executableURL
|
||||
{
|
||||
return [NSURL URLWithString: [self launchPath]];;
|
||||
return [NSURL URLWithString: [self launchPath]];
|
||||
}
|
||||
|
||||
- (void) setExecutableURL: (NSURL *)url
|
||||
|
@ -990,25 +1011,6 @@ pty_slave(const char* name)
|
|||
|
||||
@implementation NSTask (Private)
|
||||
|
||||
- (NSString *) _fullLaunchPath
|
||||
{
|
||||
NSString *val;
|
||||
|
||||
if (_launchPath == nil)
|
||||
{
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"NSTask - no launch path set"];
|
||||
}
|
||||
val = [self validatedLaunchPath];
|
||||
if (val == nil)
|
||||
{
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"NSTask - launch path (%@) not valid", _launchPath];
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
- (void) _collectChild
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
|
@ -1283,7 +1285,7 @@ quotedFromString(NSString *aString)
|
|||
return NO;
|
||||
}
|
||||
|
||||
lpath = [self _fullLaunchPath];
|
||||
lpath = [self validatedLaunchPath];
|
||||
wexecutable = (const unichar*)[lpath fileSystemRepresentation];
|
||||
|
||||
args = [[NSMutableString alloc] initWithString: quotedFromString(lpath)];
|
||||
|
@ -1629,7 +1631,7 @@ GSPrivateCheckTasks()
|
|||
return NO;
|
||||
}
|
||||
|
||||
lpath = [self _fullLaunchPath];
|
||||
lpath = [self validatedLaunchPath];
|
||||
executable = [lpath fileSystemRepresentation];
|
||||
args[0] = executable;
|
||||
|
||||
|
|
Loading…
Reference in a new issue