VirtualBox

Ignore:
Timestamp:
Nov 9, 2023 6:27:01 PM (15 months ago)
Author:
vboxsync
Message:

libs/xpcom/ipc: Rewrote the IPC daemon startup code to use IPRT directly instead of NSPR, bugref:10545

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/libs/xpcom18a4/ipc/ipcd/daemon/src/ipcdUnix.cpp

    r101982 r102047  
    5050#endif
    5151
    52 #ifdef VBOX
    53 # include <iprt/initterm.h>
    54 #endif
     52#include <iprt/initterm.h>
     53#include <iprt/getopt.h>
     54#include <iprt/message.h>
    5555
    5656#include "prio.h"
     
    458458    PRNetAddr addr;
    459459
    460 #ifdef VBOX
    461460    /* Set up the runtime without loading the support driver. */
    462     RTR3InitExe(argc, &argv, 0);
    463 #endif
     461    int vrc = RTR3InitExe(argc, &argv, 0);
     462    if (RT_FAILURE(vrc))
     463        return RTMsgInitFailure(vrc);
     464
     465    /*
     466     * Parse the command line.
     467     */
     468    static RTGETOPTDEF const s_aOptions[] =
     469    {
     470        { "--inherit-startup-pipe", 'f', RTGETOPT_REQ_UINT32 },
     471        { "--socket-path",          'p', RTGETOPT_REQ_STRING },
     472    };
     473
     474    RTGETOPTSTATE State;
     475    vrc = RTGetOptInit(&State, argc, argv, &s_aOptions[0], RT_ELEMENTS(s_aOptions), 1,  RTGETOPTINIT_FLAGS_OPTS_FIRST);
     476    if (RT_FAILURE(vrc))
     477        return RTMsgErrorExit(RTEXITCODE_FAILURE, "RTGetOptInit failed: %Rrc", vrc);
     478
     479    uint32_t        uStartupPipeFd = UINT32_MAX;
     480    const char      *pszSocketPath = NULL;
     481    RTGETOPTUNION   ValueUnion;
     482    int             chOpt;
     483    while ((chOpt = RTGetOpt(&State, &ValueUnion)) != 0)
     484    {
     485        switch (chOpt)
     486        {
     487            case 'f':
     488                uStartupPipeFd = ValueUnion.u32;
     489                break;
     490            case 'p':
     491                pszSocketPath = ValueUnion.psz;
     492                break;
     493            default:
     494                return RTGetOptPrintError(chOpt, &ValueUnion);
     495        }
     496    }
    464497
    465498    //
     
    482515    // set socket address
    483516    addr.local.family = PR_AF_LOCAL;
    484     if (argc < 2)
     517    if (!pszSocketPath)
    485518        IPC_GetDefaultSocketPath(addr.local.path, sizeof(addr.local.path));
    486519    else
    487         PL_strncpyz(addr.local.path, argv[1], sizeof(addr.local.path));
     520        PL_strncpyz(addr.local.path, pszSocketPath, sizeof(addr.local.path));
    488521
    489522#ifdef IPC_USE_FILE_LOCK
     
    493526            LOG(("Another daemon is already running, exiting.\n"));
    494527            // send a signal to the blocked parent to indicate success
    495             IPC_NotifyParent();
     528            IPC_NotifyParent(uStartupPipeFd);
    496529            return 0;
    497530        }
     
    500533            // don't notify the parent to cause it to fail in PR_Read() after
    501534            // we terminate
    502 #ifdef VBOX
    503535            if (status != ELockFileOwner)
    504536                printf("Cannot create a lock file for '%s'.\n"
    505537                        "Check permissions.\n", addr.local.path);
    506 #endif
    507538            return 0;
    508539        }
     
    518549    }
    519550    else {
    520 #ifdef VBOX
    521551        // Use large backlog, as otherwise local sockets can reject connection
    522552        // attempts. Usually harmless, but causes an unnecessary start attempt
     
    524554        // usually succeeds. But better avoid unnecessary activities.
    525555        if (PR_Listen(listenFD, 128) != PR_SUCCESS) {
    526 #else /* !VBOX */
    527         if (PR_Listen(listenFD, 5) != PR_SUCCESS) {
    528 #endif /* !VBOX */
    529556            LOG(("PR_Listen failed [%d]\n", PR_GetError()));
    530557        }
    531558        else {
    532 #ifndef VBOX
    533             // redirect all standard file descriptors to /dev/null for
    534             // proper daemonizing
    535             PR_Close(PR_STDIN);
    536             PR_Open("/dev/null", O_RDONLY, 0);
    537             PR_Close(PR_STDOUT);
    538             PR_Open("/dev/null", O_WRONLY, 0);
    539             PR_Close(PR_STDERR);
    540             PR_Open("/dev/null", O_WRONLY, 0);
    541 #endif
    542 
    543             IPC_NotifyParent();
     559
     560            IPC_NotifyParent(uStartupPipeFd);
    544561
    545562#if defined(VBOX) && !defined(XP_OS2)
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