VirtualBox

Changeset 53421 in vbox for trunk/src


Ignore:
Timestamp:
Dec 1, 2014 4:00:30 PM (10 years ago)
Author:
vboxsync
Message:

VBoxGuestLib: add re-spawn option to VbglR3Daemonize().

Location:
trunk/src/VBox/Additions
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3LibDaemonize.cpp

    r48938 r53421  
    4343# include <sys/types.h>
    4444# include <sys/stat.h>
     45# include <sys/wait.h>
    4546# include <stdio.h>
    4647# include <fcntl.h>
     
    6667 * @param   fNoChDir    Pass false to change working directory to root.
    6768 * @param   fNoClose    Pass false to redirect standard file streams to /dev/null.
     69 * @param   fRespawn    Restart the daemonised process after five seconds if it
     70 *                      terminates abnormally.
    6871 *
    6972 * @todo    Use RTProcDaemonize instead of this.
    70  */
    71 VBGLR3DECL(int) VbglR3Daemonize(bool fNoChDir, bool fNoClose)
     73 * @todo    Implement fRespawn on OS/2.
     74 * @todo    Make the respawn interval configurable.  But not until someone
     75 *          actually needs that.
     76 */
     77VBGLR3DECL(int) VbglR3Daemonize(bool fNoChDir, bool fNoClose, bool fRespawn)
    7278{
    7379#if defined(RT_OS_OS2)
     
    7682    DosGetInfoBlocks(&pTib, &pPib);
    7783
     84    AssertRelease(!fRespawn);
    7885    /* Get the full path to the executable. */
    7986    char szExe[CCHMAXPATH];
     
    211218# endif /* RT_OS_LINUX */
    212219
     220    if (fRespawn)
     221        /* We implement re-spawning as a third fork(), with the parent process
     222         * monitoring the child and re-starting it after a delay if it exits
     223         * abnormally. */
     224        for (;;)
     225        {
     226            int iStatus, rcWait;
     227
     228            pid = fork();
     229            if (pid == -1)
     230                return RTErrConvertFromErrno(errno);
     231            if (pid == 0)
     232                return VINF_SUCCESS;
     233            do
     234                rcWait = waitpid(pid, &iStatus, 0);
     235            while (rcWait == -1 && errno == EINTR);
     236            if (rcWait == -1)
     237                exit(1);
     238            if (WIFEXITED(iStatus) && WEXITSTATUS(iStatus) == 0)
     239                exit(0);
     240            sleep(5);
     241        }
    213242    return VINF_SUCCESS;
    214243#endif
  • trunk/src/VBox/Additions/common/VBoxService/VBoxService.cpp

    r52890 r53421  
    10981098#else
    10991099        VBoxServiceVerbose(1, "Daemonizing...\n");
    1100         rc = VbglR3Daemonize(false /* fNoChDir */, false /* fNoClose */);
     1100        rc = VbglR3Daemonize(false /* fNoChDir */, false /* fNoClose */,
     1101                             false /* fRespawn */);
    11011102        if (RT_FAILURE(rc))
    11021103            return VBoxServiceError("Daemon failed: %Rrc\n", rc);
  • trunk/src/VBox/Additions/x11/VBoxClient/main.cpp

    r52647 r53421  
    271271int main(int argc, char *argv[])
    272272{
    273     bool fDaemonise = true;
     273    bool fDaemonise = true, fRespawn = true;
    274274    int rc;
    275275    const char *pcszFileName, *pcszStage;
     
    311311            fDaemonise = false;
    312312        }
     313        else if (!strcmp(argv[i], "--no-respawn"))
     314        {
     315            fRespawn = false;
     316        }
    313317        else if (!strcmp(argv[i], "--clipboard"))
    314318        {
     
    373377        VBClFatalError(("Creating pid-file path: %Rrc\n", rc));
    374378    if (fDaemonise)
    375         rc = VbglR3Daemonize(false /* fNoChDir */, false /* fNoClose */);
     379        rc = VbglR3Daemonize(false /* fNoChDir */, false /* fNoClose */, fRespawn);
    376380    if (RT_FAILURE(rc))
    377381        VBClFatalError(("Daemonizing: %Rrc\n", rc));
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