VirtualBox

Changeset 54705 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Mar 10, 2015 2:02:28 PM (10 years ago)
Author:
vboxsync
Message:

Main: VBoxNetNAT/VBoxNetDHCP: sometimes it's required to kill the runner process (in case of no Main clients)

Location:
trunk/src/VBox/Main
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/include/NetworkServiceRunner.h

    r49517 r54705  
    3737    int setOption(const std::string& key, const std::string& val);
    3838
    39     int start();
    40     int stop();
     39    int  start(bool aKillProcOnStop);
     40    int  stop();
    4141    bool isRunning();
    42 
    4342    void detachFromServer();
    4443
  • trunk/src/VBox/Main/src-server/DHCPServerImpl.cpp

    r54407 r54705  
    4040struct DHCPServer::Data
    4141{
    42     Data() : enabled(FALSE) {}
     42    Data()
     43        : enabled(FALSE)
     44        , router(false)
     45    {}
    4346
    4447    Bstr IPAddress;
     
    4750
    4851    BOOL enabled;
     52    bool router;
    4953    DHCPServerRunner dhcp;
    5054
     
    5559
    5660DHCPServer::DHCPServer()
    57   : m(NULL), mVirtualBox(NULL)
     61  : m(NULL)
     62  , mVirtualBox(NULL)
    5863{
    5964    m = new DHCPServer::Data();
     
    391396    /* Indirect way to understand that we're on NAT network */
    392397    if (aOption == DhcpOpt_Router)
     398    {
    393399        m->dhcp.setOption(NetworkServiceRunner::kNsrKeyNeedMain, "on");
     400        m->router = true;
     401    }
    394402
    395403    alock.release();
     
    566574
    567575    /* XXX: This parameters Dhcp Server will fetch via API */
    568     return RT_FAILURE(m->dhcp.start()) ? E_FAIL : S_OK;
     576    return RT_FAILURE(m->dhcp.start(!m->router /* KillProcOnExit */)) ? E_FAIL : S_OK;
    569577    //m->dhcp.detachFromServer(); /* need to do this to avoid server shutdown on runner destruction */
    570578}
  • trunk/src/VBox/Main/src-server/NATNetworkImpl.cpp

    r50544 r54705  
    797797    }
    798798
    799     if (RT_SUCCESS(m->NATRunner.start()))
     799    if (RT_SUCCESS(m->NATRunner.start(false /* KillProcOnStop */)))
    800800    {
    801801        mVirtualBox->i_onNATNetworkStartStop(Bstr(mName).raw(), TRUE);
     
    813813{
    814814#ifdef VBOX_WITH_NAT_SERVICE
     815    mVirtualBox->i_onNATNetworkStartStop(Bstr(mName).raw(), FALSE);
     816
    815817    if (!m->dhcpServer.isNull())
    816818        m->dhcpServer->Stop();
    817819
    818820    if (RT_SUCCESS(m->NATRunner.stop()))
    819     {
    820         mVirtualBox->i_onNATNetworkStartStop(Bstr(mName).raw(), FALSE);
    821821        return S_OK;
    822     }
     822
    823823    /** @todo missing setError()! */
    824824    return E_FAIL;
  • trunk/src/VBox/Main/src-server/NetworkServiceRunner.cpp

    r54671 r54705  
    2222#include <iprt/param.h>
    2323#include <iprt/env.h>
     24#include <iprt/log.h>
     25#include <iprt/thread.h>
    2426
    2527
    26 const std::string NetworkServiceRunner::kNsrKeyName = "--name";
    27 const std::string NetworkServiceRunner::kNsrKeyNetwork = "--network";
     28const std::string NetworkServiceRunner::kNsrKeyName      = "--name";
     29const std::string NetworkServiceRunner::kNsrKeyNetwork   = "--network";
    2830const std::string NetworkServiceRunner::kNsrKeyTrunkType = "--trunk-type";
    29 const std::string NetworkServiceRunner::kNsrTrunkName = "--trunk-name";
    30 const std::string NetworkServiceRunner::kNsrMacAddress = "--mac-address";
    31 const std::string NetworkServiceRunner::kNsrIpAddress = "--ip-address";
    32 const std::string NetworkServiceRunner::kNsrIpNetmask = "--netmask";
    33 const std::string NetworkServiceRunner::kNsrKeyNeedMain = "--need-main";
     31const std::string NetworkServiceRunner::kNsrTrunkName    = "--trunk-name";
     32const std::string NetworkServiceRunner::kNsrMacAddress   = "--mac-address";
     33const std::string NetworkServiceRunner::kNsrIpAddress    = "--ip-address";
     34const std::string NetworkServiceRunner::kNsrIpNetmask    = "--netmask";
     35const std::string NetworkServiceRunner::kNsrKeyNeedMain  = "--need-main";
    3436
    3537struct NetworkServiceRunner::Data
    3638{
    37     Data(const char* aProcName):mProcName(aProcName), mProcess(NIL_RTPROCESS){}
     39    Data(const char* aProcName)
     40        : mProcName(aProcName)
     41        , mProcess(NIL_RTPROCESS)
     42        , mKillProcOnStop(false)
     43    {}
    3844    const char *mProcName;
    3945    RTPROCESS mProcess;
    4046    std::map<std::string, std::string> mOptions;
     47    bool mKillProcOnStop;
    4148};
    4249
     
    4451{
    4552    m = new NetworkServiceRunner::Data(aProcName);
    46 
    4753}
    4854
     
    6975
    7076
    71 int NetworkServiceRunner::start()
     77int NetworkServiceRunner::start(bool aKillProcOnStop)
    7278{
    7379    if (isRunning())
     
    108114        m->mProcess = NIL_RTPROCESS;
    109115
     116    m->mKillProcOnStop = aKillProcOnStop;
    110117    return rc;
    111118}
     
    114121int NetworkServiceRunner::stop()
    115122{
     123    /*
     124     * If the process already terminated, this function will also grab the exit
     125     * status and transition the process out of zombie status.
     126     */
    116127    if (!isRunning())
    117128        return VINF_OBJECT_DESTROYED;
     129
     130    bool fDoKillProc = true;
     131
     132    if (!m->mKillProcOnStop)
     133    {
     134        /*
     135         * This is a VBoxSVC Main client. Do NOT kill it but assume it was shut
     136         * down politely. Wait up to 1 second until the process is killed before
     137         * doing the final hard kill.
     138         */
     139        int rc = VINF_SUCCESS;
     140        for (unsigned int i = 0; i < 100; i++)
     141        {
     142            rc = RTProcWait(m->mProcess, RTPROCWAIT_FLAGS_NOBLOCK, NULL);
     143            if (RT_SUCCESS(rc))
     144                break;
     145            RTThreadSleep(10);
     146        }
     147        if (rc != VERR_PROCESS_RUNNING)
     148            fDoKillProc = false;
     149    }
     150
     151    if (fDoKillProc)
     152    {
     153        int rc = RTProcTerminate(m->mProcess);
     154        rc = RTProcWait(m->mProcess, RTPROCWAIT_FLAGS_BLOCK, NULL);
     155    }
    118156
    119157    m->mProcess = NIL_RTPROCESS;
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