From: VMware, Inc <> Date: Thu, 15 Oct 2009 21:01:14 +0000 (-0700) Subject: Save the native environment in vmtoolsd. X-Git-Tag: 2009.10.15-201664~29 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=eb9293a2d74cd12dc6673fa2287499e5f22a4b1e;p=thirdparty%2Fopen-vm-tools.git Save the native environment in vmtoolsd. Save the native environment so that applications that need to execute sub-processes using it are able to retrieve it. For that, make it available in the application context structure. Signed-off-by: Marcelo Vanzin --- diff --git a/open-vm-tools/lib/include/vmtoolsApp.h b/open-vm-tools/lib/include/vmtoolsApp.h index 9c264f12f..ded1446f8 100644 --- a/open-vm-tools/lib/include/vmtoolsApp.h +++ b/open-vm-tools/lib/include/vmtoolsApp.h @@ -186,6 +186,8 @@ typedef struct ToolsAppCtx { #else /** The FD to access the VMware blocking fs. -1 if no FD available. */ int blockFD; + /** The native environment (without any VMware modifications). */ + const char **envp; #endif /** * A GObject instance shared among all plugins. The object itself doesn't diff --git a/open-vm-tools/services/vmtoolsd/mainLoop.c b/open-vm-tools/services/vmtoolsd/mainLoop.c index bb6faf27f..892187bf0 100644 --- a/open-vm-tools/services/vmtoolsd/mainLoop.c +++ b/open-vm-tools/services/vmtoolsd/mainLoop.c @@ -35,6 +35,7 @@ #include "conf.h" #include "guestApp.h" #include "serviceObj.h" +#include "system.h" #include "util.h" #include "vm_app.h" #include "vmcheck.h" @@ -121,6 +122,13 @@ ToolsCore_Cleanup(ToolsServiceState *state) state->debugLib = NULL; } +#if !defined(_WIN32) + if (state->ctx.envp) { + System_FreeNativeEnviron(state->ctx.envp); + state->ctx.envp = NULL; + } +#endif + g_object_unref(state->ctx.serviceObj); state->ctx.serviceObj = NULL; state->ctx.config = NULL; diff --git a/open-vm-tools/services/vmtoolsd/mainPosix.c b/open-vm-tools/services/vmtoolsd/mainPosix.c index 710b96b1a..0f2c13325 100644 --- a/open-vm-tools/services/vmtoolsd/mainPosix.c +++ b/open-vm-tools/services/vmtoolsd/mainPosix.c @@ -29,7 +29,9 @@ #include #include #include "file.h" +#include "guestApp.h" #include "hostinfo.h" +#include "system.h" #include "unicode.h" #include "util.h" #include "vmtools.h" @@ -105,13 +107,15 @@ ToolsCoreSigUsrHandler(const siginfo_t *info, * * @param[in] argc Argument count. * @param[in] argv Argument array. + * @param[in] envp User environment. * * @return 0 on successful execution, error code otherwise. */ int main(int argc, - char *argv[]) + char *argv[], + const char *envp[]) { int i; int ret = EXIT_FAILURE; @@ -212,6 +216,13 @@ main(int argc, VMTOOLSAPP_ATTACH_SOURCE(&gState.ctx, src, ToolsCoreSigUsrHandler, NULL, NULL); g_source_unref(src); + /* + * Save the original environment so that we can safely spawn other + * applications (since we may have to modify the original environment + * to launch vmtoolsd successfully). + */ + gState.ctx.envp = System_GetNativeEnviron(envp); + ret = ToolsCore_Run(&gState); ToolsCore_Cleanup(&gState);