From f3dcdfe1ce175dc616a53d5664d20486fc0bbb5d Mon Sep 17 00:00:00 2001 From: Olaf Barthel Date: Tue, 12 Sep 2006 14:16:44 +0000 Subject: [PATCH] - __get_default_file() now dynamically fills in file handles for the stdin/stdout/stderr streams if it's part of the thread-safe library. - fpathconf() now checks if the file descriptor is really referring to a file. - The termios hook entry code could file descriptor's embedded file handle rather than what the thread safe library had dynamically bound to the stdin/stdout/stderr streams. git-svn-id: file:///Users/olsen/Code/migration-svn-zu-git/logical-line-staging/clib2/trunk@15130 87f5fb63-7c3d-0410-a384-fd976d0f7a62 --- library/changes | 9 ++++ library/fcntl_get_default_file.c | 69 +++++++++++++++++++++++++-- library/termios_console_fdhookentry.c | 4 +- library/unistd_fpathconf.c | 8 +++- 4 files changed, 84 insertions(+), 6 deletions(-) diff --git a/library/changes b/library/changes index d8748da..b067900 100644 --- a/library/changes +++ b/library/changes @@ -1,3 +1,12 @@ +- __get_default_file() now dynamically fills in file handles for the + stdin/stdout/stderr streams if it's part of the thread-safe library. + +- fpathconf() now checks if the file descriptor is really referring to a file. + +- The termios hook entry code could file descriptor's embedded file handle + rather than what the thread safe library had dynamically bound to the + stdin/stdout/stderr streams. + - execve() now finds commands in the current directory again, even if you omit the leading "./" path name. diff --git a/library/fcntl_get_default_file.c b/library/fcntl_get_default_file.c index 6919237..2b81e8d 100644 --- a/library/fcntl_get_default_file.c +++ b/library/fcntl_get_default_file.c @@ -1,5 +1,5 @@ /* - * $Id: fcntl_get_default_file.c,v 1.5 2006-01-08 12:04:22 obarthel Exp $ + * $Id: fcntl_get_default_file.c,v 1.6 2006-09-12 14:16:44 obarthel Exp $ * * :ts=4 * @@ -44,8 +44,9 @@ int __get_default_file(int file_descriptor,long * file_ptr) { - struct fd * fd; int result = ERROR; + struct fd * fd; + BPTR file; assert( file_descriptor >= 0 && file_descriptor < __num_fd ); assert( __fd[file_descriptor] != NULL ); @@ -59,11 +60,73 @@ __get_default_file(int file_descriptor,long * file_ptr) goto out; } - (*file_ptr) = (long)fd->fd_DefaultFile; + __fd_unlock(fd); + + #if defined(__THREAD_SAFE) + { + /* Check if this file should be dynamically bound to one of the + three standard I/O streams. */ + if(FLAG_IS_SET(fd->fd_Flags,FDF_STDIO)) + { + switch(fd->fd_DefaultFile) + { + case STDIN_FILENO: + + file = Input(); + break; + + case STDOUT_FILENO: + + file = Output(); + break; + + case STDERR_FILENO: + + #if defined(__amigaos4__) + { + file = ErrorOutput(); + } + #else + { + struct Process * this_process = (struct Process *)FindTask(NULL); + + file = this_process->pr_CES; + } + #endif /* __amigaos4__ */ + + /* The following is rather controversial; if the standard error stream + is unavailable, we default to reuse the standard output stream. This + is problematic if the standard output stream was redirected and should + not be the same as the standard error output stream. */ + if(file == ZERO) + file = Output(); + + break; + + default: + + file = ZERO; + break; + } + } + else + { + file = fd->fd_DefaultFile; + } + } + #else + { + file = fd->fd_DefaultFile; + } + #endif /* __THREAD_SAFE */ + + (*file_ptr) = (long)file; result = 0; out: + __fd_unlock(fd); + return(result); } diff --git a/library/termios_console_fdhookentry.c b/library/termios_console_fdhookentry.c index 64f41b9..fe934b4 100755 --- a/library/termios_console_fdhookentry.c +++ b/library/termios_console_fdhookentry.c @@ -1,5 +1,5 @@ /* - * $Id: termios_console_fdhookentry.c,v 1.2 2006-01-08 12:04:27 obarthel Exp $ + * $Id: termios_console_fdhookentry.c,v 1.3 2006-09-12 14:16:44 obarthel Exp $ * * :ts=4 * @@ -328,7 +328,7 @@ __termios_console_hook( } else { - if(WaitForChar(fd->fd_DefaultFile,100000*tios->c_cc[VTIME])) + if(WaitForChar(file,100000*tios->c_cc[VTIME])) result = Read(file,fam->fam_Data,fam->fam_Size); } } diff --git a/library/unistd_fpathconf.c b/library/unistd_fpathconf.c index dd10ea4..64c25fd 100644 --- a/library/unistd_fpathconf.c +++ b/library/unistd_fpathconf.c @@ -1,5 +1,5 @@ /* - * $Id: unistd_fpathconf.c,v 1.1 2006-07-28 14:37:28 obarthel Exp $ + * $Id: unistd_fpathconf.c,v 1.2 2006-09-12 14:16:44 obarthel Exp $ * * :ts=4 * @@ -63,6 +63,12 @@ fpathconf(int file_descriptor,int name) goto out; } + if(FLAG_IS_SET(fd->fd_Flags,FDF_STDIO) || FLAG_IS_SET(fd->fd_Flags,FDF_IS_SOCKET)) + { + __set_errno(EBADF); + goto out; + } + fh = BADDR(fd->fd_DefaultFile); ret = __pathconf(fh->fh_Type,name); /* Ok if fh->fh_Type==NULL */