]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Save the native environment in vmtoolsd.
authorVMware, Inc <>
Thu, 15 Oct 2009 21:01:14 +0000 (14:01 -0700)
committerMarcelo Vanzin <mvanzin@vmware.com>
Thu, 15 Oct 2009 21:01:14 +0000 (14:01 -0700)
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 <mvanzin@vmware.com>
open-vm-tools/lib/include/vmtoolsApp.h
open-vm-tools/services/vmtoolsd/mainLoop.c
open-vm-tools/services/vmtoolsd/mainPosix.c

index 9c264f12f2528afef5cfdd039cb764499228d867..ded1446f8bbc58d208d85687226825f1aad63ec9 100644 (file)
@@ -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
index bb6faf27f9b7fdb9afb1910466b35790d22a4b42..892187bf0ca2d7bb4b9e3aa960d3f1356969e1d0 100644 (file)
@@ -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;
index 710b96b1a30eb980bfe3d6beb770e3559fa1a4c1..0f2c133250c3e2cc10ad7bd038d07eed7928e29f 100644 (file)
@@ -29,7 +29,9 @@
 #include <unistd.h>
 #include <glib/gstdio.h>
 #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);