]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
desktopEvents: Tell the session manager it should not start us when relaunching a...
authorVMware, Inc <>
Tue, 29 Mar 2011 20:18:50 +0000 (13:18 -0700)
committerMarcelo Vanzin <mvanzin@vmware.com>
Tue, 29 Mar 2011 20:18:50 +0000 (13:18 -0700)
A session as defined by an X Session Manager is a collection of applications and
some state such that this collection may be recreated arbitrarily in the future.
For example, a developer may define a development session consisting of an
instance of Emacs and a web browser pointing to some documentation.  Rather than
relaunch both apps upon each login, s/he could define a "happyfundev" session
and select that to launch that collection of apps at any time.

One requirement of being managed by a session manager is that one must provide
add'l metadata to the session manager to support this restart/restore case.
However, when the session manager relaunches applications as part of a recorded
session, it doesn't record anything about the environment -- instead, each
application must persist as much of the environment it needs by itself.

In our case, we rely on the environment set up by (ironically) the session
manager during its autostart phase in order to launch correctly.  (E.g., we
rely on environment variables like KDE_FULL_SESSION to determine that we're
running under KDE.)  Since vmusr gains nothing from being restartable via the
session manager, we'd rather inform the session manager NOT to restore vmusr
as part of any desktop session.  Instead, it should continue to only launch
as part of the XDG autostart phase.

Without doing this, there is a race between two instances of vmusr launching:
one from the autostart phase and one from the session restore phase.  If the
session restore instance wins, things break.

Signed-off-by: Marcelo Vanzin <mvanzin@vmware.com>
open-vm-tools/services/plugins/desktopEvents/sessionMgr.c

index 0c2a7d065f9018f36e5ec67419fb620822d8beb1..1077c02d4df6cf1ee07d9809cfa5cdf9e9ec4ec7 100644 (file)
@@ -50,6 +50,7 @@
 
 #include <errno.h>
 #include <glib.h>
+#include <pwd.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
@@ -65,6 +66,7 @@
 
 
 static void InitSignals(ToolsAppCtx* ctx);
+static void InitSMProperties(SmcConn smcCnx);
 
 
 /*
@@ -141,6 +143,7 @@ SessionMgr_Init(ToolsAppCtx *ctx,
                         &smCallbacks, NULL, &clientID, sizeof errorBuf, errorBuf);
    if (smcCnx != NULL) {
       InitSignals(ctx);
+      InitSMProperties(smcCnx);
       g_hash_table_insert(pdata->_private, DE_FEATURE_KEY, smcCnx);
       g_debug("Registered with session manager as %s\n", clientID);
       free(clientID);
@@ -248,6 +251,63 @@ InitSignals(ToolsAppCtx *ctx)
 }
 
 
+/*
+ ******************************************************************************
+ * InitSMProperties --                                                   */ /**
+ *
+ * Tell the session manager a little bit about ourself.
+ *
+ * The most important property to us is SmRestartStyleHint, where we hint to
+ * the session manager that it shouldn't attempt to restore the vmusr container
+ * as part of a session.  (Instead, that job is handled by our XDG autostart
+ * entry.)
+ *
+ * The other properties are set only because SMlib docs claim they're
+ * mandatory.  Dummy values are used where possible.
+ *
+ * @param[in]  smcCnx   SM client connection.
+ *
+ ******************************************************************************
+ */
+
+static void
+InitSMProperties(SmcConn smcCnx)
+{
+   enum {
+      PROP_ID_CLONE_CMD,
+      PROP_ID_PROGRAM,
+      PROP_ID_RESTART_CMD,
+      PROP_ID_RESTART_STYLE,
+      PROP_ID_USER_ID,
+   };
+   static uint8 restartHint = SmRestartNever;
+   static SmPropValue values[] = {
+      { sizeof "/bin/false" - 1, "/bin/false" },
+      { sizeof "vmware-user" - 1, "vmware-user" },
+      { sizeof "/bin/false" - 1, "/bin/false" },
+      { sizeof restartHint, &restartHint },
+      { 0, NULL },
+   };
+   static SmProp properties[] = {
+      { SmCloneCommand, SmLISTofARRAY8, 1, &values[PROP_ID_CLONE_CMD] },
+      { SmProgram, SmARRAY8, 1, &values[PROP_ID_PROGRAM] },
+      { SmRestartCommand, SmLISTofARRAY8, 1, &values[PROP_ID_RESTART_CMD] },
+      { SmRestartStyleHint, SmCARD8, 1, &values[PROP_ID_RESTART_STYLE] },
+      { SmUserID, SmARRAY8, 1, &values[PROP_ID_USER_ID] },
+   };
+   static SmProp *propp[] = {
+      &properties[0], &properties[1], &properties[2], &properties[3],
+      &properties[4]
+   };
+
+   struct passwd *pw = getpwuid(getuid());
+   values[PROP_ID_USER_ID].length = strlen(pw->pw_name);
+   values[PROP_ID_USER_ID].value = pw->pw_name;
+
+   SmcSetProperties(smcCnx, ARRAYSIZE(propp), (SmProp**)propp);
+}
+
+
 /*
  ******************************************************************************
  * BEGIN libICE stuff.