From: VMware, Inc <> Date: Mon, 20 Dec 2010 22:21:25 +0000 (-0800) Subject: Internal branch sync. Included in this change: X-Git-Tag: 2010.12.19-339835~8 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b7bcd42e498beaf0787d3b1373e5ce6a7f6d4324;p=thirdparty%2Fopen-vm-tools.git Internal branch sync. Included in this change: . VIX: don't truncate cmdline . VIX: Convert process command lines and owners' names to UTF-8 in ListProcesses. . changes in shared code that don't affect open-vm-tools functionality. Signed-off-by: Marcelo Vanzin --- diff --git a/open-vm-tools/lib/include/libExport.hh b/open-vm-tools/lib/include/libExport.hh index d7bb01ef7..b5eda9703 100644 --- a/open-vm-tools/lib/include/libExport.hh +++ b/open-vm-tools/lib/include/libExport.hh @@ -26,28 +26,24 @@ #ifndef LIB_EXPORT_HH #define LIB_EXPORT_HH -#ifdef _WIN32 - #ifdef LIB_EXPORT_SOURCE - #define LIB_EXPORT __declspec(dllexport) - #else - #define LIB_EXPORT __declspec(dllimport) - #endif - - #ifdef LIB_EXPORT_WUI_SOURCE - #define LIB_EXPORT_WUI __declspec(dllexport) - #else - #define LIB_EXPORT_WUI __declspec(dllimport) - #endif +#include "vm_api.h" - #ifdef VMSTRING_EXPORT_SOURCE - #define VMSTRING_EXPORT __declspec(dllexport) - #else - #define VMSTRING_EXPORT __declspec(dllimport) - #endif -#else - #define LIB_EXPORT - #define LIB_EXPORT_WUI - #define VMSTRING_EXPORT -#endif // WIN32 +#ifdef LIB_EXPORT_SOURCE + #define LIB_EXPORT VMW_EXPORT +#else + #define LIB_EXPORT VMW_IMPORT +#endif + +#ifdef LIB_EXPORT_WUI_SOURCE + #define LIB_EXPORT_WUI VMW_EXPORT +#else + #define LIB_EXPORT_WUI VMW_IMPORT +#endif + +#ifdef VMSTRING_EXPORT_SOURCE + #define VMSTRING_EXPORT VMW_EXPORT +#else + #define VMSTRING_EXPORT VMW_IMPORT +#endif #endif // LIB_EXPORT_HH diff --git a/open-vm-tools/lib/include/strutil.h b/open-vm-tools/lib/include/strutil.h index 61e637d6d..1968b7c42 100644 --- a/open-vm-tools/lib/include/strutil.h +++ b/open-vm-tools/lib/include/strutil.h @@ -44,6 +44,7 @@ Bool StrUtil_StrToInt(int32 *out, const char *str); Bool StrUtil_StrToUint(uint32 *out, const char *str); Bool StrUtil_StrToInt64(int64 *out, const char *str); Bool StrUtil_StrToSizet(size_t *out, const char *str); +Bool StrUtil_StrToDouble(double *out, const char *str); Bool StrUtil_CapacityToSectorType(SectorType *out, const char *str, unsigned int bytes); char * StrUtil_FormatSizeInBytesUnlocalized(uint64 size); diff --git a/open-vm-tools/lib/include/vm_api.h b/open-vm-tools/lib/include/vm_api.h new file mode 100644 index 000000000..fdfea286c --- /dev/null +++ b/open-vm-tools/lib/include/vm_api.h @@ -0,0 +1,86 @@ +/********************************************************* + * Copyright (C) 2010 VMware, Inc. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation version 2.1 and no later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + *********************************************************/ + +/* + * + * vm_api.h -- + * + * Import/export macro definitions. + */ + + +#ifndef VM_API_H +#define VM_API_H + +/* + * DLL/DSO import/export macros. + * + * These macros can be used by libraries to automatically export/import symbols. + * The general approach is: + * + * 1) libfoo defines a macro, say FOO_COMPILING_DYNAMIC, + * in its Makefile/Scons file. + * + * 2) libfoo has the following code in a header file, e.g. foo/config.h, that is + * included by all headers that export/import symbols: + * #include + * #ifdef FOO_COMPILING_DYNAMIC + * # define FOO_API VMW_EXPORT + * #else + * # define FOO_API VMW_IMPORT + * #endif // FOO_COMPILING_DYNAMIC + * + * For example: + * // In a file named FooObject.h + * #ifndef FOO_OBJECT_H + * #define FOO_OBJECT_H + * + * #include + * + * class FOO_API FooObject { }; + * FOO_API FooObject *GetFooObject(); + + * #endif // FOO_OBJECT_H + * + * 3) libfoo can now use FOO_API for all symbols it would like to export, + * which resolves to VMW_EXPORT, while compiling libfoo as a dynamic shared + * library. + * + * 4) Whenever a client of libfoo includes its headers, these symbols will be + * marked with VMW_IMPORT, since FOO_COMPILING_DYNAMIC is not defined for + * the client. + * + * NOTE: By default, symbols are hidden when compiling with MSC and exported + * when compiling with GCC. Thus, it's best to compile with GCC's + * -fvisibility=hidden and -fvisibility-inlines-hidden flags, so that only + * symbols explicitly marked with VMW_EXPORT are exported. Also note that + * these flags, as well as the attributes, are available in GCC 4 and later. + */ +#ifdef _MSC_VER +# define VMW_IMPORT __declspec(dllimport) +# define VMW_EXPORT __declspec(dllexport) +#elif defined __GNUC__ && __GNUC__ >= 4 /* !_MSC_VER */ +# define VMW_IMPORT +# define VMW_EXPORT __attribute__ ((visibility ("default"))) +#else +# define VMW_IMPORT +# define VMW_EXPORT +#endif /* _MSC_VER */ + + +#endif /* VM_API_H */ diff --git a/open-vm-tools/lib/include/vm_version.h b/open-vm-tools/lib/include/vm_version.h index 0a52098ef..fbadf8a00 100644 --- a/open-vm-tools/lib/include/vm_version.h +++ b/open-vm-tools/lib/include/vm_version.h @@ -219,6 +219,7 @@ #define VCB_FILE_VERSION 4,0,0,0 #define VIM_VERSION "5.0.0" #define VPX_VERSION "5.0.0" +#define VPX_RELEASE_UPDATE "0" /* 0 = Pre-release/GA, 1 = Update 1 */ #define SVA_VERSION "1.0.0" #define WBC_VERSION "5.0.0" #define SDK_VERSION "4.1.0" @@ -277,7 +278,7 @@ #define USB_ARBITRATOR_VERSION_MAJOR 8 #define USB_ARBITRATOR_VERSION_MINOR 2 -#define USB_ARBITRATOR_VERSION_Z 4 +#define USB_ARBITRATOR_VERSION_Z 6 #define USB_ARBITRATOR_VERSION_BASE USB_ARBITRATOR_VERSION_MAJOR.\ USB_ARBITRATOR_VERSION_MINOR @@ -292,7 +293,7 @@ * USB Arbitrator Component version. This version is used by the linux * installer. See USB_ARBITRATOR_COMPONENT_VERSION_NUMBER in mk/defs-onetime.mk */ -#define USB_ARBITRATOR_COMPONENT_VERSION_NUMBER "8.2.4" +#define USB_ARBITRATOR_COMPONENT_VERSION_NUMBER "8.2.6" #ifdef VMX86_VPX #define VIM_API_TYPE "VirtualCenter" @@ -398,7 +399,7 @@ # if defined(__APPLE__) # define PRODUCT_LICENSE_VERSION "3.0" # else -# define PRODUCT_LICENSE_VERSION "7.0+" +# define PRODUCT_LICENSE_VERSION "8.0+" # endif # elif defined(VMX86_VPX) # define PRODUCT_LICENSE_VERSION "5.0" diff --git a/open-vm-tools/lib/misc/strutil.c b/open-vm-tools/lib/misc/strutil.c index 64322f3d4..a7a40572f 100644 --- a/open-vm-tools/lib/misc/strutil.c +++ b/open-vm-tools/lib/misc/strutil.c @@ -265,7 +265,7 @@ StrUtil_DecimalStrToUint(unsigned int *out, // OUT *out = (unsigned int)val; return TRUE; } - + /* *----------------------------------------------------------------------------- @@ -444,6 +444,45 @@ StrUtil_StrToSizet(size_t *out, // OUT: The output value } +/* + *----------------------------------------------------------------------------- + * + * StrUtil_StrToDouble -- + * + * Convert a string into a double. + * + * Results: + * TRUE if the conversion was successful and 'out' contains the converted + * result. + * FALSE otherwise. 'out' is undefined. + * + * Side effects: + * Modifies errno. + * + *----------------------------------------------------------------------------- + */ + +Bool +StrUtil_StrToDouble(double *out, // OUT: The output value + const char *str) // IN : String to parse +{ + char *ptr = NULL; + + ASSERT(out); + ASSERT(str); + + errno = 0; + + *out = strtod(str, &ptr); + + /* + * Input must be complete and no overflow. + */ + + return *ptr == '\0' && errno != ERANGE; +} + + #ifndef N_PLAT_NLM // NetWare Tools ask for unresolved _GLOBAL_OFFSET_TABLE... /* *----------------------------------------------------------------------------- @@ -495,7 +534,7 @@ StrUtil_CapacityToSectorType(SectorType *out, // OUT: The output value /* * [kK], [mM], [gG], and [tT] represent kilo, mega, giga, and tera * byte quantities respectively. [bB] represents a singular byte - * quantity. [sS] represents a sector quantity. + * quantity. [sS] represents a sector quantity. * * For kilo, mega, giga, and tera we're OK with an additional byte * suffix. Otherwise, the presence of an additional suffix is an error. @@ -542,7 +581,7 @@ StrUtil_CapacityToSectorType(SectorType *out, // OUT: The output value return TRUE; } #endif - + /* *----------------------------------------------------------------------------- diff --git a/open-vm-tools/lib/procMgr/procMgrPosix.c b/open-vm-tools/lib/procMgr/procMgrPosix.c index 45f905c34..860a5821b 100644 --- a/open-vm-tools/lib/procMgr/procMgrPosix.c +++ b/open-vm-tools/lib/procMgr/procMgrPosix.c @@ -143,6 +143,92 @@ setresgid(gid_t ruid, #endif +/* + *---------------------------------------------------------------------- + * + * ProcMgr_ReadProcFile -- + * + * Read the contents of a file in /proc/. + * + * The size is essentially unbounded because of cmdline arguments. + * The only way to figure out the content size is to keep reading; + * stat(2) and lseek(2) lie. + * + * The contents are NUL terminated -- in some distros may not include + * a NUL for some commands (eg. pid 1, /sbin/init) -- so add + * one to be safe. + * + * Results: + * + * The length of the file. + * + * -1 on error. + * + * Side effects: + * + * The returned contents must be freed by caller. + * + *---------------------------------------------------------------------- + */ + +#if !defined(sun) +int +ProcMgr_ReadProcFile(int fd, // IN + char **contents) // OUT +{ + int size = 0; +#if !defined(__FreeBSD__) && !defined(__APPLE__) + char tmp[512]; + int numRead; + + *contents = NULL; + numRead = read(fd, tmp, sizeof(tmp)); + size = numRead; + + if (numRead <= 0) { + goto done; + } + + /* + * handle the 99% case + */ + if (sizeof(tmp) > numRead) { + char *result; + + result = malloc(numRead + 1); + if (NULL == result) { + size = -1; + goto done; + } + memcpy(result, tmp, numRead); + result[numRead] = '\0'; + *contents = result; + goto done; + } else { + DynBuf dbuf; + + DynBuf_Init(&dbuf); + DynBuf_Append(&dbuf, tmp, numRead); + do { + numRead = read(fd, tmp, sizeof(tmp)); + if (numRead > 0) { + DynBuf_Append(&dbuf, tmp, numRead); + } + size += numRead; + } while (numRead > 0); + // add the NUL term + DynBuf_Append(&dbuf, "", 1); + DynBuf_Trim(&dbuf); + *contents = DynBuf_Detach(&dbuf); + DynBuf_Destroy(&dbuf); + } +done: +#endif + return size; +} + +#endif // !sun + /* *---------------------------------------------------------------------- * @@ -250,8 +336,8 @@ ProcMgr_ListProcesses(void) pid_t pid; int replaceLoop; struct passwd *pwd; - char cmdLineTemp[2048]; - char cmdStatTemp[2048]; + char *cmdLineTemp = NULL; + char *cmdStatTemp = NULL; char *cmdLine; char *userName = NULL; size_t strLen = 0; @@ -296,14 +382,18 @@ ProcMgr_ListProcesses(void) * In the future, we could keep the NUL version around and pass it * back to the client for easier parsing when retrieving individual * command line parameters is needed. - * - * We read at most (sizeof cmdLineTemp) - 1 bytes to leave room - * for NUL termination at the end. */ - numRead = read(cmdFd, cmdLineTemp, sizeof cmdLineTemp - sizeof(char)); + numRead = ProcMgr_ReadProcFile(cmdFd, &cmdLineTemp); close(cmdFd); + if (numRead < 0) { + continue; + } + if (numRead > 0) { + /* + * Stop before we hit the final '\0'; want to leave it alone. + */ for (replaceLoop = 0 ; replaceLoop < (numRead - 1) ; replaceLoop++) { if ('\0' == cmdLineTemp[replaceLoop]) { cmdLineTemp[replaceLoop] = ' '; @@ -326,17 +416,11 @@ ProcMgr_ListProcesses(void) cmdFd = open(cmdFilePath, O_RDONLY); } if (cmdFd != -1) { - numRead = read(cmdFd, cmdLineTemp, sizeof(cmdLineTemp) - sizeof(char)); + numRead = ProcMgr_ReadProcFile(cmdFd, &cmdLineTemp); close(cmdFd); - - if (numRead < 0) { - cmdLineTemp[0] = '\0'; - } else { - cmdLineTemp[numRead] = '\0'; - } } if (numRead > 0) { - /* + /* * Extract the part with just the name, by reading until the first * space, then reading the next non-space word after that, and * ignoring everything else. The format looks like this: @@ -344,8 +428,8 @@ ProcMgr_ListProcesses(void) * for example: * "Name: nfsd" */ - const char* nameStart = NULL; - char* copyItr = NULL; + const char *nameStart; + char *copyItr; /* Skip non-whitespace. */ for (nameStart = cmdLineTemp; *nameStart && @@ -365,21 +449,6 @@ ProcMgr_ListProcesses(void) } } - /* - * There is an edge case where /proc/#/cmdline does not NUL terminate - * the command. /sbin/init (process 1) is like that on some distros. - * So let's guarantee that the string is NUL terminated, even if - * the last character of the string might already be NUL. - * This is safe to do because we read at most (sizeof cmdLineTemp) - 1 - * bytes from /proc/#/cmdline -- we left just enough space to add - * NUL termination at the end. - */ - if (numRead < 0) { - cmdLineTemp[0] = '\0'; - } else { - cmdLineTemp[numRead] = '\0'; - } - /* * Get the inode information for this process. This gives us * the process owner. @@ -389,7 +458,7 @@ ProcMgr_ListProcesses(void) "/proc/%s", ent->d_name) == -1) { Debug("Giant process id '%s'\n", ent->d_name); - continue; + goto next_entry; } /* @@ -399,7 +468,7 @@ ProcMgr_ListProcesses(void) */ statResult = stat(cmdFilePath, &fileStat); if (0 != statResult) { - continue; + goto next_entry; } /* @@ -411,22 +480,22 @@ ProcMgr_ListProcesses(void) "/proc/%s/stat", ent->d_name) == -1) { Debug("Giant process id '%s'\n", ent->d_name); - continue; + goto next_entry; } cmdFd = open(cmdFilePath, O_RDONLY); if (-1 == cmdFd) { - continue; + goto next_entry; } - numRead = read(cmdFd, cmdStatTemp, sizeof cmdStatTemp); + numRead = ProcMgr_ReadProcFile(cmdFd, &cmdStatTemp); close(cmdFd); if (0 >= numRead) { - continue; + goto next_entry; } /* * Skip over initial process id and process name. "123 (bash) [...]". */ stringBegin = strchr(cmdStatTemp, ')') + 2; - + numberFound = sscanf(stringBegin, "%c %d %d %d %d %d " "%lu %lu %lu %lu %lu %Lu %Lu %Lu %Lu %ld %ld " "%d %ld %Lu", @@ -443,14 +512,18 @@ ProcMgr_ListProcesses(void) (int *) &dummy, (long *) &dummy, &relativeStartTime); if (20 != numberFound) { - continue; + goto next_entry; } processStartTime = hostStartTime + (relativeStartTime / hertz); /* * Store the command line string pointer in dynbuf. */ - cmdLine = strdup(cmdLineTemp); + if (cmdLineTemp) { + cmdLine = Unicode_Alloc(cmdLineTemp, STRING_ENCODING_DEFAULT); + } else { + cmdLine = Unicode_Alloc("", STRING_ENCODING_UTF8); + } DynBuf_Append(&dbProcCmd, &cmdLine, sizeof cmdLine); /* @@ -465,7 +538,7 @@ ProcMgr_ListProcesses(void) pwd = getpwuid(fileStat.st_uid); userName = (NULL == pwd) ? Str_Asprintf(&strLen, "%d", (int) fileStat.st_uid) - : Util_SafeStrdup(pwd->pw_name); + : Unicode_Alloc(pwd->pw_name, STRING_ENCODING_DEFAULT); DynBuf_Append(&dbProcOwner, &userName, sizeof userName); /* @@ -474,6 +547,10 @@ ProcMgr_ListProcesses(void) DynBuf_Append(&dbProcStartTime, &processStartTime, sizeof processStartTime); + +next_entry: + free(cmdLineTemp); + free(cmdStatTemp); } // while readdir closedir(dir); diff --git a/open-vm-tools/lib/procMgr/procMgrSolaris.c b/open-vm-tools/lib/procMgr/procMgrSolaris.c index 3886dd5d0..478b704e8 100644 --- a/open-vm-tools/lib/procMgr/procMgrSolaris.c +++ b/open-vm-tools/lib/procMgr/procMgrSolaris.c @@ -174,12 +174,19 @@ ProcMgr_ListProcesses(void) * ExtractCommandLineFromAddressSpaceFile for every process. */ if (strlen(procInfo.pr_psargs) + 1 == PRARGSZ) { - cmdLineTemp = ExtractCommandLineFromAddressSpaceFile(&procInfo); - if(cmdLineTemp == NULL) { - cmdLineTemp = Util_SafeStrdup(procInfo.pr_psargs); + char *tmp; + + tmp = ExtractCommandLineFromAddressSpaceFile(&procInfo); + if (tmp != NULL) { + cmdLineTemp = Unicode_Alloc(tmp, STRING_ENCODING_DEFAULT); + free(tmp); + } else { + cmdLineTemp = Unicode_Alloc(procInfo.pr_psargs, + STRING_ENCODING_DEFAULT); } } else { - cmdLineTemp = Util_SafeStrdup(procInfo.pr_psargs); + cmdLineTemp = Unicode_Alloc(procInfo.pr_psargs, + STRING_ENCODING_DEFAULT); } /* @@ -199,7 +206,7 @@ ProcMgr_ListProcesses(void) pwd = getpwuid(procInfo.pr_uid); userName = (NULL == pwd) ? Str_Asprintf(&strLen, "%d", (int) procInfo.pr_uid) - : Util_SafeStrdup(pwd->pw_name); + : Unicode_Alloc(pwd->pw_name, STRING_ENCODING_DEFAULT); DynBuf_Append(&dbProcOwner, &userName, sizeof userName); /* diff --git a/open-vm-tools/modules/shared/vmxnet/vmnet_def.h b/open-vm-tools/modules/shared/vmxnet/vmnet_def.h index 139f538c6..0d4bb6cb8 100644 --- a/open-vm-tools/modules/shared/vmxnet/vmnet_def.h +++ b/open-vm-tools/modules/shared/vmxnet/vmnet_def.h @@ -40,6 +40,7 @@ #define _VMNET_DEF_H_ #define INCLUDE_ALLOW_USERLEVEL +#define INCLUDE_ALLOW_VMCORE #define INCLUDE_ALLOW_MODULE #define INCLUDE_ALLOW_VMK_MODULE @@ -47,6 +48,8 @@ #define INCLUDE_ALLOW_DISTRIBUTE #include "includeCheck.h" +#define VMNET_NAME_BUFFER_LEN 128 /* Increased for i18n. */ + /* * capabilities - not all of these are implemented in the virtual HW * (eg VLAN support is in the virtual switch) so even vlance diff --git a/open-vm-tools/services/plugins/dndcp/copyPasteDnDWrapper.cpp b/open-vm-tools/services/plugins/dndcp/copyPasteDnDWrapper.cpp index 41d8b5917..43c3d9849 100644 --- a/open-vm-tools/services/plugins/dndcp/copyPasteDnDWrapper.cpp +++ b/open-vm-tools/services/plugins/dndcp/copyPasteDnDWrapper.cpp @@ -26,9 +26,6 @@ #define G_LOG_DOMAIN "dndcp" -#include "copyPasteDnDWrapper.h" -#include "guestDnDCPMgr.hh" - #if defined(HAVE_GTKMM) #include "copyPasteDnDX11.h" #endif @@ -41,6 +38,9 @@ #include "copyPasteDnDMac.h" #endif +#include "copyPasteDnDWrapper.h" +#include "guestDnDCPMgr.hh" + extern "C" { #include "vmware.h" #include "rpcout.h" diff --git a/open-vm-tools/services/plugins/dndcp/dnd/dndCPLibExport.hh b/open-vm-tools/services/plugins/dndcp/dnd/dndCPLibExport.hh index 0528f7a7b..23b10efe9 100644 --- a/open-vm-tools/services/plugins/dndcp/dnd/dndCPLibExport.hh +++ b/open-vm-tools/services/plugins/dndcp/dnd/dndCPLibExport.hh @@ -26,6 +26,9 @@ #define DND_CP_LIB_EXPORT_HH #if defined VMX86_TOOLS || COMPILE_WITHOUT_CUI +# ifdef LIB_EXPORT +# undef LIB_EXPORT +# endif #define LIB_EXPORT #else #include "libExport.hh"