From: VMware, Inc <> Date: Tue, 24 Aug 2010 18:04:43 +0000 (-0700) Subject: Changes in shared code that don't affect open-vm-tools functionality. X-Git-Tag: 2010.08.24-292196~67 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7c8c75a82a7fcd98fbdeb62180259e51fea3afd3;p=thirdparty%2Fopen-vm-tools.git Changes in shared code that don't affect open-vm-tools functionality. Signed-off-by: Marcelo Vanzin --- diff --git a/open-vm-tools/lib/file/fileIOPosix.c b/open-vm-tools/lib/file/fileIOPosix.c index b1ac820f9..6f4a0591d 100644 --- a/open-vm-tools/lib/file/fileIOPosix.c +++ b/open-vm-tools/lib/file/fileIOPosix.c @@ -2173,6 +2173,51 @@ FileIO_PrivilegedPosixOpen(ConstUnicode pathName, // IN: } +/* + *----------------------------------------------------------------------------- + * + * FileIO_FDToStream + * + * Return a FILE * stream equivalent to the given (POSIX) file descriptor. + * This is the logical equivalent of Posix dup() then fdopen(). + * + * Caller should fclose the returned descriptor when finished. + * + * Results: + * !NULL A FILE * associated with the file associated with the fd + * NULL Failure + * + * Side effects: + * New fd allocated. + * + *----------------------------------------------------------------------------- + */ + + +FILE * +FileIO_FDToStream(int fd, // IN: + const char *mode, // IN: + Bool textMode) // IN: unused +{ + int dupFD; + FILE *stream; + + dupFD = dup(fd); + + if (dupFD == -1) { + return NULL; + } + + stream = fdopen(dupFD, mode); + + if (stream == NULL) { + close(dupFD); + } + + return stream; +} + + /* *----------------------------------------------------------------------------- * @@ -2181,14 +2226,11 @@ FileIO_PrivilegedPosixOpen(ConstUnicode pathName, // IN: * Return a FILE * stream equivalent to the given FileIODescriptor. * This is the logical equivalent of Posix dup() then fdopen(). * - * Since the passed descriptor and returned FILE * represent the same - * underlying file, and their cursor is shared, you should avoid - * interleaving uses to both. + * Caller should fclose the returned descriptor when finished. * * Results: - * A FILE * representing the same underlying file as the passed descriptor - * NULL if there was an error. - * Caller should fclose the returned descriptor when finished. + * !NULL A FILE * associated with the file associated with the fd + * NULL Failure * * Side effects: * New fd allocated. @@ -2200,21 +2242,14 @@ FILE * FileIO_DescriptorToStream(FileIODescriptor *fdesc, // IN: Bool textMode) // IN: unused { - int dupFd; - const char *mode; int tmpFlags; - FILE *stream; + const char *mode; /* The file you pass us should be valid and opened for *something* */ ASSERT(FileIO_IsValid(fdesc)); ASSERT((fdesc->flags & (FILEIO_OPEN_ACCESS_READ | FILEIO_OPEN_ACCESS_WRITE)) != 0); tmpFlags = fdesc->flags & (FILEIO_OPEN_ACCESS_READ | FILEIO_OPEN_ACCESS_WRITE); - dupFd = dup(fdesc->posix); - if (dupFd == -1) { - return NULL; - } - if (tmpFlags == (FILEIO_OPEN_ACCESS_READ | FILEIO_OPEN_ACCESS_WRITE)) { mode = "r+"; } else if (tmpFlags == FILEIO_OPEN_ACCESS_WRITE) { @@ -2223,18 +2258,11 @@ FileIO_DescriptorToStream(FileIODescriptor *fdesc, // IN: mode = "r"; } - stream = fdopen(dupFd, mode); - - if (stream == NULL) { - close(dupFd); - } - - return stream; + return FileIO_FDToStream(fdesc->posix, mode, textMode); } #if defined(__APPLE__) - /* *----------------------------------------------------------------------------- * diff --git a/open-vm-tools/lib/include/fileIO.h b/open-vm-tools/lib/include/fileIO.h index 51003c5f6..bb3ab1129 100644 --- a/open-vm-tools/lib/include/fileIO.h +++ b/open-vm-tools/lib/include/fileIO.h @@ -371,6 +371,10 @@ int FileIO_PrivilegedPosixOpen(ConstUnicode pathName, int flags); #endif +FILE *FileIO_FDToStream(int fd, + const char *mode, + Bool textMode); + FILE *FileIO_DescriptorToStream(FileIODescriptor *fd, Bool textMode); diff --git a/open-vm-tools/lib/include/log.h b/open-vm-tools/lib/include/log.h index 23591a23a..c83c70b36 100644 --- a/open-vm-tools/lib/include/log.h +++ b/open-vm-tools/lib/include/log.h @@ -31,7 +31,7 @@ typedef void (LogBasicFunc)(const char *fmt, va_list args); typedef enum { - LOG_NO_SYSTEM_LOGGER, + LOG_SYSTEM_LOGGER_NONE, LOG_SYSTEM_LOGGER_ADJUNCT, LOG_SYSTEM_LOGGER_ONLY } SysLogger; @@ -100,11 +100,11 @@ uint32 Log_MaxLineLength(void); void Log_RegisterBasicFunctions(LogBasicFunc *log, LogBasicFunc *warning); -Bool Log_SwitchFile(const char *fileName, - const char *config, - Bool copy, - uint32 systemLoggerUse, - char *systemLoggerID); +Bool Log_SetOutput(const char *fileName, + const char *config, + Bool copy, + uint32 systemLoggerUse, + char *systemLoggerID); size_t Log_MakeTimeString(Bool millisec, char *buf,