VirtualBox

Changeset 4064 in vbox


Ignore:
Timestamp:
Aug 7, 2007 2:19:46 PM (18 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
23501
Message:

Main/Frontends: Pass the value of the DISPLAY variable of the starting application to the VM process (#2101).

Location:
trunk/src/VBox
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManage.cpp

    r3917 r4064  
    42364236        }
    42374237
     4238        Bstr env;
     4239#ifdef RT_OS_LINUX
     4240        /* make sure the VM process will start on the same display as VBoxManage */
     4241        env = Utf8StrFmt ("DISPLAY=%s", getenv ("DISPLAY"));
     4242#endif
    42384243        ComPtr<IProgress> progress;
    4239         CHECK_ERROR_RET(virtualBox, OpenRemoteSession(session, uuid, sessionType, progress.asOutParam()), rc);
     4244        CHECK_ERROR_RET(virtualBox, OpenRemoteSession(session, uuid, sessionType,
     4245                                                      env, progress.asOutParam()), rc);
    42404246        RTPrintf("Waiting for the remote session to open...\n");
    42414247        CHECK_ERROR_RET(progress, WaitForCompletion (-1), 1);
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxSelectorWnd.cpp

    r3802 r4064  
    848848#endif
    849849
    850     CProgress progress = vbox.OpenRemoteSession (session, id, "gui");
     850    QString env;
     851#if defined (Q_WS_X11)
     852    /* make sure the VM process will start on the same display as the Selector */
     853    env.sprintf ("DISPLAY=%s", getenv ("DISPLAY"));
     854#endif
     855
     856    CProgress progress = vbox.OpenRemoteSession (session, id, "gui", env);
    851857    if (!vbox.isOk())
    852858    {
  • trunk/src/VBox/Main/MachineImpl.cpp

    r4041 r4064  
    5252#include <stdio.h>
    5353#include <stdlib.h>
    54 #include <VBox/err.h>
    55 #include <VBox/cfgldr.h>
     54
    5655#include <iprt/path.h>
    5756#include <iprt/dir.h>
     
    5958#include <iprt/process.h>
    6059#include <iprt/cpputils.h>
     60#include <iprt/env.h>
     61
     62#include <VBox/err.h>
     63#include <VBox/cfgldr.h>
    6164#include <VBox/param.h>
    6265
     
    27632766 */
    27642767HRESULT Machine::openRemoteSession (IInternalSessionControl *aControl,
    2765                                     INPTR BSTR aType, Progress *aProgress)
     2768                                    INPTR BSTR aType, INPTR BSTR aEnvironment,
     2769                                    Progress *aProgress)
    27662770{
    27672771    LogFlowThisFuncEnter();
     
    28042808    RTPROCESS pid = NIL_RTPROCESS;
    28052809
     2810    RTENV env = NIL_RTENV;
     2811
     2812    if (aEnvironment)
     2813    {
     2814        char *newEnvStr = NULL;
     2815
     2816        do
     2817        {
     2818            /* clone the current environment */
     2819            int vrc = RTEnvClone(&env, NULL);
     2820            AssertRCBreak (vrc, vrc = vrc);
     2821
     2822            vrc = RTStrUtf8ToCurrentCP (&newEnvStr, Utf8Str (aEnvironment));
     2823            AssertRCBreak (vrc, vrc = vrc);
     2824
     2825            /* put new variables to the environment
     2826             * (ignore empty variable names here since RTEnv API
     2827             * intentionally doesn't do that) */
     2828            char *var = newEnvStr;
     2829            for (char *p = newEnvStr; *p; ++ p)
     2830            {
     2831                if (*p == '\n' && (p == newEnvStr || *(p - 1) != '\\'))
     2832                {
     2833                    *p = '\0';
     2834                    if (*var)
     2835                        if (VBOX_FAILURE (vrc = RTEnvPutEx(env, var)))
     2836                            break;
     2837                    var = p + 1;
     2838                }
     2839            }
     2840            if (VBOX_SUCCESS (vrc) && *var)
     2841                vrc = RTEnvPutEx(env, var);
     2842
     2843            AssertRCBreak (vrc, vrc = vrc);
     2844        }
     2845        while (0);
     2846
     2847        if (newEnvStr != NULL)
     2848            RTStrFree(newEnvStr);
     2849    }
     2850
    28062851    Bstr type (aType);
    28072852    if (type == "gui")
     
    28222867        const char * args[] = {path, "-comment", name, "-startvm", idStr, 0 };
    28232868#endif
    2824         vrc = RTProcCreate (path, args, NULL, 0, &pid);
     2869        vrc = RTProcCreate (path, args, RTEnvGetArray (env), 0, &pid);
    28252870    }
    28262871    else
     
    28392884        const char * args[] = {path, "-comment", name, "-startvm", idStr, 0 };
    28402885#endif
    2841         vrc = RTProcCreate (path, args, NULL, 0, &pid);
     2886        vrc = RTProcCreate (path, args, RTEnvGetArray (env), 0, &pid);
    28422887    }
    28432888    else
     
    28562901        const char * args[] = {path, "-comment", name, "-startvm", idStr, "-capture", 0 };
    28572902#endif
    2858         vrc = RTProcCreate (path, args, NULL, 0, &pid);
     2903        vrc = RTProcCreate (path, args, RTEnvGetArray (env), 0, &pid);
    28592904    }
    28602905    else
    28612906    {
     2907        if (env != NIL_RTENV)
     2908            RTEnvDestroy (env);
    28622909        return setError (E_INVALIDARG,
    28632910            tr ("Invalid session type: '%ls'"), aType);
    28642911    }
     2912
     2913    if (env != NIL_RTENV)
     2914        RTEnvDestroy (env);
    28652915
    28662916    if (VBOX_FAILURE (vrc))
  • trunk/src/VBox/Main/VirtualBoxImpl.cpp

    r3668 r4064  
    19141914                                            INPTR GUIDPARAM aMachineId,
    19151915                                            INPTR BSTR aType,
     1916                                            INPTR BSTR aEnvironment,
    19161917                                            IProgress **aProgress)
    19171918{
     
    19511952                    FALSE /* aCancelable */);
    19521953
    1953     rc = machine->openRemoteSession (control, aType, progress);
     1954    rc = machine->openRemoteSession (control, aType, aEnvironment, progress);
    19541955
    19551956    if (SUCCEEDED (rc))
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r4041 r4064  
    664664  <interface
    665665     name="IVirtualBox" extends="$dispatched"
    666      uuid="d1a2295c-d257-4a4c-a9a6-843d87db6f45"
     666     uuid="76b25f3c-15d4-4785-a9d3-adc6a462beec"
    667667     wsmap="global"
    668668     >
     
    13821382    <method name="createSharedFolder">
    13831383      <desc>
    1384         Creates a new shared folder by associating the given logical name with
    1385         the given host path, adds it to the collection of shared folders and
    1386         starts sharing it. Refer to the description of
     1384        Creates a new global shared folder by associating the given logical
     1385        name with the given host path, adds it to the collection of shared
     1386        folders and starts sharing it. Refer to the description of
    13871387        <link to="ISharedFolder"/> to read more about logical names.
    13881388      </desc>
     
    13971397    <method name="removeSharedFolder">
    13981398      <desc>
    1399         Removes a shared folder with the given name previously created
    1400         by <link to="#createSharedFolder"/> from the collection of
     1399        Removes the global shared folder with the given name previously
     1400        created by <link to="#createSharedFolder"/> from the collection of
    14011401        shared folders and stops sharing it.
    14021402      </desc>
     
    14621462    <method name="openSession">
    14631463      <desc>
    1464         <p>Opens a new direct session with the given virtual machine.
    1465           Within the direct session context, it is possible to change
    1466           all VM settings, as well as to execute the VM in the process
    1467           space of the session object. There can be only one direct
    1468           session open at a time for every virtual machine.</p>
    1469         <p>Upon successful return, the session object can be used to
    1470           get access to the machine and to the VM console.
    1471         </p>
     1464        Opens a new direct session with the given virtual machine.
     1465
     1466        Within the direct session context, it is possible to change
     1467        all VM settings, as well as to execute the VM in the process
     1468        space of the session object. There can be only one direct
     1469        session open at a time for every virtual machine.
     1470     
     1471        Upon successful return, the session object can be used to
     1472        get access to the machine and to the VM console.
    14721473      </desc>
    14731474      <param name="session" type="ISession" dir="in">
     
    14891490    <method name="openRemoteSession">
    14901491      <desc>
    1491         <p>Opens a new remote session with the given virtual
    1492           machine. Opening the remote session causes the server to start
    1493           a new process that opens a direct session with the given VM.
    1494           The remote session provides some level of control over the VM
    1495           execution (using the IConsole interface) to the caller. Within
    1496           the remote session context, it is not possible to change any
    1497           static VM settings (such as name, HDD configuration, etc.).</p>
    1498         <p>This operation can take some time, so the progress object
    1499           is returned to let the caller be informed when the session is
    1500           actually open. Until then, the remote session object remains in
    1501           the closed state and accessing the machine or its console through
    1502           it is invalid.
    1503         </p>
     1492        Opens a new remote session with the given virtual
     1493        machine.
     1494
     1495        Opening a remote session causes the VirtualBox server to start a new
     1496        process that opens a direct session with the given VM.  The remote
     1497        session provides some level of control over the VM execution to the
     1498        caller (using the IConsole interface); however, within the remote
     1499        session context, not all VM settings are available for modification.
     1500       
     1501        This operation can take some time, so the progress object
     1502        is returned to let the caller be informed when the session is
     1503        actually open. Until then, the remote session object remains in
     1504        the closed state and accessing the machine or its console through
     1505        it is invalid.
    15041506
    15051507        Currently supported session types (values of the @a type
    1506         parameter) are:
     1508        argument) are:
    15071509        <ul>
    15081510          <li><tt>gui</tt>: VirtualBox Qt GUI session</li>
     
    15101512        </ul>
    15111513
    1512         <note>
    1513           It is impossible to open a remote session with the machine
     1514        The @a environment argument is a string containing definitions of
     1515        environment variables in the following format:
     1516        @code
     1517          NAME[=VALUE]\n
     1518          NAME[=VALUE]\n
     1519          ...
     1520        @endcode
     1521        where <tt>\\n</tt> is the new line character. These environment
     1522        variables will be appended to the environment of the VirtualBox server
     1523        process. If an environment variable exists both in the server process
     1524        and in this list, the value from this list takes precedence over the
     1525        server's variable. If the value of the environment variable is
     1526        omitted, this variable will be removed from the resulting environment.
     1527        If the environment string is @c null, the server environment is
     1528        inherited by the started process as is.
     1529
     1530        <note>
     1531          It is an error to open a remote session with the machine
    15141532          that already has an open direct session or waits until the
    15151533          previous request to open the remote session is completed
     
    15391557        </desc>
    15401558      </param>
     1559      <param name="environment" type="wstring" dir="in">
     1560        <desc>
     1561          Environment to pass to the opened session (may be @c null).
     1562        </desc>
     1563      </param>
    15411564      <param name="progress" type="IProgress" dir="return">
    15421565        <desc>Progress object to track the operation completion.</desc>
     
    15461569    <method name="openExistingSession">
    15471570      <desc>
    1548         <p>Opens a new remote session with the virtual machine for
    1549           which a direct session is already open.
    1550           The remote session provides some level of control over the VM
    1551           execution (using the IConsole interface) to the caller. Within
    1552           the remote session context, it is not possible to change any
    1553           static VM settings (such as name, HDD configuration, etc.).</p>
    1554         <p>As opposed to <link to="#openRemoteSession()"/>, the number of
    1555           remote sessions opened this way is not limited by the API.</p>
    1556         <note>
    1557           It is impossible to open a remote session with the machine
    1558           that doesn't have an open direct session.
    1559         </note>
     1571        Opens a new remote session with the virtual machine for
     1572        which a direct session is already open.
     1573
     1574        The remote session provides some level of control over the VM
     1575        execution (using the IConsole interface) to the caller; however,
     1576        within the remote session context, not all VM settings are available
     1577        for modification.
     1578
     1579        As opposed to <link to="#openRemoteSession()"/>, the number of
     1580        remote sessions opened this way is not limited by the API
     1581
     1582        <note>
     1583          It is an error to open a remote session with the machine that
     1584          doesn't have an open direct session.
     1585        </note>
     1586
    15601587        <see>openRemoteSession</see>
    15611588      </desc>
     
    26002627    <method name="createSharedFolder">
    26012628      <desc>
    2602         Creates a new shared folder by associating the given logical name with
    2603         the given host path, adds it to the collection of shared folders and
    2604         starts sharing it. Refer to the description of
     2629        Creates a new permanent shared folder by associating the given logical
     2630        name with the given host path, adds it to the collection of shared
     2631        folders and starts sharing it. Refer to the description of
    26052632        <link to="ISharedFolder"/> to read more about logical names.
    26062633      </desc>
     
    26152642    <method name="removeSharedFolder">
    26162643      <desc>
    2617         Removes a shared folder with the given name previously created
    2618         by <link to="#createSharedFolder"/> from the collection of
     2644        Removes the permanent shared folder with the given name previously
     2645        created by <link to="#createSharedFolder"/> from the collection of
    26192646        shared folders and stops sharing it.
    26202647      </desc>
     
    33173344    <method name="createSharedFolder">
    33183345      <desc>
    3319         Creates a new shared folder by associating the given logical name with
    3320         the given host path, adds it to the collection of shared folders and
    3321         starts sharing it. Refer to the description of
     3346        Creates a transient new shared folder by associating the given logical
     3347        name with the given host path, adds it to the collection of shared
     3348        folders and starts sharing it. Refer to the description of
    33223349        <link to="ISharedFolder"/> to read more about logical names.
    33233350      </desc>
     
    33323359    <method name="removeSharedFolder">
    33333360      <desc>
    3334         Removes a shared folder with the given name previously created
    3335         by <link to="#createSharedFolder"/> from the collection of
     3361        Removes a transient shared folder with the given name previously
     3362        created by <link to="#createSharedFolder"/> from the collection of
    33363363        shared folders and stops sharing it.
    33373364      </desc>
  • trunk/src/VBox/Main/include/MachineImpl.h

    r4041 r4064  
    543543    HRESULT openSession (IInternalSessionControl *aControl);
    544544    HRESULT openRemoteSession (IInternalSessionControl *aControl,
    545                                INPTR BSTR aType, Progress *aProgress);
     545                               INPTR BSTR aType, INPTR BSTR aEnvironment,
     546                               Progress *aProgress);
    546547    HRESULT openExistingSession (IInternalSessionControl *aControl);
    547548
  • trunk/src/VBox/Main/include/VirtualBoxImpl.h

    r3668 r4064  
    174174    STDMETHOD(OpenSession) (ISession *aSession, INPTR GUIDPARAM aMachineId);
    175175    STDMETHOD(OpenRemoteSession) (ISession *aSession, INPTR GUIDPARAM aMachineId,
    176                                   INPTR BSTR aType, IProgress **aProgress);
     176                                  INPTR BSTR aType, INPTR BSTR aEnvironment,
     177                                  IProgress **aProgress);
    177178    STDMETHOD(OpenExistingSession) (ISession *aSession, INPTR GUIDPARAM aMachineId);
    178179    STDMETHOD(RegisterCallback) (IVirtualBoxCallback *callback);
  • trunk/src/VBox/Main/testcase/tstAPI.cpp

    r3834 r4064  
    823823        ComPtr <IProgress> progress;
    824824        CHECK_RC_BREAK (virtualBox->OpenRemoteSession (session, guid, Bstr("gui"),
    825                                                        progress.asOutParam()));
     825                                                       NULL, progress.asOutParam()));
    826826        printf ("Waiting for the session to open...\n");
    827827        CHECK_RC_BREAK (progress->WaitForCompletion (-1));
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette