VirtualBox

Changeset 1471 in vbox for trunk


Ignore:
Timestamp:
Mar 14, 2007 2:59:04 PM (18 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
19531
Message:

Main: XPCOM: Initial implementation of auto-startable "out-of-proc" VirtualBox component (VBoxSVC).

Location:
trunk/src/VBox/Main
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/Makefile

    r1349 r1471  
    3838  $(error "VBox: VBOX_WITH_XPCOM isn't defined")
    3939 endif
     40 DLLS            = VBoxSVCM
    4041 LIBRARIES       = VBoxXPCOM
    4142 DEFS           += VBOX_WITH_XPCOM
     
    9495
    9596#
    96 # VBoxSVC
     97# VBoxSVC executable
    9798#
    9899VBoxSVC_TEMPLATE = VBOXMAINEXE
     
    198199
    199200#
    200 # VBoxC
     201# VBoxSVC wrapper module
     202#
     203ifdef VBOX_WITH_XPCOM
     204
     205VBoxSVCM_TEMPLATE               = VBOXMAIN
     206VBoxSVCM_DEFS                   = IN_RING3 IN_CFGLDR_R3
     207VBoxSVCM_INCS                   = \
     208        include \
     209        $(PATH_VBoxC) \
     210        $(PATH_VBoxCOM)
     211VBoxSVCM_SOURCES                = \
     212        linux/server_module.cpp
     213
     214endif # VBOX_WITH_XPCOM
     215
     216#
     217# VBoxC module
    201218#
    202219VBoxC_TEMPLATE = VBOXMAIN
     
    437454xpcom-components_SYMLINKS = \
    438455        VBoxC$(SUFF_DLL)=>../VBoxC$(SUFF_DLL) \
     456        VBoxSVCM$(SUFF_DLL)=>../VBoxSVCM$(SUFF_DLL) \
    439457        VBoxXPCOMIPCC$(SUFF_DLL)=>../VBoxXPCOMIPCC$(SUFF_DLL) \
    440458        VirtualBox_XPCOM.xpt=>../VirtualBox_XPCOM.xpt \
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r1218 r1471  
    6464    name="VirtualBox"
    6565    uuid="46137EEC-703B-4fe5-AFD4-7C9BBBBA0259"
    66     version="1.0"
    67     desc="InnoTek VirtualBox Machine Type Library"
     66    version="1.3"
     67    desc="InnoTek VirtualBox Type Library"
    6868    supportsErrorInfo="yes"
    6969>
     
    14731473    </interface>
    14741474
    1475     <class name="VirtualBox" uuid="B1A7A4F2-47B9-4A1E-82B2-07CCD5323C3F">
     1475    <class name="VirtualBox" uuid="B1A7A4F2-47B9-4A1E-82B2-07CCD5323C3F"
     1476           namespace="virtualbox.org">
    14761477        <interface name="IVirtualBox" default="yes"/>
    14771478    </class>
     
    72027203    </interface>
    72037204
    7204     <class name="Session" uuid="3C02F46D-C9D2-4f11-A384-53F0CF917214">
     7205    <class name="Session" uuid="3C02F46D-C9D2-4f11-A384-53F0CF917214"
     7206           namespace="virtualbox.org">
    72057207        <interface name="ISession" default="yes"/>
    72067208    </class>
  • trunk/src/VBox/Main/idl/xpidl.xsl

    r1142 r1471  
    291291        <xsl:with-param name="str" select="@name"/>
    292292    </xsl:call-template>
    293     <xsl:text>_CONTRACTID "@xpcom/</xsl:text><xsl:value-of select="@name"/>
    294     <xsl:text>;1"&#x0A;</xsl:text>
     293    <!-- Contract ID -->
     294    <xsl:text>_CONTRACTID &quot;@</xsl:text>
     295    <xsl:value-of select="@namespace"/>
     296    <xsl:text>/</xsl:text>
     297    <xsl:value-of select="@name"/>
     298    <xsl:text>;1&quot;&#x0A;</xsl:text>
    295299    <!-- CLSID_xxx declarations for XPCOM, for compatibility with Win32 -->
    296300    <xsl:text>// for compatibility with Win32&#x0A;</xsl:text>
  • trunk/src/VBox/Main/linux/module.cpp

    r436 r1471  
    2121
    2222#include <nsIGenericFactory.h>
    23 #include <VirtualBox_XPCOM.h>
    2423
    25 #include <GuestImpl.h>
    26 #include <KeyboardImpl.h>
    27 #include <MouseImpl.h>
    28 #include <DisplayImpl.h>
    29 #include <MachineDebuggerImpl.h>
    30 #include <USBDeviceImpl.h>
    31 #include <RemoteUSBDeviceImpl.h>
    32 #include <SharedFolderImpl.h>
    33 #include <FramebufferImpl.h>
    34 #include <ProgressImpl.h>
    35 #include <NetworkAdapterImpl.h>
     24// generated file
     25#include "VirtualBox_XPCOM.h"
    3626
    37 #include <SessionImpl.h>
    38 #include <ConsoleImpl.h>
    39 #include <ConsoleVRDPServer.h>
     27#include "GuestImpl.h"
     28#include "KeyboardImpl.h"
     29#include "MouseImpl.h"
     30#include "DisplayImpl.h"
     31#include "MachineDebuggerImpl.h"
     32#include "USBDeviceImpl.h"
     33#include "RemoteUSBDeviceImpl.h"
     34#include "SharedFolderImpl.h"
     35#include "FramebufferImpl.h"
     36#include "ProgressImpl.h"
     37#include "NetworkAdapterImpl.h"
     38
     39#include "SessionImpl.h"
     40#include "ConsoleImpl.h"
     41#include "ConsoleVRDPServer.h"
     42
     43#include "Logging.h"
    4044
    4145// XPCOM glue code unfolding
     
    7680
    7781/**
    78  *  Singleton class factory that holds the reference to the created instance
     82 *  Singleton class factory that holds a reference to the created instance
    7983 *  (preventing it from being destroyed) until the module is explicitly
    8084 *  unloaded by the XPCOM shutdown code.
     
    129133NS_GENERIC_FACTORY_CONSTRUCTOR_WITH_RC (Session)
    130134
     135
     136/**
     137 *  Component definition table.
     138 *  Lists all components defined in this module.
     139 */
    131140static const nsModuleComponentInfo components[] =
    132141{
    133142    {
    134         "Session component", NS_SESSION_CID, NS_SESSION_CONTRACTID,
    135         SessionConstructor,
     143        "Session component", // description
     144        NS_SESSION_CID, NS_SESSION_CONTRACTID, // CID/ContractID
     145        SessionConstructor, // constructor function
    136146        NULL, // registration function
    137147        NULL, // deregistration function
     
    139149//        SessionClassFactory::releaseInstance,
    140150        NULL, // destructor function
    141         NS_CI_INTERFACE_GETTER_NAME(Session),
     151        NS_CI_INTERFACE_GETTER_NAME(Session), // interfaces function
    142152        NULL, // language helper
    143         &NS_CLASSINFO_NAME(Session)
     153        &NS_CLASSINFO_NAME(Session) // global class info & flags
    144154    }
    145155};
    146156
    147 NS_IMPL_NSGETMODULE(SessionModule, components)
     157NS_IMPL_NSGETMODULE (VirtualBox_Client_Module, components)
    148158
  • trunk/src/VBox/Main/linux/server.cpp

    r1397 r1471  
    11/** @file
    22 *
    3  * XPCOM server module implementation
     3 * XPCOM server process start point
    44 */
    55
     
    3939#include <iprt/path.h>
    4040#include <iprt/critsect.h>
     41#include <iprt/timer.h>
     42
    4143#include <VBox/param.h>
    4244#include <VBox/version.h>
     
    187189////////////////////////////////////////////////////////////////////////////////
    188190
     191enum
     192{
     193    /* Delay before shutting down the VirtualBox server after the last
     194     * VirtualBox instance is released, in ms */
     195    VBoxSVC_ShutdownDelay = 5000,
     196};
     197
     198static bool gAutoShutdown = false;
     199
    189200static nsIEventQueue* gEventQ = nsnull;
    190201static PRBool volatile gKeepRunning = PR_TRUE;
     
    203214    virtual ~VirtualBoxClassFactory()
    204215    {
    205         Log (("VirtualBoxClassFactory: deleting VirtualBox...\n"));
     216        LogFlowFunc (("Deleting VirtualBox...\n"));
    206217
    207218        FinalRelease();
    208219        sInstance = 0;
    209220
    210         Log (("VirtualBoxClassFactory: VirtualBox object deleted.\n"));
     221        LogFlowFunc (("VirtualBox object deleted.\n"));
    211222        printf ("Informational: VirtualBox object deleted.\n");
     223
     224        /* Instruct the main event loop to terminate. Note that it's enough
     225         * to set gKeepRunning to false because we are on the main thread
     226         * already (i.e. no need to post events there). */
     227        if (gAutoShutdown)
     228            gKeepRunning = PR_FALSE;
    212229    }
    213230
    214231    NS_IMETHOD_(nsrefcnt) Release()
    215232    {
    216         // we overload Release() to guarantee the VirtualBox destructor is
    217         // always called on the main thread
     233        /* we overload Release() to guarantee the VirtualBox destructor is
     234         * always called on the main thread */
    218235
    219236        nsrefcnt count = VirtualBox::Release();
     
    221238        if (count == 1)
    222239        {
    223             // the last reference held by clients is being released
    224             // (see GetInstance())
     240            /* the last reference held by clients is being released
     241             * (see GetInstance()) */
    225242
    226243            PRBool onMainThread = PR_TRUE;
     
    230247            if (!onMainThread)
    231248            {
    232                 // post a destruction event to the main thread to release the
    233                 // extra reference added in GetInstance()
    234 
    235                 LogFlow (("VirtualBoxClassFactory: the last VirtualBox reference "
    236                           "is being released, scheduling the destruction...\n"));
    237 
    238                 PLEvent *ev = new PLEvent;
    239                 gEventQ->InitEvent (ev, NULL, DestructEventHandler,
    240                                               DestructEventDestructor);
    241                 nsresult rv = gEventQ->PostEvent (ev);
    242                 if (NS_FAILED (rv))
     249                LogFlowFunc (("Last VirtualBox instance was released, "
     250                              "scheduling server shutdown in %d ms...\n",
     251                              VBoxSVC_ShutdownDelay));
     252
     253                /* Start a shutdown timer to provide some delay */
     254                int vrc = RTTimerStart (sTimer, 0);
     255/// @todo uncomment when implemented
     256//                AssertRC (vrc);
     257                if (VBOX_FAILURE (vrc))
    243258                {
    244                     // this means we've been already stopped (for example
    245                     // by Ctrl-C). FactoryDestructor() (NS_ShutdownXPCOM())
    246                     // will do the job.
    247                     PL_DestroyEvent (ev);
     259                    /* failed to start the timer, post the shutdown event
     260                     * manually */
     261                    ShutdownTimer (NULL, NULL);
    248262                }
    249263            }
    250264            else
    251265            {
    252                 // Here we come if:
    253                 //
    254                 // a) gEventQ is 0 which means either FactoryDestructor() is called
    255                 //    or the IPC/DCONNECT shutdown sequence is initiated by the
    256                 //    XPCOM shutdown routine (NS_ShutdownXPCOM()), which always
    257                 //    happens on the main thread.
    258                 //
    259                 // b) gEventQ has reported we're on the main thread. This means
    260                 //    that DestructEventHandler() has been called, but another
    261                 //    client was faster and requested VirtualBox again.
    262                 //
    263                 // We have nothing to do in these cases.
     266                /* Here we come if:
     267                 *
     268                 * a) gEventQ is 0 which means either FactoryDestructor() is called
     269                 *    or the IPC/DCONNECT shutdown sequence is initiated by the
     270                 *    XPCOM shutdown routine (NS_ShutdownXPCOM()), which always
     271                 *    happens on the main thread.
     272                 *
     273                 * b) gEventQ has reported we're on the main thread. This means
     274                 *    that DestructEventHandler() has been called, but another
     275                 *    client was faster and requested VirtualBox again.
     276                 *
     277                 * We have nothing to do in these cases.
     278                 */
    264279            }
    265280        }
     
    272287        Assert (RTCritSectIsInitialized (&sLock));
    273288
    274         // stop accepting GetInstance() requests during possible destruction
     289        /* stop accepting GetInstance() requests during possible destruction */
    275290        RTCritSectEnter (&sLock);
    276291
    277292        Assert (sInstance);
    278293
    279         // release the reference we added in GetInstance()
    280         // (will call the destructor if nobody referenced us again)
     294        /* release the reference we added in GetInstance()
     295         * (will call the destructor if nobody referenced us again) */
    281296        nsrefcnt count = sInstance->Release();
    282297        if (count != 0)
    283298        {
    284             LogFlow (("VirtualBoxClassFactory: destruciton is canceled\n"));
     299            LogFlowFunc (("Destruction is canceled.\n"));
    285300        }
    286301
     
    295310    }
    296311
     312    static void ShutdownTimer (PRTTIMER pTimer, void *pvUser)
     313    {
     314        NOREF (pvUser);
     315
     316        if (pTimer)
     317        {
     318            /* it's a single shot timer */
     319            int vrc = RTTimerStop (pTimer);
     320/// @todo uncomment when implemented
     321//                AssertRC (vrc);
     322            NOREF (vrc);
     323        }
     324
     325        /* post a destruction event to the main thread to safely release the
     326         * extra reference added in VirtualBoxClassFactory::GetInstance() */
     327
     328        LogFlowFunc (("Posting VirtualBox destruction & shtutdown event...\n"));
     329
     330        PLEvent *ev = new PLEvent;
     331        gEventQ->InitEvent (ev, NULL, DestructEventHandler,
     332                            DestructEventDestructor);
     333        nsresult rv = gEventQ->PostEvent (ev);
     334        if (NS_FAILED (rv))
     335        {
     336            /* this means we've been already stopped (for example
     337             * by Ctrl-C). FactoryDestructor() (NS_ShutdownXPCOM())
     338             * will do the job. */
     339            PL_DestroyEvent (ev);
     340        }
     341    }
     342
    297343    static NS_IMETHODIMP FactoryConstructor()
    298344    {
    299         LogFlow (("VirtualBoxClassFactory::FactoryConstructor()\n"));
    300 
    301         // create a critsect to protect object construction
     345        LogFlowFunc (("\n"));
     346
     347        /* create a critsect to protect object construction */
    302348        if (VBOX_FAILURE (RTCritSectInit (&sLock)))
    303349            return NS_ERROR_OUT_OF_MEMORY;
    304350
     351        int vrc = RTTimerCreateEx (&sTimer,
     352                                   uint64_t (VBoxSVC_ShutdownDelay) * 1000000,
     353                                   0, ShutdownTimer, NULL);
     354        NOREF (vrc);
     355/// @todo uncomment when implemented
     356//         if (VBOX_FAILURE (vrc))
     357//         {
     358//             LogFlowFunc (("Failed to create a timer! (vrc=%Vrc)\n", vrc));
     359//             return NS_ERROR_FAILURE;
     360//         }
     361
    305362        return NS_OK;
    306363    }
     
    308365    static NS_IMETHODIMP FactoryDestructor()
    309366    {
    310         LogFlow (("VirtualBoxClassFactory::FactoryDestructor()\n"));
     367        LogFlowFunc (("\n"));
     368
     369        RTTimerDestroy (sTimer);
     370        sTimer = NULL;
    311371
    312372        RTCritSectDelete (&sLock);
     
    314374        if (sInstance)
    315375        {
    316             // Either posting a destruction event falied for some reason (most
    317             // likely, the quit event has been received before the last release),
    318             // or the client has terminated abnormally w/o releasing its
    319             // VirtualBox instance (so NS_ShutdownXPCOM() is doing a cleanup).
    320             // Release the extra reference we added in GetInstance().
     376            /* Either posting a destruction event falied for some reason (most
     377             * likely, the quit event has been received before the last release),
     378             * or the client has terminated abnormally w/o releasing its
     379             * VirtualBox instance (so NS_ShutdownXPCOM() is doing a cleanup).
     380             * Release the extra reference we added in GetInstance(). */
    321381            sInstance->Release();
    322382        }
     
    327387    static nsresult GetInstance (VirtualBox **inst)
    328388    {
    329         Log (("VirtualBoxClassFactory: getting VirtualBox object...\n"));
     389        LogFlowFunc (("Getting VirtualBox object...\n"));
    330390
    331391        RTCritSectEnter (&sLock);
     
    335395        if (sInstance == 0)
    336396        {
    337             Log (("VirtualBoxClassFactory: creating new VirtualBox object...\n"));
     397            LogFlowFunc (("Creating new VirtualBox object...\n"));
    338398            sInstance = new VirtualBoxClassFactory();
    339399            if (sInstance)
    340400            {
    341                 // make an extra AddRef to take the full control
    342                 // on the VirtualBox destruction (see FinalRelease())
     401                /* make an extra AddRef to take the full control
     402                 * on the VirtualBox destruction (see FinalRelease()) */
    343403                sInstance->AddRef();
    344404
    345                 sInstance->AddRef(); // protect FinalConstruct()
     405                sInstance->AddRef(); /* protect FinalConstruct() */
    346406                rv = sInstance->FinalConstruct();
    347407                printf ("Informational: VirtualBox object created (rc=%08X).\n", rv);
    348408                if (NS_FAILED (rv))
    349409                {
    350                     // on failure diring VirtualBox initialization, delete it
    351                     // immediately on the current thread, ignoring the reference
    352                     // count (VirtualBox should be aware of that meaning that it
    353                     // has already completely unintialized itself in this case)
    354                     Log (("VirtualBoxClassFactory: VirtualBox creation failed "
    355                           "(rc=%08X), deleting immediately...\n", rv));
     410                    /* on failure diring VirtualBox initialization, delete it
     411                     * immediately on the current thread, ignoring the reference
     412                     * count (VirtualBox should be aware of that meaning that it
     413                     * has already completely unintialized itself in this
     414                     * case) */
     415                    LogFlowFunc (("VirtualBox creation failed "
     416                                  "(rc=%08X), deleting immediately...\n", rv));
    356417                    delete sInstance;
    357418                    sInstance = 0;
     
    365426        else
    366427        {
    367             Log (("VirtualBoxClassFactory: using existing VirtualBox object...\n"));
     428            LogFlowFunc (("Using existing VirtualBox object...\n"));
    368429            nsrefcnt count = sInstance->AddRef();
    369430            Assert (count > 1);
     
    371432            if (count == 2)
    372433            {
    373                 LogFlow (("VirtualBoxClassFactory: another client has requested "
    374                           "a reference of VirtualBox scheduled for destruction, "
    375                           "canceling detruction...\n"));
    376 
    377                 // add a reference to compensate one that DestructEventHandler()
    378                 // will release
     434                LogFlowFunc (("Another client has requested "
     435                              "a reference of VirtualBox scheduled for destruction, "
     436                              "canceling detruction...\n"));
     437
     438                /* add a reference to compensate one that DestructEventHandler()
     439                 * will release */
    379440                sInstance->AddRef();
    380441            }
     
    392453    static VirtualBox *sInstance;
    393454    static RTCRITSECT sLock;
     455
     456    static PRTTIMER sTimer;
    394457};
    395458
     
    397460RTCRITSECT VirtualBoxClassFactory::sLock = {0};
    398461
    399 NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR_WITH_RC (
    400     VirtualBox, VirtualBoxClassFactory::GetInstance
    401 )
     462PRTTIMER VirtualBoxClassFactory::sTimer = NULL;
     463
     464NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR_WITH_RC
     465    (VirtualBox, VirtualBoxClassFactory::GetInstance)
    402466
    403467////////////////////////////////////////////////////////////////////////////////
     
    477541 *  starts up (somewhere during the initialization of the libipcdc.so module)
    478542 *  when we just reference XPCOM's NS_NewGenericFactory() from here (i.e. even
    479  *  before actually calling it) and run VBoxSVC using the debug XPCOM libraries.
     543 *  before actually calling it) and run VBoxSVC using the debug XPCOM
     544 *  libraries.
     545 *
     546 *  Actually, I know why, but I find it too stupid even to discuss.
    480547 */
    481548class nsMyFactory : public nsIGenericFactory, public nsIClassInfo {
     
    677744/////////////////////////////////////////////////////////////////////////////
    678745
    679 // a helper function to register self components upon start-up
    680 // of the out-of-proc server
    681 static nsresult RegisterSelfComponents (
    682     nsIComponentRegistrar *registrar,
    683     const nsMyModuleComponentInfo *components, PRUint32 count)
     746/**
     747 * Hhelper function to register self components upon start-up
     748 * of the out-of-proc server.
     749 */
     750static nsresult
     751RegisterSelfComponents (nsIComponentRegistrar *registrar,
     752                        const nsMyModuleComponentInfo *components,
     753                        PRUint32 count)
    684754{
    685755    nsresult rc = NS_OK;
    686756    const nsMyModuleComponentInfo *info = components;
    687     for (PRUint32 i = 0; i < count && NS_SUCCEEDED( rc ); i++, info++) {
    688         // skip components w/o a constructor
     757    for (PRUint32 i = 0; i < count && NS_SUCCEEDED (rc); i++, info++)
     758    {
     759        /* skip components w/o a constructor */
    689760        if (!info->mConstructor) continue;
    690         // create a new generic factory for a component and register it
     761        /* create a new generic factory for a component and register it */
    691762        nsIGenericFactory *factory;
    692 //        rc = NS_NewGenericFactory (&factory, info);
     763        rc = NS_NewGenericFactory (&factory, info);
    693764        rc = NS_NewMyFactory (&factory, info);
    694         if (NS_SUCCEEDED( rc )) {
    695             rc = registrar->RegisterFactory (
    696                 info->mCID,
    697                 info->mDescription,
    698                 info->mContractID,
    699                 factory
    700             );
     765        if (NS_SUCCEEDED (rc))
     766        {
     767            rc = registrar->RegisterFactory (info->mCID,
     768                                             info->mDescription,
     769                                             info->mContractID,
     770                                             factory);
    701771            factory->Release();
    702772        }
     
    706776
    707777/////////////////////////////////////////////////////////////////////////////
    708 
    709 #define VIRTUALBOXSERVER_IPCNAME "VirtualBoxServer"
    710778
    711779static ipcIService *gIpcServ = nsnull;
     
    715783void PR_CALLBACK quitEventDestructor (PLEvent* self) { delete self; }
    716784
    717 void signal_handler (int sig)
     785static void signal_handler (int sig)
    718786{
    719787    if (gEventQ && gKeepRunning)
    720788    {
    721         // post a quit event to the queue
     789        /* post a quit event to the queue */
    722790        PLEvent *ev = new PLEvent;
    723791        gEventQ->InitEvent (ev, NULL, quitEventHandler, quitEventDestructor);
     
    735803 * the code is taken from http://www.linuxjournal.com/article/6391.
    736804 */
    737 void bt_sighandler (int sig, siginfo_t *info, void *secret)
     805static void bt_sighandler (int sig, siginfo_t *info, void *secret)
    738806{
    739807
     
    768836    const struct option options[] =
    769837    {
     838        { "automate",  no_argument,       NULL, 'a' },
    770839        { "daemonize", no_argument,       NULL, 'd' },
    771840        { "pidfile",   required_argument, NULL, 'p' },
     
    783852        switch (c)
    784853        {
     854            case 'a':
     855            {
     856                /* --automate mode means we are started by XPCOM on
     857                 * demand. Daemonize ourselves and activate
     858                 * auto-shutdown. */
     859                gAutoShutdown = true;
     860                fDaemonize = true;
     861                break;
     862            }
     863
    785864            case 'd':
    786865            {
     
    796875
    797876            default:
    798                 break;
     877            {
     878                /* exit on invalid options */
     879                return 1;
     880            }
    799881        }
    800882    }
     
    808890        if (pipe(daemon_pipe_fds) < 0)
    809891        {
    810             printf("Error creating pipe! errno = %d\n", errno);
     892            printf("ERROR: pipe() failed (errno = %d)\n", errno);
    811893            return 1;
    812894        }
     
    815897        if (childpid == -1)
    816898        {
    817             printf("Error failed to fork!\n");
     899            printf("ERROR: fork() failed (errno = %d)\n", errno);
    818900            return 1;
    819901        }
     
    832914            {
    833915                if (strcmp(msg, "READY") == 0)
    834                 {
    835                     Log (("child process signalled ready\n"));
    836916                    fSuccess = true;
    837                 }
    838917                else
    839                 {
    840                     Log (("unknown message from child\n"));
    841                 }
     918                    printf ("ERROR: Unknown message from child "
     919                            "process (%s)\n", msg);
    842920            }
    843921            else
    844             {
    845                 Log (("0 bytes read from child process\n"));
    846             }
     922                printf ("ERROR: 0 bytes read from child process\n");
     923
    847924            /* close the reading end of the pipe as well and exit */
    848925            close(daemon_pipe_fds[0]);
     
    851928        /* we're the child process */
    852929
     930        /* Create a new SID for the child process */
     931        pid_t sid = setsid();
     932        if (sid < 0)
     933        {
     934            printf("ERROR: setsid() failed (errno = %d)\n", errno);
     935            return 1;
     936        }
     937
     938        /* Redirect standard i/o streams to /dev/null */
     939        freopen ("/dev/null", "r", stdin);
     940        freopen ("/dev/null", "w", stdout);
     941        freopen ("/dev/null", "w", stderr);
     942
    853943        /* close the reading end of the pipe */
    854944        close(daemon_pipe_fds[0]);
     
    857947#if defined(USE_BACKTRACE)
    858948    {
    859         // install our signal handler to backtrace the call stack
     949        /* install our signal handler to backtrace the call stack */
    860950        struct sigaction sa;
    861951        sa.sa_sigaction = bt_sighandler;
     
    880970        XPCOMGlueStartup (nsnull);
    881971
    882         // get the path to the executable
    883         char buf [RTPATH_MAX];
    884         char *appPath = NULL;
    885 #if defined(DEBUG)
    886         appPath = getenv ("VIRTUALBOX_APP_HOME");
    887         if (appPath)
    888             RTPathReal (appPath, buf, RTPATH_MAX);
    889         else
     972        char path [RTPATH_MAX];
     973        path [0] = '\0';
     974
     975        nsCOMPtr<nsIFile> nsAppPath;
     976        {
     977            /* get the path to the executable */
     978            char *appPath = NULL;
     979#if defined (DEBUG)
     980            appPath = getenv ("VIRTUALBOX_APP_HOME");
     981            if (appPath)
     982                RTPathReal (appPath, path, RTPATH_MAX);
     983            else
    890984#endif
    891         RTPathProgram (buf, RTPATH_MAX);
    892         appPath = buf;
    893 
    894         nsCOMPtr<nsIFile> nsAppPath;
    895         {
     985                RTPathProgram (path, RTPATH_MAX);
     986            appPath = path;
     987
    896988            nsCOMPtr<nsILocalFile> file;
    897989            rc = NS_NewNativeLocalFile (nsEmbedCString (appPath),
     
    900992                nsAppPath = do_QueryInterface (file, &rc);
    901993        }
    902         if (NS_FAILED( rc ))
    903         {
    904             printf ("ERROR: failed to create file object! (rc=%08X)\n", rc);
     994        if (NS_FAILED (rc))
     995        {
     996            printf ("ERROR: Failed to create file object! (rc=%08X)\n", rc);
    905997            break;
    906998        }
     999
     1000        /* get the executable name (will be used below) */
     1001        if (!RTProcGetExecutableName (path, sizeof (path)))
     1002        {
     1003            printf ("ERROR: Failed to get executable name!\n");
     1004            break;
     1005        }
     1006
     1007        LogFlowFunc (("Will use \"%s\" as server name.\n", path));
    9071008
    9081009        nsCOMPtr<nsIServiceManager> servMan;
     
    9101011        if (!servMan)
    9111012        {
    912             printf ("ERROR: failed to get service manager!\n");
     1013            printf ("ERROR: Failed to get service manager!\n");
    9131014            break;
    9141015        }
     
    9171018        if (!registrar)
    9181019        {
    919             printf ("ERROR: failed to get component registrar!\n");
     1020            printf ("ERROR: Failed to get component registrar!\n");
    9201021            break;
    9211022        }
     
    9261027        if (NS_FAILED (rc))
    9271028        {
    928             printf ("ERROR: failed to register server components! (rc=%08X)\n", rc);
     1029            printf ("ERROR: Failed to register server components! (rc=%08X)\n", rc);
    9291030            break;
    9301031        }
    9311032
    932         // get the main thread's event queue (afaik, the dconnect service always
    933         // gets created upon XPCOM startup, so it will use the main (this)
    934         // thread's event queue to receive IPC events)
     1033        /* get the main thread's event queue (afaik, the dconnect service always
     1034         * gets created upon XPCOM startup, so it will use the main (this)
     1035         * thread's event queue to receive IPC events) */
    9351036        rc = NS_GetMainEventQ (&gEventQ);
    9361037        if (NS_FAILED (rc))
    9371038        {
    938             printf ("ERROR: failed to get the main event queue! (rc=%08X)\n", rc);
     1039            printf ("ERROR: Failed to get the main event queue! (rc=%08X)\n", rc);
    9391040            break;
    9401041        }
     
    9431044        if (NS_FAILED (rc))
    9441045        {
    945             printf ("ERROR: failed to get IPC service! (rc=%08X)\n", rc);
     1046            printf ("ERROR: Failed to get IPC service! (rc=%08X)\n", rc);
    9461047            break;
    9471048        }
     
    9491050        NS_ADDREF (gIpcServ = ipcServ);
    9501051
    951         rc = gIpcServ->AddName (VIRTUALBOXSERVER_IPCNAME);
     1052        /* use the executable name as the server name */
     1053        rc = gIpcServ->AddName (path);
    9521054        if (NS_FAILED (rc))
    9531055        {
    954             printf ("ERROR: failed to register VirtualBoxServer! (rc=%08X)\n", rc);
     1056            printf ("ERROR: Failed to register VirtualBoxServer! (rc=%08X)\n", rc);
    9551057            NS_RELEASE (gIpcServ);
    9561058            break;
     
    9581060
    9591061        {
    960             // setup signal handling to convert some signals to a quit event
     1062            /* setup signal handling to convert some signals to a quit event */
    9611063            struct sigaction sa;
    9621064            sa.sa_handler = signal_handler;
     
    10211123        }
    10221124
    1023         gIpcServ->RemoveName (VIRTUALBOXSERVER_IPCNAME);
     1125        gIpcServ->RemoveName (path);
    10241126
    10251127        // stop accepting new events
     
    10371139
    10381140    // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM
    1039     LogFlow (("VBoxSVC::main(): calling NS_ShutdownXPCOM()...\n"));
     1141    LogFlowFunc (("Calling NS_ShutdownXPCOM()...\n"));
    10401142    rc = NS_ShutdownXPCOM (nsnull);
    1041     LogFlow (("VBoxSVC::main(): finished NS_ShutdownXPCOM() (rc=%08X).\n", rc));
    1042 
    1043     if (NS_FAILED( rc ))
    1044         printf ("ERROR: failed to shutdown XPCOM! (rc=%08X)\n", rc);
     1143    LogFlowFunc (("Finished NS_ShutdownXPCOM() (rc=%08X)\n", rc));
     1144
     1145    if (NS_FAILED (rc))
     1146        printf ("ERROR: Failed to shutdown XPCOM! (rc=%08X)\n", rc);
    10451147
    10461148    XPCOMGlueShutdown();
  • trunk/src/VBox/Main/testcase/tstAPI.cpp

    r1128 r1471  
    215215
    216216    printf ("Creating VirtualBox object...\n");
    217     CHECK_RC (virtualBox.createLocalObject (CLSID_VirtualBox,
    218                                             "VirtualBoxServer"));
     217    CHECK_RC (virtualBox.createLocalObject (CLSID_VirtualBox));
    219218    if (FAILED (rc))
    220219    {
     
    238237
    239238        printf ("Creating one more VirtualBox object...\n");
    240         CHECK_RC (virtualBox2.createLocalObject (CLSID_VirtualBox,
    241                                                 "VirtualBoxServer"));
     239        CHECK_RC (virtualBox2.createLocalObject (CLSID_VirtualBox));
    242240        if (FAILED (rc))
    243241        {
     
    481479#endif
    482480
    483 #if 1
     481#if 0
    484482    // create a new machine (w/o registering it)
    485483    ///////////////////////////////////////////////////////////////////////////
Note: See TracChangeset for help on using the changeset viewer.

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