VirtualBox

Changeset 32971 in vbox


Ignore:
Timestamp:
Oct 7, 2010 10:15:26 AM (14 years ago)
Author:
vboxsync
Message:

XPCOM: implement a shortcut PR_CreateProcessDetached which directly uses IPRT to daemonize the process. XPCOM only starts IPCD this way, and its own code didn't properly detach it, it remained a child of the client which triggered the IPCD start.

Location:
trunk/src/libs/xpcom18a4/nsprpub/pr
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/libs/xpcom18a4/nsprpub/pr/include/md/_unixos.h

    r1 r32971  
    173173
    174174#if defined(DEBUG) && !defined(DARWIN) && !defined(NEXTSTEP)
    175 #if !defined(SOLARIS)   
     175#if !defined(SOLARIS)
    176176#include <string.h>  /* for memset() */
    177177#define _MD_INIT_STACK(ts,REDZONE)                                      \
     
    218218#endif  /* DEBUG */
    219219
    220 #if !defined(SOLARIS) 
     220#if !defined(SOLARIS)
    221221
    222222#define PR_SET_INTSOFF(newval)
     
    246246);
    247247
     248#ifdef VBOX
     249/* Create a new detached process (fork() + exec()) */
     250#define _MD_CREATE_PROCESS_DETACHED _MD_CreateUnixProcessDetached
     251extern PRStatus _MD_CreateUnixProcessDetached(
     252    const char *path,
     253    char *const *argv,
     254    char *const *envp,
     255    const struct PRProcessAttr *attr
     256);
     257#endif /* VBOX */
     258
    248259#define _MD_DETACH_PROCESS _MD_DetachUnixProcess
    249260extern PRStatus _MD_DetachUnixProcess(struct PRProcess *process);
     
    297308
    298309extern void             _MD_MakeNonblock(PRFileDesc *fd);
    299 #define _MD_MAKE_NONBLOCK                       _MD_MakeNonblock               
     310#define _MD_MAKE_NONBLOCK                       _MD_MakeNonblock
    300311
    301312/************************************************************************/
     
    401412#define _MD_SHUTDOWN    _MD_shutdown
    402413
    403 extern PRInt32          _MD_recv(PRFileDesc *fd, void *buf, PRInt32 amount, 
     414extern PRInt32          _MD_recv(PRFileDesc *fd, void *buf, PRInt32 amount,
    404415                               PRIntn flags, PRIntervalTime timeout);
    405416#define _MD_RECV        _MD_recv
  • trunk/src/libs/xpcom18a4/nsprpub/pr/include/private/primpl.h

    r11551 r32971  
    9191
    9292/*
    93 NSPR 2.0 must implement its function across a range of platforms 
     93NSPR 2.0 must implement its function across a range of platforms
    9494including: MAC, Windows/16, Windows/95, Windows/NT, and several
    95 variants of Unix. Each implementation shares common code as well 
     95variants of Unix. Each implementation shares common code as well
    9696as having platform dependent portions. This standard describes how
    9797the model dependent portions are to be implemented.
    9898
    99 In header file pr/include/primpl.h, each publicly declared 
     99In header file pr/include/primpl.h, each publicly declared
    100100platform dependent function is declared as:
    101101
     
    103103#define _PR_MD_FUNCTION _MD_FUNCTION
    104104
    105 In header file pr/include/md/<platform>/_<platform>.h, 
     105In header file pr/include/md/<platform>/_<platform>.h,
    106106each #define'd macro is redefined as one of:
    107107
     
    113113Where:
    114114
    115 <blanks> is no definition at all. In this case, the function is not implemented 
    116 and is never called for this platform. 
    117 For example: 
     115<blanks> is no definition at all. In this case, the function is not implemented
     116and is never called for this platform.
     117For example:
    118118#define _MD_INIT_CPUS()
    119119
    120 <expanded macro> is a C language macro expansion. 
    121 For example: 
     120<expanded macro> is a C language macro expansion.
     121For example:
    122122#define        _MD_CLEAN_THREAD(_thread) \
    123123    PR_BEGIN_MACRO \
     
    126126    PR_END_MACRO
    127127
    128 <osFunction> is some function implemented by the host operating system. 
    129 For example: 
     128<osFunction> is some function implemented by the host operating system.
     129For example:
    130130#define _MD_EXIT        exit
    131131
    132 <_MD_function> is the name of a function implemented for this platform in 
    133 pr/src/md/<platform>/<soruce>.c file. 
    134 For example: 
     132<_MD_function> is the name of a function implemented for this platform in
     133pr/src/md/<platform>/<soruce>.c file.
     134For example:
    135135#define        _MD_GETFILEINFO         _MD_GetFileInfo
    136136
     
    181181
    182182/*
    183  * bits defined for pthreads 'state' field 
     183 * bits defined for pthreads 'state' field
    184184 */
    185185#define PT_THREAD_DETACHED  0x01    /* thread can't be joined */
     
    207207#endif /* GC_LEAK_DETECTOR */
    208208
    209 /* 
     209/*
    210210** Possible values for thread's suspend field
    211211** Note that the first two can be the same as they are really mutually exclusive,
     
    247247#ifdef _PR_LOCAL_THREADS_ONLY
    248248
    249 #define        _PR_MD_SUSPEND_THREAD(thread)       
    250 #define        _PR_MD_RESUME_THREAD(thread)       
    251 #define        _PR_MD_SUSPEND_CPU(cpu)       
    252 #define        _PR_MD_RESUME_CPU(cpu)       
    253 #define        _PR_MD_BEGIN_SUSPEND_ALL()       
    254 #define        _PR_MD_END_SUSPEND_ALL()       
    255 #define        _PR_MD_BEGIN_RESUME_ALL()       
     249#define        _PR_MD_SUSPEND_THREAD(thread)
     250#define        _PR_MD_RESUME_THREAD(thread)
     251#define        _PR_MD_SUSPEND_CPU(cpu)
     252#define        _PR_MD_RESUME_CPU(cpu)
     253#define        _PR_MD_BEGIN_SUSPEND_ALL()
     254#define        _PR_MD_END_SUSPEND_ALL()
     255#define        _PR_MD_BEGIN_RESUME_ALL()
    256256#define        _PR_MD_END_RESUME_ALL()
    257257#define _PR_MD_INIT_ATTACHED_THREAD(thread) PR_FAILURE
     
    294294    PRThread *idle_thread;      /* user-level idle thread for this CPUThread */
    295295
    296     PRIntervalTime last_clock;  /* the last time we went into 
     296    PRIntervalTime last_clock;  /* the last time we went into
    297297                                 * _PR_ClockInterrupt() on this CPU
    298298                                 */
     
    317317#endif
    318318
    319 #ifdef _PR_LOCAL_THREADS_ONLY 
     319#ifdef _PR_LOCAL_THREADS_ONLY
    320320
    321321NSPR_API(struct _PRCPU *)              _pr_currentCPU;
     
    405405    PR_END_MACRO
    406406
    407 #ifdef _PR_LOCAL_THREADS_ONLY 
     407#ifdef _PR_LOCAL_THREADS_ONLY
    408408
    409409#define _PR_IS_NATIVE_THREAD(thread) 0
     
    435435
    436436#define _PR_ADD_SLEEPQ(_thread, _timeout) \
    437     _PR_AddSleepQ(_thread, _timeout);   
     437    _PR_AddSleepQ(_thread, _timeout);
    438438
    439439#define _PR_DEL_SLEEPQ(_thread, _propogate) \
    440     _PR_DelSleepQ(_thread, _propogate); 
     440    _PR_DelSleepQ(_thread, _propogate);
    441441
    442442#define _PR_ADD_JOINQ(_thread, _cpu) \
     
    470470    _PR_MD_LOCK(&(_cpu)->queue->runQLock );\
    471471    PR_END_MACRO
    472    
     472
    473473#define _PR_RUNQ_UNLOCK(_cpu) \
    474474    PR_BEGIN_MACRO \
     
    519519    PR_ASSERT((_thread)->queueCount == 0); \
    520520    (_thread)->queueCount = QUEUE_SLEEP; \
    521     _PR_AddSleepQ(_thread, _timeout); 
     521    _PR_AddSleepQ(_thread, _timeout);
    522522
    523523#define _PR_DEL_SLEEPQ(_thread, _propogate) \
    524524    PR_ASSERT((_thread)->queueCount == QUEUE_SLEEP);\
    525525    (_thread)->queueCount = 0; \
    526     _PR_DelSleepQ(_thread, _propogate); 
     526    _PR_DelSleepQ(_thread, _propogate);
    527527
    528528#define _PR_ADD_JOINQ(_thread, _cpu) \
     
    577577#define _PR_LOCK_UNLOCK(_lock) \
    578578    _PR_MD_UNLOCK(&(_lock)->ilock);
    579    
     579
    580580extern void _PR_UnblockLockWaiter(PRLock *lock);
    581581
     
    586586
    587587#define _PR_CVAR_LOCK(_cvar) \
    588     _PR_MD_LOCK(&(_cvar)->ilock); 
     588    _PR_MD_LOCK(&(_cvar)->ilock);
    589589#define _PR_CVAR_UNLOCK(_cvar) \
    590590    _PR_MD_UNLOCK(&(_cvar)->ilock);
     
    626626#define _PR_STACK_PRIMORDIAL    0x4    /* stack for primordial thread */
    627627
    628 /* 
     628/*
    629629** If the default stcksize from the client is zero, we need to pick a machine
    630630** dependent value.  This is only for standard user threads.  For custom threads,
     
    996996#define    _PR_MD_END_RESUME_ALL _MD_END_RESUME_ALL
    997997
    998 #if defined(IRIX) 
     998#if defined(IRIX)
    999999NSPR_API(void) _PR_IRIX_CHILD_PROCESS(void);
    10001000#endif        /* IRIX */
     
    10171017
    10181018extern PRStatus _PR_MD_CREATE_THREAD(
    1019                         PRThread *thread, 
    1020                         void (*start) (void *), 
    1021                         PRThreadPriority priority,                     
     1019                        PRThread *thread,
     1020                        void (*start) (void *),
     1021                        PRThreadPriority priority,
    10221022                        PRThreadScope scope,
    10231023                        PRThreadState state,
     
    11911191#define    _PR_MD_SHUTDOWN _MD_SHUTDOWN
    11921192
    1193 extern PRInt32 _PR_MD_RECV(PRFileDesc *fd, void *buf, PRInt32 amount, 
     1193extern PRInt32 _PR_MD_RECV(PRFileDesc *fd, void *buf, PRInt32 amount,
    11941194                               PRIntn flags, PRIntervalTime timeout);
    11951195#define    _PR_MD_RECV _MD_RECV
    11961196
    11971197extern PRInt32 _PR_MD_SEND(
    1198     PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags, 
     1198    PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
    11991199    PRIntervalTime timeout);
    12001200#define    _PR_MD_SEND _MD_SEND
    12011201
    1202 extern PRInt32 _PR_MD_ACCEPT_READ(PRFileDesc *sd, PRInt32 *newSock, 
     1202extern PRInt32 _PR_MD_ACCEPT_READ(PRFileDesc *sd, PRInt32 *newSock,
    12031203                                PRNetAddr **raddr, void *buf, PRInt32 amount,
    12041204                                PRIntervalTime timeout);
     
    12061206
    12071207#ifdef WIN32
    1208 extern PRInt32 _PR_MD_FAST_ACCEPT(PRFileDesc *fd, PRNetAddr *addr, 
     1208extern PRInt32 _PR_MD_FAST_ACCEPT(PRFileDesc *fd, PRNetAddr *addr,
    12091209                                PRUint32 *addrlen, PRIntervalTime timeout,
    12101210                                PRBool fast,
     
    12121212                                void *callbackArg);
    12131213
    1214 extern PRInt32 _PR_MD_FAST_ACCEPT_READ(PRFileDesc *sd, PRInt32 *newSock, 
     1214extern PRInt32 _PR_MD_FAST_ACCEPT_READ(PRFileDesc *sd, PRInt32 *newSock,
    12151215                                PRNetAddr **raddr, void *buf, PRInt32 amount,
    12161216                                PRIntervalTime timeout, PRBool fast,
     
    12231223
    12241224extern PRInt32 _PR_MD_SENDFILE(
    1225     PRFileDesc *sock, PRSendFileData *sfd, 
     1225    PRFileDesc *sock, PRSendFileData *sfd,
    12261226        PRInt32 flags, PRIntervalTime timeout);
    12271227#define _PR_MD_SENDFILE _MD_SENDFILE
     
    13011301        } else { \
    13021302                PR_SetError(PR_IO_TIMEOUT_ERROR, 0); \
    1303         }                                                       
    1304                
     1303        }
     1304
    13051305extern void *_PR_MD_GET_SP(PRThread *thread);
    13061306#define    _PR_MD_GET_SP _MD_GET_SP
     
    14541454    struct PRThread *owner;         /* current lock owner */
    14551455    PRCList waitQ;                  /* list of threads waiting for lock */
    1456     PRThreadPriority priority;      /* priority of lock */ 
     1456    PRThreadPriority priority;      /* priority of lock */
    14571457    PRThreadPriority boostPriority; /* boosted priority of lock owner */
    14581458    _MDLock ilock;                  /* Internal Lock to protect user-level fields */
     
    16621662    PRUint32 threadAllocatedOnStack;/* boolean */
    16631663
    1664     /* When an async IO is in progress and a second async IO cannot be 
     1664    /* When an async IO is in progress and a second async IO cannot be
    16651665     * initiated, the io_pending flag is set to true.  Some platforms will
    16661666     * not use the io_pending flag.  If the io_pending flag is true, then
     
    16691669    PRBool io_pending;
    16701670    PRInt32 io_fd;
    1671  
     1671
    16721672    /* If a timeout occurs or if an outstanding IO is interrupted and the
    1673      * OS doesn't support a real cancellation (NT or MAC), then the 
     1673     * OS doesn't support a real cancellation (NT or MAC), then the
    16741674     * io_suspended flag will be set to true.  The thread will be resumed
    16751675     * but may run into trouble issuing additional IOs until the io_pending
    1676      * flag can be cleared 
     1676     * flag can be cleared
    16771677     */
    16781678    PRBool io_suspended;
     
    17441744#endif
    17451745#if !defined(XP_UNIX)   /* BugZilla: 4090 */
    1746     PRBool  appendMode;                             
     1746    PRBool  appendMode;
    17471747#endif
    17481748    _MDFileDesc md;
     
    17621762
    17631763#ifdef MOZ_UNICODE
    1764 struct PRDirUTF16 { 
    1765     PRDirEntry d; 
    1766     _MDDirUTF16 md; 
    1767 }; 
     1764struct PRDirUTF16 {
     1765    PRDirEntry d;
     1766    _MDDirUTF16 md;
     1767};
    17681768#endif /* MOZ_UNICODE */
    17691769
     
    18961896#define    _PR_MD_CREATE_PROCESS _MD_CREATE_PROCESS
    18971897
     1898#ifdef _MD_CREATE_PROCESS_DETACHED
     1899# define _PR_MD_CREATE_PROCESS_DETACHED _MD_CREATE_PROCESS_DETACHED
     1900#endif
     1901
    18981902extern PRStatus _PR_MD_DETACH_PROCESS(PRProcess *process);
    18991903#define    _PR_MD_DETACH_PROCESS _MD_DETACH_PROCESS
     
    19031907
    19041908extern PRStatus _PR_MD_KILL_PROCESS(PRProcess *process);
    1905 #define    _PR_MD_KILL_PROCESS _MD_KILL_PROCESS       
     1909#define    _PR_MD_KILL_PROCESS _MD_KILL_PROCESS
    19061910
    19071911/* Current Time */
     
    20002004** Declare PRSharedMemory.
    20012005*/
    2002 struct PRSharedMemory 
     2006struct PRSharedMemory
    20032007{
    20042008    char        *ipcname; /* after conversion to native */
     
    20182022#define _PR_SHM_IDENT 0xdeadbad
    20192023};
    2020                                                      
    2021 extern PRSharedMemory * _MD_OpenSharedMemory( 
     2024
     2025extern PRSharedMemory * _MD_OpenSharedMemory(
    20222026    const char *name,
    20232027    PRSize      size,
     
    20392043#define _PR_MD_DELETE_SHARED_MEMORY  _MD_DeleteSharedMemory
    20402044
    2041 extern PRFileMap* _md_OpenAnonFileMap( 
     2045extern PRFileMap* _md_OpenAnonFileMap(
    20422046    const char *dirName,
    20432047    PRSize      size,
  • trunk/src/libs/xpcom18a4/nsprpub/pr/src/md/unix/uxproces.c

    r23919 r32971  
    6464#endif
    6565
     66#ifdef VBOX
     67#include <iprt/err.h>
     68#include <iprt/env.h>
     69#include <iprt/process.h>
     70#endif
     71
    6672/*
    6773 **********************************************************************
     
    179185#ifdef VMS
    180186    char VMScurdir[FILENAME_MAX+1] = { '\0' } ;
    181 #endif 
     187#endif
    182188
    183189    process = PR_NEW(PRProcess);
     
    530536
    531537#endif  /* _PR_SHARE_CLONES */
     538
     539#ifdef VBOX
     540PRStatus
     541_MD_CreateUnixProcessDetached(
     542    const char *path,
     543    char *const *argv,
     544    char *const *envp,
     545    const PRProcessAttr *attr)
     546{
     547    int vrc;
     548    int nEnv, idx;
     549    RTENV childEnv;
     550    RTENV newEnv = RTENV_DEFAULT;
     551
     552    if (PR_CallOnce(&pr_wp.once, _MD_InitProcesses) == PR_FAILURE) {
     553            return PR_FAILURE;
     554    }
     555    /* this code doesn't support all attributes */
     556    PR_ASSERT(!attr || !attr->currentDirectory);
     557    PR_ASSERT(!attr || !attr->stdinFd);
     558    PR_ASSERT(!attr || !attr->stdoutFd);
     559    PR_ASSERT(!attr || !attr->stderrFd);
     560    /* no custom environment, please */
     561    PR_ASSERT(!envp);
     562
     563    childEnv = RTENV_DEFAULT;
     564    if (attr && attr->fdInheritBuffer) {
     565        vrc = RTEnvClone(&newEnv, childEnv);
     566        if (RT_FAILURE(vrc))
     567            return PR_FAILURE;
     568        vrc = RTEnvPutEx(newEnv, attr->fdInheritBuffer);
     569        if (RT_FAILURE(vrc))
     570        {
     571            RTEnvDestroy(newEnv);
     572            return PR_FAILURE;
     573        }
     574        childEnv = newEnv;
     575    }
     576
     577    vrc = RTProcCreate(path, (const char **)argv, childEnv,
     578                       RTPROC_FLAGS_DETACHED, NULL);
     579    if (newEnv != RTENV_DEFAULT) {
     580        RTEnvDestroy(newEnv);
     581    }
     582    if (RT_SUCCESS(vrc))
     583        return PR_SUCCESS;
     584    else
     585        return PR_FAILURE;
     586}  /* _MD_CreateUnixProcessDetached */
     587#endif
    532588
    533589/*
     
    688744             * waitpid() cannot return 0 because we did not invoke it
    689745             * with the WNOHANG option.
    690              */ 
     746             */
    691747            PR_ASSERT(0 != pid);
    692748
     
    745801        PR_Lock(pr_wp.ml);
    746802#endif
    747            
     803
    748804        do {
    749805            rv = read(pr_wp.pipefd[0], buf, sizeof(buf));
  • trunk/src/libs/xpcom18a4/nsprpub/pr/src/misc/prinit.c

    r11822 r32971  
    4141#ifdef VBOX_USE_IPRT_IN_NSPR
    4242# include <iprt/initterm.h>
    43 #endif 
     43#endif
    4444
    4545PRLogModuleInfo *_pr_clock_lm;
     
    178178#ifdef VBOX_USE_IPRT_IN_NSPR
    179179    RTR3Init();
    180 #endif 
     180#endif
    181181#ifdef _PR_ZONE_ALLOCATOR
    182182    _PR_InitZones();
     
    200200        _pr_shm_lm = PR_NewLogModule("shm");
    201201        _pr_shma_lm = PR_NewLogModule("shma");
    202      
    203     /* NOTE: These init's cannot depend on _PR_MD_CURRENT_THREAD() */ 
     202
     203    /* NOTE: These init's cannot depend on _PR_MD_CURRENT_THREAD() */
    204204    _PR_MD_EARLY_INIT();
    205205
     
    221221
    222222    _PR_InitThreads(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
    223    
     223
    224224#ifdef WIN16
    225225        {
     
    227227    _pr_top_of_task_stack = (char *) &top;
    228228        }
    229 #endif   
     229#endif
    230230
    231231#ifndef _PR_GLOBAL_THREADS_ONLY
     
    256256        _pr_init_ipv6();
    257257#endif
    258        
     258
    259259    _PR_MD_FINAL_INIT();
    260260}
     
    335335 * _PR_CleanupBeforeExit --
    336336 *
    337  *   Perform the cleanup work before exiting the process. 
     337 *   Perform the cleanup work before exiting the process.
    338338 *   We first do the cleanup generic to all platforms.  Then
    339339 *   we call _PR_MD_CLEANUP_BEFORE_EXIT(), where platform-dependent
     
    350350_PR_CleanupBeforeExit(void)
    351351{
    352 /* 
     352/*
    353353Do not make any calls here other than to destroy resources.  For example,
    354354do not make any calls that eventually may end up in PR_Lock.  Because the
     
    383383 *   PR_Cleanup() does not exit the primordial thread (which would
    384384 *   in turn exit the process).
    385  *   
     385 *
    386386 *   PR_Cleanup() only responds when it is called by the primordial
    387387 *   thread. Calls by any other thread are silently ignored.
     
    481481 *------------------------------------------------------------------------
    482482 * PR_ProcessExit --
    483  * 
     483 *
    484484 *   Cause an immediate, nongraceful, forced termination of the process.
    485485 *   It takes a PRIntn argument, which is the exit status code of the
    486486 *   process.
    487  *   
     487 *
    488488 * See also: PR_Cleanup()
    489489 *
     
    658658                name, (PRIntn)fd->methods->file_type, fd->secret->md.osfd);
    659659    }
    660     attr->fdInheritBufferUsed += nwritten; 
     660    attr->fdInheritBufferUsed += nwritten;
    661661    return PR_SUCCESS;
    662662}
     
    746746    const PRProcessAttr *attr)
    747747{
     748#ifndef _PR_MD_CREATE_PROCESS_DETACHED
    748749    PRProcess *process;
    749750    PRStatus rv;
    750 
     751s
    751752#ifdef XP_OS2
    752753    process = _PR_CreateOS2ProcessEx(path, argv, envp, attr, PR_TRUE);
     
    764765    }
    765766    return PR_SUCCESS;
     767#else /* _PR_MD_CREATE_PROCESS_DETACHED */
     768    return _PR_MD_CREATE_PROCESS_DETACHED(path, argv, envp, attr);
     769#endif /* _PR_MD_CREATE_PROCESS_DETACHED */
    766770}
    767771
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