From b048323196490ebffd5840e0b8db53c0ede86fc2 Mon Sep 17 00:00:00 2001 From: Olaf Barthel Date: Sat, 12 Mar 2005 09:43:48 +0000 Subject: [PATCH] - Aliases of file descriptors are now using the signal semaphore of the original file descriptor. - close() did not return 0 if the file descriptor in question was really just an alias. Fixed. - Added a feature which makes it possible to have several clients use the standard I/O streams (stdin/stdout/stderr) and have these referring to their process' Input()/Output()/ErrorOutput() streams. This is intended to support the upcoming shared library feature. git-svn-id: file:///Users/olsen/Code/migration-svn-zu-git/logical-line-staging/clib2/trunk@14885 87f5fb63-7c3d-0410-a384-fd976d0f7a62 --- library/changes | 13 ++++++++++ library/fcntl_lock.c | 12 +++++++++- library/socket_hook_entry.c | 8 +++---- library/stdio_fdhookentry.c | 47 ++++++++++++++++++++++++++++++------- library/stdio_headers.h | 4 +++- 5 files changed, 69 insertions(+), 15 deletions(-) diff --git a/library/changes b/library/changes index c15710d..5f7752c 100644 --- a/library/changes +++ b/library/changes @@ -74,6 +74,19 @@ that the constructors/destructors are called in the proper order, too. +- Aliases of file descriptors are now using the signal semaphore + of the original file descriptor. + +- close() did not return 0 if the file descriptor in question + was really just an alias. Fixed. + +- Added a feature which makes it possible to have several clients + use the standard I/O streams (stdin/stdout/stderr) and have these + referring to their process' Input()/Output()/ErrorOutput() + streams. This is intended to support the upcoming shared + library feature. + + c.lib 1.189 (5.3.2005) diff --git a/library/fcntl_lock.c b/library/fcntl_lock.c index 3128ea5..0d25f32 100644 --- a/library/fcntl_lock.c +++ b/library/fcntl_lock.c @@ -1,5 +1,5 @@ /* - * $Id: fcntl_lock.c,v 1.1 2005-02-28 13:22:53 obarthel Exp $ + * $Id: fcntl_lock.c,v 1.2 2005-03-12 09:43:47 obarthel Exp $ * * :ts=4 * @@ -44,6 +44,11 @@ void __fd_lock(struct fd * fd) { + /* If this descriptor is really an alias, use the semaphore + associated with the original instead. */ + if(fd != NULL && fd->fd_Original != NULL) + fd = fd->fd_Original; + if(fd != NULL && fd->fd_Lock != NULL) ObtainSemaphore(fd->fd_Lock); } @@ -53,6 +58,11 @@ __fd_lock(struct fd * fd) void __fd_unlock(struct fd * fd) { + /* If this descriptor is really an alias, use the semaphore + associated with the original instead. */ + if(fd != NULL && fd->fd_Original != NULL) + fd = fd->fd_Original; + if(fd != NULL && fd->fd_Lock != NULL) ReleaseSemaphore(fd->fd_Lock); } diff --git a/library/socket_hook_entry.c b/library/socket_hook_entry.c index ba048a5..bd524ab 100644 --- a/library/socket_hook_entry.c +++ b/library/socket_hook_entry.c @@ -1,5 +1,5 @@ /* - * $Id: socket_hook_entry.c,v 1.12 2005-03-09 12:06:10 obarthel Exp $ + * $Id: socket_hook_entry.c,v 1.13 2005-03-12 09:43:47 obarthel Exp $ * * :ts=4 * @@ -104,6 +104,8 @@ __socket_hook_entry( SHOWMSG("file_action_close"); + result = 0; + /* If this is an alias, just remove it. */ if(__fd_is_aliased(fd)) { @@ -116,7 +118,7 @@ __socket_hook_entry( { PROFILE_OFF(); - __CloseSocket((LONG)fd->fd_DefaultFile); + result = __CloseSocket((LONG)fd->fd_DefaultFile); PROFILE_ON(); } @@ -134,8 +136,6 @@ __socket_hook_entry( /* And that's the last for this file descriptor. */ memset(fd,0,sizeof(*fd)); - result = 0; - break; case file_action_seek: diff --git a/library/stdio_fdhookentry.c b/library/stdio_fdhookentry.c index 2411a22..5a31d63 100644 --- a/library/stdio_fdhookentry.c +++ b/library/stdio_fdhookentry.c @@ -1,5 +1,5 @@ /* - * $Id: stdio_fdhookentry.c,v 1.19 2005-03-09 12:06:10 obarthel Exp $ + * $Id: stdio_fdhookentry.c,v 1.20 2005-03-12 09:43:48 obarthel Exp $ * * :ts=4 * @@ -75,6 +75,35 @@ __fd_hook_entry( __fd_lock(fd); file = fd->fd_DefaultFile; + + /* Check if this file should be dynamically bound to one of the + three standard I/O streams. */ + if(file == ZERO && FLAG_IS_SET(fd->fd_Flags,FDF_STDIO)) + { + if (fd == __fd[STDIN_FILENO]) + { + file = Input(); + } + else if (fd == __fd[STDOUT_FILENO]) + { + file = Output(); + } + else if (fd == __fd[STDERR_FILENO]) + { + #if defined(__amigaos4__) + { + file = ErrorOutput(); + } + #else + { + struct Process * this_process = (struct Process *)FindTask(NULL); + + file = this_process->pr_CES; + } + #endif /* __amigaos4__ */ + } + } + if(file == ZERO) { SHOWMSG("file is closed"); @@ -160,23 +189,23 @@ __fd_hook_entry( SHOWMSG("file_action_close"); + /* The following is almost guaranteed not to fail. */ + result = 0; + /* If this is an alias, just remove it. */ if(__fd_is_aliased(fd)) { __remove_fd_alias(fd); } - else + else if (fd->fd_DefaultFile != ZERO) { - /* The following is almost guaranteed not to fail. */ - result = 0; - /* Are we disallowed to close this file? */ if(FLAG_IS_SET(fd->fd_Flags,FDF_NO_CLOSE)) { /* OK, so we cannot close it. But we might be obliged to reset a console into buffered mode. */ if(FLAG_IS_SET(fd->fd_Flags,FDF_NON_BLOCKING) && FLAG_IS_SET(fd->fd_Flags,FDF_IS_INTERACTIVE)) - SetMode(file,DOSFALSE); + SetMode(fd->fd_DefaultFile,DOSFALSE); } else { @@ -194,14 +223,14 @@ __fd_hook_entry( PROFILE_OFF(); - parent_dir = __safe_parent_of_file_handle(file); + parent_dir = __safe_parent_of_file_handle(fd->fd_DefaultFile); if(parent_dir != ZERO) { - if(__safe_examine_file_handle(file,fib)) + if(__safe_examine_file_handle(fd->fd_DefaultFile,fib)) name_and_path_valid = TRUE; } - if(CANNOT Close(file)) + if(CANNOT Close(fd->fd_DefaultFile)) { fam->fam_Error = __translate_io_error_to_errno(IoErr()); diff --git a/library/stdio_headers.h b/library/stdio_headers.h index de3006f..1cbdfb8 100644 --- a/library/stdio_headers.h +++ b/library/stdio_headers.h @@ -1,5 +1,5 @@ /* - * $Id: stdio_headers.h,v 1.19 2005-03-11 13:23:18 obarthel Exp $ + * $Id: stdio_headers.h,v 1.20 2005-03-12 09:43:48 obarthel Exp $ * * :ts=4 * @@ -316,6 +316,8 @@ struct iob mode (sockets only). */ #define FDF_IS_INTERACTIVE (1UL<<11) /* File is attached to a console window or something like it. */ +#define FDF_STDIO (1UL<<12) /* File is to be attached to one of the + standard input/output/error streams. */ /****************************************************************************/