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

« back to all changes in this revision

Viewing changes to src/VBox/Runtime/r3/init.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:
41
41
# include <unistd.h>
42
42
# ifndef RT_OS_OS2
43
43
#  include <pthread.h>
 
44
#  include <signal.h>
 
45
#  include <errno.h>
 
46
#  define IPRT_USE_SIG_CHILD_DUMMY
44
47
# endif
45
48
#endif
46
49
#ifdef RT_OS_OS2
123
126
#endif
124
127
 
125
128
 
 
129
/**
 
130
 * atexit callback.
 
131
 *
 
132
 * This makes sure any loggers are flushed and will later also work the
 
133
 * termination callback chain.
 
134
 */
 
135
static void rtR3ExitCallback(void)
 
136
{
 
137
    if (g_cUsers > 0)
 
138
    {
 
139
        PRTLOGGER pLogger = RTLogGetDefaultInstance();
 
140
        if (pLogger)
 
141
            RTLogFlush(pLogger);
 
142
 
 
143
        pLogger = RTLogRelDefaultInstance();
 
144
        if (pLogger)
 
145
            RTLogFlush(pLogger);
 
146
    }
 
147
}
 
148
 
126
149
 
127
150
#ifndef RT_OS_WINDOWS
128
151
/**
135
158
#endif /* RT_OS_WINDOWS */
136
159
 
137
160
#ifdef RT_OS_OS2
 
161
/** Fork completion callback for OS/2.  Only called in the child. */
 
162
static void rtR3ForkOs2ChildCompletionCallback(void *pvArg, int rc, __LIBC_FORKCTX enmCtx)
 
163
{
 
164
    Assert(enmCtx == __LIBC_FORK_CTX_CHILD); NOREF(enmCtx);
 
165
    NOREF(pvArg);
 
166
 
 
167
    if (!rc)
 
168
        rtR3ForkChildCallback();
 
169
}
 
170
 
138
171
/** Low-level fork callback for OS/2.  */
139
172
int rtR3ForkOs2Child(__LIBC_PFORKHANDLE pForkHandle, __LIBC_FORKOP enmOperation)
140
173
{
141
 
    if (enmOperation == __LIBC_FORK_STAGE_COMPLETION_CHILD)
142
 
        rtR3ForkChildCallback();
 
174
    if (enmOperation == __LIBC_FORK_OP_EXEC_CHILD)
 
175
        return pForkHandle->pfnCompletionCallback(pForkHandle, rtR3ForkOs2ChildCompletionCallback, NULL, __LIBC_FORK_CTX_CHILD);
143
176
    return 0;
144
177
}
145
178
 
183
216
    return VINF_SUCCESS;
184
217
}
185
218
 
 
219
 
 
220
#ifdef IPRT_USE_SIG_CHILD_DUMMY
 
221
/**
 
222
 * Dummy SIGCHILD handler.
 
223
 *
 
224
 * Assigned on rtR3Init only when SIGCHILD handler is set SIGIGN or SIGDEF to
 
225
 * ensure waitpid works properly for the terminated processes.
 
226
 */
 
227
static void rtR3SigChildHandler(int iSignal)
 
228
{
 
229
    NOREF(iSignal);
 
230
}
 
231
#endif /* IPRT_USE_SIG_CHILD_DUMMY */
 
232
 
 
233
 
186
234
/**
187
235
 * rtR3Init worker.
188
236
 */
268
316
    /* Init C runtime locale. */
269
317
    setlocale(LC_CTYPE, "");
270
318
 
271
 
    /* Fork callbacks. */
 
319
    /* Fork and exit callbacks. */
272
320
#if !defined(RT_OS_WINDOWS) && !defined(RT_OS_OS2)
273
321
    rc = pthread_atfork(NULL, NULL, rtR3ForkChildCallback);
274
322
    AssertMsg(rc == 0, ("%d\n", rc));
275
323
#endif
 
324
    atexit(rtR3ExitCallback);
 
325
 
 
326
#ifdef IPRT_USE_SIG_CHILD_DUMMY
 
327
    /*
 
328
     * SIGCHLD must not be ignored (that's default), otherwise posix compliant waitpid
 
329
     * implementations won't work right.
 
330
     */
 
331
    for (;;)
 
332
    {
 
333
        struct sigaction saOld;
 
334
        rc = sigaction(SIGCHLD, 0, &saOld);         AssertMsg(rc == 0, ("%d/%d\n", rc, errno));
 
335
        if (    rc != 0
 
336
            ||  (saOld.sa_flags & SA_SIGINFO)
 
337
            || (   saOld.sa_handler != SIG_IGN
 
338
                && saOld.sa_handler != SIG_DFL)
 
339
           )
 
340
            break;
 
341
 
 
342
        /* Try install dummy handler. */
 
343
        struct sigaction saNew = saOld;
 
344
        saNew.sa_flags   = SA_NOCLDSTOP | SA_RESTART;
 
345
        saNew.sa_handler = rtR3SigChildHandler;
 
346
        rc = sigemptyset(&saNew.sa_mask);           AssertMsg(rc == 0, ("%d/%d\n", rc, errno));
 
347
        struct sigaction saOld2;
 
348
        rc = sigaction(SIGCHLD, &saNew, &saOld2);   AssertMsg(rc == 0, ("%d/%d\n", rc, errno));
 
349
        if (    rc != 0
 
350
            ||  (   saOld2.sa_handler == saOld.sa_handler
 
351
                 && !(saOld2.sa_flags & SA_SIGINFO))
 
352
           )
 
353
            break;
 
354
 
 
355
        /* Race during dynamic load, restore and try again... */
 
356
        sigaction(SIGCHLD, &saOld2, NULL);
 
357
        RTThreadYield();
 
358
    }
 
359
#endif /* IPRT_USE_SIG_CHILD_DUMMY */
276
360
 
277
361
#ifdef IPRT_WITH_ALIGNMENT_CHECKS
278
362
    /*