diff --git a/ChangeLog b/ChangeLog index ad38534b7..2dc940d83 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Thu Apr 15 9:47:00 1999 Richard Frith-Macdonald + + * Source/UnixFileHandle.m: ([-fileDescriptor]) return a valid file + descriptor (for /dev/null) for the null device. + * Source/NSTask.m: ([-launch]) Add code to reset signals in subprocess + and to close all file descriptors (except stdin, stdout and stderr). + Wed Apr 14 14:32:00 1999 Richard Frith-Macdonald * Source/NSPortNameServer.m: Don't suspend thread while waiting for diff --git a/Source/NSTask.m b/Source/NSTask.m index e55d5dec9..64335a6da 100644 --- a/Source/NSTask.m +++ b/Source/NSTask.m @@ -41,8 +41,16 @@ #include #include +#include #include +/* + * If we don't have NFILE, default to 256 open descriptors. + */ +#ifndef NOFILE +#define NOFILE 256 +#endif + NSString *NSTaskDidTerminateNotification = @"NSTaskDidTerminateNotification"; static NSRecursiveLock *tasksLock = nil; @@ -490,6 +498,19 @@ extern char *objc_find_executable(const char *name); } if (pid == 0) { + int i; + + /* + * Make sure the task gets default signal setup. + */ + for (i = 0; i < 32; i++) + { + signal(i, SIG_DFL); + } + + /* + * Make sure task is run in it's own process group. + */ #if HAVE_SETPGRP setpgrp(); #else @@ -498,6 +519,7 @@ extern char *objc_find_executable(const char *name); setpgid(pid, pid); #endif #endif + /* * Set up stdin, stdout and stderr by duplicating descriptors as * necessary and closing the originals (to ensure we won't have a @@ -506,24 +528,21 @@ extern char *objc_find_executable(const char *name); if (idesc != 0) { dup2(idesc, 0); - if (idesc != odesc && idesc != edesc) - { - (void) close(idesc); - } } if (odesc != 1) { dup2(odesc, 1); - if (odesc != edesc) - { - (void) close(odesc); - } } if (edesc != 2) { dup2(edesc, 2); - (void) close(edesc); } + + for (i = 3; i < NOFILE; i++) + { + (void) close(i); + } + chdir(path); execve(executable, args, envl); exit(-1); diff --git a/Source/UnixFileHandle.m b/Source/UnixFileHandle.m index 9fde2c28e..5d95b2939 100644 --- a/Source/UnixFileHandle.m +++ b/Source/UnixFileHandle.m @@ -636,8 +636,6 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin) - (int)fileDescriptor { - if (isNullDevice) - return -1; return descriptor; }