mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 09:04:13 +00:00
Generally improved launching of programs.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@4076 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
a7f9d28f0d
commit
05f1223db3
6 changed files with 156 additions and 47 deletions
15
ChangeLog
15
ChangeLog
|
@ -1,7 +1,18 @@
|
|||
Wed Apr 14 9:10:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||
Wed Apr 14 10:50:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||
|
||||
* Source/NSBundle: ([+allBundles]) implemented (ignoring the frameworks
|
||||
issue).
|
||||
issue). Extra internal GNUstep specific methods provided -
|
||||
([+_gnustep_target_cpu]), ([+_gnustep_target_dir])
|
||||
([+_gnustep_target_os]), ([+_library_combo])
|
||||
So that we can easily determine wrapper path information.
|
||||
* Source/NSTaks: Preparation for garbage collecting.
|
||||
Major work on launching - now makes intelligent use of launch path.
|
||||
Tries various GNUstep directories - if unable to find executable
|
||||
that way, resorts to using the unix PATH environment variable.
|
||||
* Source/NSPortNameServer.m: Removed a couple of unix specific calls.
|
||||
* Source/NSDistributedNotificationCenter.m: Removed a couple of unix
|
||||
specific calls.
|
||||
* Tools/Makefile.postamble: Install gdnc in non-library specific dir.
|
||||
|
||||
Tue Apr 13 22:05:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||
|
||||
|
|
|
@ -919,4 +919,25 @@ _bundle_load_callback(Class theClass, Category *theCategory)
|
|||
return nil;
|
||||
}
|
||||
|
||||
+ (NSString*) _gnustep_target_cpu
|
||||
{
|
||||
return gnustep_target_cpu;
|
||||
}
|
||||
|
||||
+ (NSString*) _gnustep_target_dir
|
||||
{
|
||||
return gnustep_target_dir;
|
||||
}
|
||||
|
||||
+ (NSString*) _gnustep_target_os
|
||||
{
|
||||
return gnustep_target_os;
|
||||
}
|
||||
|
||||
+ (NSString*) _library_combo
|
||||
{
|
||||
return library_combo;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -28,6 +28,9 @@
|
|||
#include <Foundation/NSException.h>
|
||||
#include <Foundation/NSArchiver.h>
|
||||
#include <Foundation/NSNotification.h>
|
||||
#include <Foundation/NSDate.h>
|
||||
#include <Foundation/NSThread.h>
|
||||
#include <Foundation/NSTask.h>
|
||||
#include <Foundation/NSDistributedNotificationCenter.h>
|
||||
|
||||
#include "../Tools/gdnc.h"
|
||||
|
@ -37,8 +40,8 @@
|
|||
* message about it - they include installation path information.
|
||||
*/
|
||||
#define stringify_it(X) #X
|
||||
#define make_gdnc_cmd(X) stringify_it(X) "/Tools/" GNUSTEP_TARGET_DIR "/" LIBRARY_COMBO "/gdnc &"
|
||||
#define make_gdnc_err(X) "check that " stringify_it(X) "/Tools/" GNUSTEP_TARGET_DIR "/" LIBRARY_COMBO "/gdnc is running."
|
||||
#define make_gdnc_cmd(X) stringify_it(X) "/Tools/" GNUSTEP_TARGET_DIR "/gdnc"
|
||||
#define make_gdnc_err(X) "check that " stringify_it(X) "/Tools/" GNUSTEP_TARGET_DIR "/gdnc is running."
|
||||
|
||||
/*
|
||||
* Global variables for distributed notification center types.
|
||||
|
@ -335,10 +338,17 @@ static NSDistributedNotificationCenter *defCenter = nil;
|
|||
|
||||
if (recursion == NO)
|
||||
{
|
||||
static NSString *cmd = nil;
|
||||
|
||||
if (cmd == nil)
|
||||
cmd = [NSString stringWithCString:
|
||||
make_gdnc_cmd(GNUSTEP_INSTALL_PREFIX)];
|
||||
|
||||
NSLog(@"NSDistributedNotificationCenter failed to contact GDNC server.\n");
|
||||
NSLog(@"Attempting to start GDNC process - this will take several seconds.\n");
|
||||
system(make_gdnc_cmd(GNUSTEP_INSTALL_PREFIX));
|
||||
sleep(8);
|
||||
[NSTask launchedTaskWithLaunchPath: cmd arguments: nil];
|
||||
[NSThread sleepUntilDate:
|
||||
[NSDate dateWithTimeIntervalSinceNow: 8.0]];
|
||||
NSLog(@"Retrying connection to the GDNC server.\n");
|
||||
recursion = YES;
|
||||
[self _connect];
|
||||
|
|
|
@ -34,6 +34,9 @@
|
|||
#include <Foundation/NSMapTable.h>
|
||||
#include <Foundation/NSSet.h>
|
||||
#include <Foundation/NSHost.h>
|
||||
#include <Foundation/NSTask.h>
|
||||
#include <Foundation/NSDate.h>
|
||||
#include <Foundation/NSThread.h>
|
||||
#include <Foundation/NSPortNameServer.h>
|
||||
#include <base/TcpPort.h>
|
||||
|
||||
|
@ -47,7 +50,7 @@
|
|||
* message about it - they include installation path information.
|
||||
*/
|
||||
#define stringify_it(X) #X
|
||||
#define make_gdomap_cmd(X) stringify_it(X) "/Tools/"GNUSTEP_TARGET_DIR"/gdomap &"
|
||||
#define make_gdomap_cmd(X) stringify_it(X) "/Tools/"GNUSTEP_TARGET_DIR"/gdomap"
|
||||
#define make_gdomap_err(X) "check that " stringify_it(X) "/Tools/"GNUSTEP_TARGET_DIR"/gdomap is running and owned by root."
|
||||
#define make_gdomap_port(X) stringify_it(X)
|
||||
|
||||
|
@ -920,9 +923,13 @@ static NSPortNameServer *defaultServer = nil;
|
|||
|
||||
- (void) _retry
|
||||
{
|
||||
static NSString *cmd = nil;
|
||||
|
||||
if (cmd == nil)
|
||||
cmd = [NSString stringWithCString: make_gdomap_cmd(GNUSTEP_INSTALL_PREFIX)];
|
||||
NSLog(@"NSPortNameServer attempting to start gdomap on local host");
|
||||
system(make_gdomap_cmd(GNUSTEP_INSTALL_PREFIX));
|
||||
sleep(5);
|
||||
[NSTask launchedTaskWithLaunchPath: cmd arguments: nil];
|
||||
[NSThread sleepUntilDate: [NSDate dateWithTimeIntervalSinceNow: 5.0]];
|
||||
NSLog(@"NSPortNameServer retrying connection attempt to gdomap");
|
||||
[self _open: nil];
|
||||
}
|
||||
|
|
135
Source/NSTask.m
135
Source/NSTask.m
|
@ -1,5 +1,5 @@
|
|||
/* Implementation for NSTask for GNUStep
|
||||
Copyright (C) 1998 Free Software Foundation, Inc.
|
||||
Copyright (C) 1998,1999 Free Software Foundation, Inc.
|
||||
|
||||
Written by: Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||
Date: 1998
|
||||
|
@ -24,6 +24,7 @@
|
|||
#include <config.h>
|
||||
#include <base/preface.h>
|
||||
#include <Foundation/NSObject.h>
|
||||
#include <Foundation/NSBundle.h>
|
||||
#include <Foundation/NSData.h>
|
||||
#include <Foundation/NSDate.h>
|
||||
#include <Foundation/NSString.h>
|
||||
|
@ -107,21 +108,26 @@ static void handleSignal(int sig)
|
|||
[task setLaunchPath: path];
|
||||
[task setArguments: args];
|
||||
[task launch];
|
||||
return [task autorelease];
|
||||
return AUTORELEASE(task);
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
- (void) gcFinalize
|
||||
{
|
||||
[tasksLock lock];
|
||||
NSMapRemove(activeTasks, (void*)taskId);
|
||||
[tasksLock unlock];
|
||||
[arguments release];
|
||||
[environment release];
|
||||
[launchPath release];
|
||||
[currentDirectoryPath release];
|
||||
[standardError release];
|
||||
[standardInput release];
|
||||
[standardOutput release];
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[self gcFinalize];
|
||||
RELEASE(arguments);
|
||||
RELEASE(environment);
|
||||
RELEASE(launchPath);
|
||||
RELEASE(currentDirectoryPath);
|
||||
RELEASE(standardError);
|
||||
RELEASE(standardInput);
|
||||
RELEASE(standardOutput);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
@ -197,9 +203,7 @@ static void handleSignal(int sig)
|
|||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"NSTask - task has been launched"];
|
||||
}
|
||||
[args retain];
|
||||
[arguments release];
|
||||
arguments = args;
|
||||
ASSIGN(arguments, args);
|
||||
}
|
||||
|
||||
- (void) setCurrentDirectoryPath: (NSString*)path
|
||||
|
@ -209,9 +213,7 @@ static void handleSignal(int sig)
|
|||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"NSTask - task has been launched"];
|
||||
}
|
||||
[path retain];
|
||||
[currentDirectoryPath release];
|
||||
currentDirectoryPath = path;
|
||||
ASSIGN(currentDirectoryPath, path);
|
||||
}
|
||||
|
||||
- (void) setEnvironment: (NSDictionary*)env
|
||||
|
@ -221,9 +223,7 @@ static void handleSignal(int sig)
|
|||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"NSTask - task has been launched"];
|
||||
}
|
||||
[env retain];
|
||||
[environment release];
|
||||
environment = env;
|
||||
ASSIGN(environment, env);
|
||||
}
|
||||
|
||||
- (void) setLaunchPath: (NSString*)path
|
||||
|
@ -233,9 +233,7 @@ static void handleSignal(int sig)
|
|||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"NSTask - task has been launched"];
|
||||
}
|
||||
[path retain];
|
||||
[launchPath release];
|
||||
launchPath = path;
|
||||
ASSIGN(launchPath, path);
|
||||
}
|
||||
|
||||
- (void) setStandardError: (id)hdl
|
||||
|
@ -247,9 +245,7 @@ static void handleSignal(int sig)
|
|||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"NSTask - task has been launched"];
|
||||
}
|
||||
[hdl retain];
|
||||
[standardError release];
|
||||
standardError = hdl;
|
||||
ASSIGN(standardError, hdl);
|
||||
}
|
||||
|
||||
- (void) setStandardInput: (NSFileHandle*)hdl
|
||||
|
@ -261,9 +257,7 @@ static void handleSignal(int sig)
|
|||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"NSTask - task has been launched"];
|
||||
}
|
||||
[hdl retain];
|
||||
[standardInput release];
|
||||
standardInput = hdl;
|
||||
ASSIGN(standardInput, hdl);
|
||||
}
|
||||
|
||||
- (void) setStandardOutput: (NSFileHandle*)hdl
|
||||
|
@ -275,9 +269,7 @@ static void handleSignal(int sig)
|
|||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"NSTask - task has been launched"];
|
||||
}
|
||||
[hdl retain];
|
||||
[standardOutput release];
|
||||
standardOutput = hdl;
|
||||
ASSIGN(standardOutput, hdl);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -328,9 +320,20 @@ static void handleSignal(int sig)
|
|||
[self notImplemented: _cmd]; /* Undocumented as yet */
|
||||
}
|
||||
|
||||
/* Declaration from find_exec.c */
|
||||
extern char *objc_find_executable(const char *name);
|
||||
|
||||
- (void) launch
|
||||
{
|
||||
NSMutableArray *toClose;
|
||||
NSFileManager *mgr = [NSFileManager defaultManager];
|
||||
NSString *libs = [NSBundle _library_combo];
|
||||
NSString *arch = [NSBundle _gnustep_target_dir];
|
||||
NSString *prog;
|
||||
NSString *lpath;
|
||||
NSString *base_path;
|
||||
NSString *arch_path;
|
||||
NSString *full_path;
|
||||
int pid;
|
||||
const char *executable;
|
||||
const char *path;
|
||||
|
@ -357,16 +360,71 @@ static void handleSignal(int sig)
|
|||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"NSTask - no launch path set"];
|
||||
}
|
||||
else if ([[NSFileManager defaultManager] isExecutableFileAtPath:
|
||||
launchPath] == NO)
|
||||
|
||||
/*
|
||||
* Set lpath to the actual path to use for the executable.
|
||||
* First choice - base_path/architecture/library_combo/prog.
|
||||
* Second choice - base_path/architecture/prog.
|
||||
* Third choice - base_path/prog.
|
||||
* Otherwise - try using PATH environment variable if possible.
|
||||
*/
|
||||
prog = [launchPath lastPathComponent];
|
||||
base_path = [launchPath stringByDeletingLastPathComponent];
|
||||
if ([[base_path lastPathComponent] isEqualToString: libs] == YES)
|
||||
base_path = [base_path stringByDeletingLastPathComponent];
|
||||
if ([[base_path lastPathComponent] isEqualToString: arch] == YES)
|
||||
base_path = [base_path stringByDeletingLastPathComponent];
|
||||
arch_path = [base_path stringByAppendingPathComponent: arch];
|
||||
full_path = [arch_path stringByAppendingPathComponent: libs];
|
||||
|
||||
lpath = [full_path stringByAppendingPathComponent: prog];
|
||||
if ([mgr isExecutableFileAtPath: lpath] == NO)
|
||||
{
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"NSTask - launch path is not valid"];
|
||||
lpath = [arch_path stringByAppendingPathComponent: prog];
|
||||
if ([mgr isExecutableFileAtPath: lpath] == NO)
|
||||
{
|
||||
lpath = [base_path stringByAppendingPathComponent: prog];
|
||||
if ([mgr isExecutableFileAtPath: lpath] == NO)
|
||||
{
|
||||
const char *cpath = 0;
|
||||
|
||||
/*
|
||||
* Last resort - if the launch path was simply a program name
|
||||
* get objc_find_executable() to try using the PATH environment
|
||||
* variable to find the executable.
|
||||
*/
|
||||
if ([base_path isEqualToString: @""] == YES)
|
||||
{
|
||||
|
||||
cpath = objc_find_executable([prog cString]);
|
||||
}
|
||||
if (cpath == 0)
|
||||
{
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"NSTask - launch path is not valid"];
|
||||
}
|
||||
else
|
||||
{
|
||||
lpath = [NSString stringWithCString: cpath];
|
||||
OBJC_FREE((void*)cpath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Make sure we have a standardised absolute path to pass to execve()
|
||||
*/
|
||||
if ([lpath isAbsolutePath] == NO)
|
||||
{
|
||||
NSString *current = [mgr currentDirectoryPath];
|
||||
|
||||
executable = [[self launchPath] cString];
|
||||
lpath = [current stringByAppendingPathComponent: lpath];
|
||||
}
|
||||
lpath = [lpath stringByStandardizingPath];
|
||||
|
||||
executable = [lpath cString];
|
||||
args[0] = [prog cString];
|
||||
|
||||
args[0] = [[[self launchPath] lastPathComponent] cString];
|
||||
for (i = 0; i < ac; i++)
|
||||
{
|
||||
args[i+1] = [[[a objectAtIndex: i] description] cString];
|
||||
|
@ -474,6 +532,7 @@ static void handleSignal(int sig)
|
|||
{
|
||||
taskId = pid;
|
||||
hasLaunched = YES;
|
||||
ASSIGN(launchPath, lpath); // Actual path used.
|
||||
|
||||
[tasksLock lock];
|
||||
NSMapInsert(activeTasks, (void*)taskId, (void*)self);
|
||||
|
@ -523,7 +582,7 @@ static void handleSignal(int sig)
|
|||
limit = [[NSDate alloc] initWithTimeIntervalSinceNow: 0.1];
|
||||
[[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode
|
||||
beforeDate: limit];
|
||||
[limit release];
|
||||
RELEASE(limit);
|
||||
}
|
||||
}
|
||||
@end
|
||||
|
|
|
@ -26,6 +26,7 @@ after-install::
|
|||
echo "in which case you should install it by hand."; \
|
||||
else \
|
||||
$(INSTALL) -m 05755 $(GNUSTEP_OBJ_DIR)/gdomap $(GNUSTEP_INSTALLATION_DIR)/Tools/$(GNUSTEP_TARGET_DIR); \
|
||||
$(INSTALL) -m 05755 $(GNUSTEP_OBJ_DIR)/gdnc $(GNUSTEP_INSTALLATION_DIR)/Tools/$(GNUSTEP_TARGET_DIR); \
|
||||
fi; \
|
||||
|
||||
# Things to do before uninstalling
|
||||
|
|
Loading…
Reference in a new issue