Index: /trunk/doc/manual/en_US/SDKRef.xml
===================================================================
--- /trunk/doc/manual/en_US/SDKRef.xml	(revision 55799)
+++ /trunk/doc/manual/en_US/SDKRef.xml	(revision 55800)
@@ -3942,4 +3942,11 @@
           DVD images, and (less obviously) further API functionality
           such as cloning floppy images.</para>
+        </listitem>
+
+        <listitem>
+          <para>The attribute <computeroutput>IMachine::sessionType</computeroutput>
+          has been renamed to <xref linkend="IMachine__sessionName"
+          xreflabel="IMachine::sessionName()" />. This cleans up the confusing
+          terminology (as the session type is something different).</para>
         </listitem>
 
Index: /trunk/src/VBox/Frontends/VBoxHeadless/VBoxHeadless.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VBoxHeadless/VBoxHeadless.cpp	(revision 55799)
+++ /trunk/src/VBox/Frontends/VBoxHeadless/VBoxHeadless.cpp	(revision 55800)
@@ -911,4 +911,6 @@
               Utf8Str(id).c_str()));
 
+        // set session name
+        CHECK_ERROR_BREAK(session, COMSETTER(Name)(Bstr("headless").raw()));
         // open a session
         CHECK_ERROR_BREAK(m, LockMachine(session, LockType_VM));
Index: /trunk/src/VBox/Frontends/VBoxManage/VBoxManageInfo.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VBoxManage/VBoxManageInfo.cpp	(revision 55799)
+++ /trunk/src/VBox/Frontends/VBoxManage/VBoxManageInfo.cpp	(revision 55800)
@@ -1679,12 +1679,12 @@
         if (SUCCEEDED(rc) && sessState != SessionState_Unlocked)
         {
-            Bstr sessType;
-            rc = machine->COMGETTER(SessionType)(sessType.asOutParam());
-            if (SUCCEEDED(rc) && !sessType.isEmpty())
+            Bstr sessName;
+            rc = machine->COMGETTER(SessionName)(sessName.asOutParam());
+            if (SUCCEEDED(rc) && !sessName.isEmpty())
             {
                 if (details == VMINFO_MACHINEREADABLE)
-                    RTPrintf("SessionType=\"%ls\"\n", sessType.raw());
-                else
-                    RTPrintf("Session type:    %ls\n", sessType.raw());
+                    RTPrintf("SessionName=\"%ls\"\n", sessName.raw());
+                else
+                    RTPrintf("Session name:    %ls\n", sessName.raw());
             }
         }
Index: /trunk/src/VBox/Frontends/VBoxSDL/VBoxSDL.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VBoxSDL/VBoxSDL.cpp	(revision 55799)
+++ /trunk/src/VBox/Frontends/VBoxSDL/VBoxSDL.cpp	(revision 55800)
@@ -6,5 +6,5 @@
 
 /*
- * Copyright (C) 2006-2014 Oracle Corporation
+ * Copyright (C) 2006-2015 Oracle Corporation
  *
  * This file is part of VirtualBox Open Source Edition (OSE), as
@@ -1557,4 +1557,5 @@
     else
     {
+        pSession->COMSETTER(Name)(Bstr("GUI/SDL").raw());
         rc = pMachine->LockMachine(pSession, LockType_VM);
     }
Index: /trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp	(revision 55799)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp	(revision 55800)
@@ -1476,4 +1476,7 @@
             break;
         }
+
+        if (lockType == KLockType_VM)
+            session.SetName("GUI/Qt");
 
         /* Lock found machine to session: */
Index: /trunk/src/VBox/Frontends/VirtualBox/src/selector/UIVMItem.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/selector/UIVMItem.cpp	(revision 55799)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/selector/UIVMItem.cpp	(revision 55800)
@@ -5,5 +5,5 @@
 
 /*
- * Copyright (C) 2006-2012 Oracle Corporation
+ * Copyright (C) 2006-2015 Oracle Corporation
  *
  * This file is part of VirtualBox Open Source Edition (OSE), as
@@ -483,11 +483,10 @@
         if (!session.isNull())
         {
-            /* Acquire the session type: */
-            const QString strSessionType = session.GetMachine().GetSessionType();
+            /* Acquire the session name: */
+            const QString strSessionName = session.GetMachine().GetSessionName();
             /* Close the session early: */
             session.UnlockMachine();
-            /* Check whether we are in 'headless' session type: */
-            if (strSessionType.compare("headless", Qt::CaseInsensitive) == 0)
-                return true;
+            /* Check whether we are in 'headless' session: */
+            return strSessionName == "headless";
         }
     }
Index: /trunk/src/VBox/Main/idl/VirtualBox.xidl
===================================================================
--- /trunk/src/VBox/Main/idl/VirtualBox.xidl	(revision 55799)
+++ /trunk/src/VBox/Main/idl/VirtualBox.xidl	(revision 55800)
@@ -4170,5 +4170,5 @@
   <interface
     name="IMachine" extends="$unknown"
-    uuid="701464d0-7284-42e9-b7b3-894cf31536b7"
+    uuid="77a44043-a68a-4ef9-ac26-e9567b1e6bbc"
     wsmap="managed"
     wrap-hint-server-addinterfaces="IInternalMachineControl"
@@ -4670,12 +4670,13 @@
     </attribute>
 
-    <attribute name="sessionType" type="wstring" readonly="yes">
-      <desc>
-        Type of the session. If <link to="#sessionState"/> is
+    <attribute name="sessionName" type="wstring" readonly="yes">
+      <desc>
+        Name of the session. If <link to="#sessionState"/> is
         Spawning or Locked, this attribute contains the
         same value as passed to the
         <link to="IMachine::launchVMProcess"/> method in the
-        @a type parameter. If the session was used with
-        <link to="IMachine::lockMachine" />, or if
+        @a name parameter. If the session was established with
+        <link to="IMachine::lockMachine" />, it is the name of the session
+        (if set, otherwise empty string). If
         <link to="#sessionState"/> is SessionClosed, the value of this
         attribute is an empty string.
@@ -5191,5 +5192,5 @@
         </desc>
       </param>
-      <param name="type" type="wstring" dir="in">
+      <param name="name" type="wstring" dir="in">
         <desc>
           Front-end to use for the new VM process. The following are currently supported:
@@ -19266,5 +19267,5 @@
   <interface
     name="ISession" extends="$unknown"
-    uuid="12F4DCDB-12B2-4EC1-B7CD-DDD9F6C5BF4D"
+    uuid="3d4f472c-aac8-4387-94be-54042bcd8901"
     wsmap="managed"
     wrap-hint-server-addinterfaces="IInternalSessionControl"
@@ -19339,4 +19340,15 @@
     </attribute>
 
+    <attribute name="name" type="wstring">
+      <desc>
+        Name of this session. Important only for VM sessions, otherwise it
+        it will be remembered, but not used for anything significant (and can
+        be left at the empty string which is the default). The value can only
+        be changed when the session state is SessionState_Unlocked. Make sure
+        that you use a descriptive name which does not conflict with the VM
+        process session names: "GUI/Qt", "GUI/SDL" and "headless".
+      </desc>
+    </attribute>
+
     <attribute name="machine" type="IMachine" readonly="yes">
       <desc>Machine object associated with this session.</desc>
@@ -19344,5 +19356,6 @@
 
     <attribute name="console" type="IConsole" readonly="yes">
-      <desc>Console object associated with this session.</desc>
+      <desc>Console object associated with this session. Only sessions
+      which locked the machine for a VM process have a non-null console.</desc>
     </attribute>
 
Index: /trunk/src/VBox/Main/include/MachineImpl.h
===================================================================
--- /trunk/src/VBox/Main/include/MachineImpl.h	(revision 55799)
+++ /trunk/src/VBox/Main/include/MachineImpl.h	(revision 55800)
@@ -149,6 +149,6 @@
             SessionState_T mState;
 
-            /** Session type string (for indirect sessions) */
-            Utf8Str mType;
+            /** Session name string (of the primary session) */
+            Utf8Str mName;
 
             /** Session machine object */
@@ -928,5 +928,6 @@
     HRESULT getSettingsModified(BOOL *aSettingsModified);
     HRESULT getSessionState(SessionState_T *aSessionState);
-    HRESULT getSessionType(com::Utf8Str &aSessionType);
+    HRESULT getSessionType(SessionType_T *aSessionType);
+    HRESULT getSessionName(com::Utf8Str &aSessionType);
     HRESULT getSessionPID(ULONG *aSessionPID);
     HRESULT getState(MachineState_T *aState);
Index: /trunk/src/VBox/Main/include/SessionImpl.h
===================================================================
--- /trunk/src/VBox/Main/include/SessionImpl.h	(revision 55799)
+++ /trunk/src/VBox/Main/include/SessionImpl.h	(revision 55800)
@@ -5,5 +5,5 @@
 
 /*
- * Copyright (C) 2006-2014 Oracle Corporation
+ * Copyright (C) 2006-2015 Oracle Corporation
  *
  * This file is part of VirtualBox Open Source Edition (OSE), as
@@ -57,4 +57,6 @@
     HRESULT getState(SessionState_T *aState);
     HRESULT getType(SessionType_T *aType);
+    HRESULT getName(com::Utf8Str &aName);
+    HRESULT setName(const com::Utf8Str &aName);
     HRESULT getMachine(ComPtr<IMachine> &aMachine);
     HRESULT getConsole(ComPtr<IConsole> &aConsole);
@@ -143,4 +145,5 @@
     SessionState_T mState;
     SessionType_T mType;
+    Utf8Str mName;
 
     ComPtr<IInternalMachineControl> mControl;
Index: /trunk/src/VBox/Main/src-client/SessionImpl.cpp
===================================================================
--- /trunk/src/VBox/Main/src-client/SessionImpl.cpp	(revision 55799)
+++ /trunk/src/VBox/Main/src-client/SessionImpl.cpp	(revision 55800)
@@ -5,5 +5,5 @@
 
 /*
- * Copyright (C) 2006-2014 Oracle Corporation
+ * Copyright (C) 2006-2015 Oracle Corporation
  *
  * This file is part of VirtualBox Open Source Edition (OSE), as
@@ -149,4 +149,23 @@
 
     *aType = mType;
+    return S_OK;
+}
+
+HRESULT Session::getName(com::Utf8Str &aName)
+{
+    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
+
+    aName = mName;
+    return S_OK;
+}
+
+HRESULT Session::setName(const com::Utf8Str &aName)
+{
+    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
+
+    if (mState != SessionState_Unlocked)
+        return setError(VBOX_E_INVALID_OBJECT_STATE, tr("Trying to set name for a session which is not in state \"unlocked\""));
+
+    mName = aName;
     return S_OK;
 }
Index: /trunk/src/VBox/Main/src-server/MachineImpl.cpp
===================================================================
--- /trunk/src/VBox/Main/src-server/MachineImpl.cpp	(revision 55799)
+++ /trunk/src/VBox/Main/src-server/MachineImpl.cpp	(revision 55800)
@@ -2674,5 +2674,4 @@
 HRESULT Machine::getSessionState(SessionState_T *aSessionState)
 {
-
     AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
 
@@ -2682,9 +2681,9 @@
 }
 
-HRESULT Machine::getSessionType(com::Utf8Str &aSessionType)
+HRESULT Machine::getSessionName(com::Utf8Str &aSessionName)
 {
     AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
 
-    aSessionType = mData->mSession.mType;
+    aSessionName = mData->mSession.mName;
 
     return S_OK;
@@ -3223,4 +3222,7 @@
                     E_INVALIDARG);
 
+    // session name (only used in some code paths)
+    Utf8Str strSessionName;
+
     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
 
@@ -3437,4 +3439,13 @@
                          tr("Failed to assign the machine to the session (%Rhrc)"), rc);
 
+            // get session name, either to remember or to compare against
+            // the already known session name.
+            {
+                Bstr bstrSessionName;
+                HRESULT rc2 = aSession->COMGETTER(Name)(bstrSessionName.asOutParam());
+                if (SUCCEEDED(rc2))
+                    strSessionName = bstrSessionName;
+            }
+
             if (    SUCCEEDED(rc)
                  && fLaunchingVMProcess
@@ -3485,4 +3496,5 @@
         if (fLaunchingVMProcess)
         {
+            Assert(mData->mSession.mName == strSessionName);
             /* Note that the progress object is finalized later */
             /** @todo Consider checking mData->mSession.mProgress for cancellation
@@ -3522,4 +3534,6 @@
             mData->mSession.mDirectControl = pSessionControl;
             mData->mSession.mState = SessionState_Locked;
+            if (!fLaunchingVMProcess)
+                mData->mSession.mName = strSessionName;
             /* associate the SessionMachine with this Machine */
             mData->mSession.mMachine = sessionMachine;
@@ -3561,9 +3575,9 @@
  */
 HRESULT Machine::launchVMProcess(const ComPtr<ISession> &aSession,
-                                 const com::Utf8Str &aType,
+                                 const com::Utf8Str &aName,
                                  const com::Utf8Str &aEnvironment,
                                  ComPtr<IProgress> &aProgress)
 {
-    Utf8Str strFrontend(aType);
+    Utf8Str strFrontend(aName);
     /* "emergencystop" doesn't need the session, so skip the checks/interface
      * retrieval. This code doesn't quite fit in here, but introducing a
@@ -7430,5 +7444,5 @@
     if (fSeparate)
     {
-        if (mData->mSession.mState != SessionState_Unlocked && mData->mSession.mType.compare("headless", Utf8Str::CaseInsensitive))
+        if (mData->mSession.mState != SessionState_Unlocked && mData->mSession.mName == "headless")
             return setError(VBOX_E_INVALID_OBJECT_STATE,
                             tr("The machine '%s' is in a state which is incompatible with launching a separate UI process"),
@@ -7531,4 +7545,5 @@
 #endif
 
+    Utf8Str strCanonicalName;
 
 #ifdef VBOX_WITH_QTGUI
@@ -7539,4 +7554,5 @@
         || !strFrontend.compare("GUI/Qt/separate", Utf8Str::CaseInsensitive))
     {
+        strCanonicalName = "GUI/Qt";
 # ifdef RT_OS_DARWIN /* Avoid Launch Services confusing this with the selector by using a helper app. */
         /* Modify the base path so that we don't need to use ".." below. */
@@ -7607,4 +7623,5 @@
         || !strFrontend.compare("GUI/SDL/separate", Utf8Str::CaseInsensitive))
     {
+        strCanonicalName = "GUI/SDL";
         static const char s_szVBoxSDL_exe[] = "VBoxSDL" HOSTSUFF_EXE;
         Assert(cchBufLeft >= sizeof(s_szVBoxSDL_exe));
@@ -7641,4 +7658,5 @@
        )
     {
+        strCanonicalName = "headless";
         /* On pre-4.0 the "headless" type was used for passing "--vrdp off" to VBoxHeadless to let it work in OSE,
          * which did not contain VRDP server. In VBox 4.0 the remote desktop server (VRDE) is optional,
@@ -7732,5 +7750,6 @@
         mData->mSession.mPID = pid;
         mData->mSession.mState = SessionState_Spawning;
-        mData->mSession.mType = strFrontend;
+        Assert(strCanonicalName.isNotEmpty());
+        mData->mSession.mName = strCanonicalName;
     }
     else
@@ -12654,5 +12673,5 @@
     mData->mSession.mMachine.setNull();
     mData->mSession.mState = SessionState_Unlocked;
-    mData->mSession.mType.setNull();
+    mData->mSession.mName.setNull();
 
     /* destroy the machine client token before leaving the exclusive lock */
