~ubuntu-branches/ubuntu/trusty/virtualbox-ose/trusty

« back to all changes in this revision

Viewing changes to src/VBox/Additions/common/VBoxService/VBoxService.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2009-12-18 16:44:29 UTC
  • mfrom: (0.3.3 upstream) (0.4.6 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091218164429-jd34ccexpv5na11a
Tags: 3.1.2-dfsg-1ubuntu1
* Merge from Debian unstable (LP: #498219), remaining changes:
  - Disable update action
    - debian/patches/u01-disable-update-action.dpatch
  - VirtualBox should go in Accessories, not in System tools (LP: #288590)
    - debian/virtualbox-ose-qt.files/virtualbox-ose.desktop
  - Add Apport hook
    - debian/virtualbox-ose.files/source_virtualbox-ose.py
    - debian/virtualbox-ose.install
  - Add Launchpad integration
    - debian/control
    - debian/lpi-bug.xpm
    - debian/patches/u02-lp-integration.dpatch
* Fixes the following bugs:
  - Kernel module fails to build with Linux >= 2.6.32 (LP: #474625)
  - X.Org drivers need to be rebuilt against X-Server 1.7 (LP: #495935)
  - The *-source packages try to build the kernel modules even though the
    kernel headers aren't available (LP: #473334)
* Replace *-source packages with transitional packages for *-dkms.
* Adapt u01-disable-update-action.dpatch and u02-lp-integration.dpatch for
  new upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
#include <iprt/asm.h>
38
38
#include <iprt/path.h>
39
39
#include <VBox/log.h>
40
 
#include <VBox/VBoxGuest.h>
 
40
#include <VBox/VBoxGuestLib.h>
41
41
#include "VBoxServiceInternal.h"
42
42
 
43
43
 
280
280
     */
281
281
    VBoxServiceVerbose(2, "Initializing services ...\n");
282
282
    for (unsigned j = 0; j < RT_ELEMENTS(g_aServices); j++)
283
 
    {
284
 
        rc = g_aServices[j].pDesc->pfnInit();
285
 
        if (RT_FAILURE(rc))
 
283
        if (g_aServices[j].fEnabled)
286
284
        {
287
 
            VBoxServiceError("Service '%s' failed pre-init: %Rrc\n", g_aServices[j].pDesc->pszName);
288
 
            return rc;
 
285
            rc = g_aServices[j].pDesc->pfnInit();
 
286
            if (RT_FAILURE(rc))
 
287
            {
 
288
                VBoxServiceError("Service '%s' failed to initialize: %Rrc\n",
 
289
                                 g_aServices[j].pDesc->pszName, rc);
 
290
                return rc;
 
291
            }
289
292
        }
290
 
    }
291
293
 
292
294
    /*
293
295
     * Start the service(s).
313
315
        /* wait for the thread to initialize */
314
316
        RTThreadUserWait(g_aServices[j].Thread, 60 * 1000);
315
317
        if (g_aServices[j].fShutdown)
 
318
        {
 
319
            VBoxServiceError("Service '%s' failed to start!\n", g_aServices[j].pDesc->pszName);
316
320
            rc = VERR_GENERAL_FAILURE;
 
321
        }
317
322
    }
318
323
    if (RT_SUCCESS(rc))
319
324
    {
325
330
            VBoxServiceError("Service '%s' stopped unexpected; rc=%Rrc\n", g_aServices[iMain].pDesc->pszName, rc);
326
331
        }
327
332
    }
328
 
 
329
 
    /* Should never get here. */
330
333
    return rc;
331
334
}
332
335
 
347
350
        if (g_aServices[j].fStarted)
348
351
            g_aServices[j].pDesc->pfnStop();
349
352
    for (unsigned j = 0; j < RT_ELEMENTS(g_aServices); j++)
350
 
    {
351
 
        if (g_aServices[j].Thread != NIL_RTTHREAD)
 
353
        if (g_aServices[j].fEnabled)
352
354
        {
353
 
            int rc = RTThreadWait(g_aServices[j].Thread, 30*1000, NULL);
354
 
            if (RT_FAILURE(rc))
355
 
                VBoxServiceError("Service '%s' failed to stop. (%Rrc)\n", g_aServices[j].pDesc->pszName, rc);
 
355
            if (g_aServices[j].Thread != NIL_RTTHREAD)
 
356
            {
 
357
                int rc;
 
358
                VBoxServiceVerbose(2, "Waiting for service '%s' to stop ...\n", g_aServices[j].pDesc->pszName);
 
359
                for (int i=0; i<30; i++) /* Wait 30 seconds in total */
 
360
                {
 
361
                    rc = RTThreadWait(g_aServices[j].Thread, 1000 /* Wait 1 second */, NULL);
 
362
                    if (RT_SUCCESS(rc))
 
363
                        break;
 
364
#ifdef RT_OS_WINDOWS
 
365
                    /* Notify SCM that it takes a bit longer ... */
 
366
                    VBoxServiceWinSetStatus(SERVICE_STOP_PENDING, i);
 
367
#endif
 
368
                }
 
369
                if (RT_FAILURE(rc))
 
370
                    VBoxServiceError("Service '%s' failed to stop. (%Rrc)\n", g_aServices[j].pDesc->pszName, rc);
 
371
            }
 
372
            VBoxServiceVerbose(3, "Terminating service '%s' (%d) ...\n", g_aServices[j].pDesc->pszName, j);
 
373
            g_aServices[j].pDesc->pfnTerm();
356
374
        }
357
 
        g_aServices[j].pDesc->pfnTerm();
358
 
    }
359
375
 
360
376
    VBoxServiceVerbose(2, "Stopping services returned: rc=%Rrc\n", rc);
361
377
    return rc;
365
381
int main(int argc, char **argv)
366
382
{
367
383
    int rc = VINF_SUCCESS;
368
 
 
369
384
    /*
370
385
     * Init globals and such.
371
386
     */
372
387
    RTR3Init();
 
388
 
 
389
    /*
 
390
     * Connect to the kernel part before daemonizing so we can fail
 
391
     * and complain if there is some kind of problem. We need to initialize
 
392
     * the guest lib *before* we do the pre-init just in case one of services
 
393
     * needs do to some initial stuff with it.
 
394
     */
 
395
    VBoxServiceVerbose(2, "Calling VbgR3Init()\n");
 
396
    rc = VbglR3Init();
 
397
    if (RT_FAILURE(rc))
 
398
        return VBoxServiceError("VbglR3Init failed with rc=%Rrc.\n", rc);
 
399
 
 
400
    /* Do pre-init of services. */
373
401
    g_pszProgName = RTPathFilename(argv[0]);
374
402
    for (unsigned j = 0; j < RT_ELEMENTS(g_aServices); j++)
375
403
    {
521
549
    if (iMain == ~0U)
522
550
        return VBoxServiceSyntax("At least one service must be enabled.\n");
523
551
 
524
 
    /*
525
 
     * Connect to the kernel part before daemonizing so we can fail
526
 
     * and complain if there is some kind of problem.
527
 
     */
528
 
    VBoxServiceVerbose(2, "Calling VbgR3Init()\n");
529
 
    rc = VbglR3Init();
530
 
    if (RT_FAILURE(rc))
531
 
        return VBoxServiceError("VbglR3Init failed with rc=%Rrc.\n", rc);
532
 
 
533
552
    VBoxServiceVerbose(0, "Started. Verbose level = %d\n", g_cVerbosity);
534
553
 
535
554
    /*