Exemple #1
0
/*------------------------------------------------------------------------*/
void HandleSigTerm()
/*------------------------------------------------------------------------*/
{
    struct timeval  timeout;
    fd_set          readfds;
    fd_set          writefds;
    int             highfd          = 0;
    int             fdcount         = 0;

    SLPDLog("****************************************\n");
    SLPDLogTime();
    SLPDLog("SLPD daemon shutting down\n");
    SLPDLog("****************************************\n");

    /* close all incoming sockets */
    SLPDIncomingDeinit();

    /* unregister with all DAs */
    SLPDKnownDADeinit();

    timeout.tv_sec  = 5;
    timeout.tv_usec = 0; 

    /* Do a dead DA passive advert to tell everyone we're goin' down */
    SLPDKnownDAPassiveDAAdvert(0, 1);

    /* if possible wait until all outgoing socket are done and closed */
    while(SLPDOutgoingDeinit(1))
    {
        FD_ZERO(&writefds);
        FD_ZERO(&readfds);
        LoadFdSets(&G_OutgoingSocketList, &highfd, &readfds,&writefds);
        fdcount = select(highfd+1,&readfds,&writefds,0,&timeout);
        if(fdcount == 0)
        {
            break;
        }

        SLPDOutgoingHandler(&fdcount,&readfds,&writefds);
    }

    SLPDOutgoingDeinit(0);

    SLPDLog("****************************************\n");
    SLPDLogTime();
    SLPDLog("SLPD daemon shut down\n");
    SLPDLog("****************************************\n");

#ifdef DEBUG
    #ifdef ENABLE_SECURITY
    SLPDSpiDeinit();
    #endif
    SLPDDatabaseDeinit();
    SLPDPropertyDeinit();
    xmalloc_deinit();    
#endif

}
Exemple #2
0
/** Cleans up the User Agent library. 
 *
 * Deinitializes the network sub-system if required, and the debug
 * memory allocator.
 * 
 * @internal
 */
static void ExitUserAgentLibrary(void)
{
   if (SLPAtomicDec(&s_OpenSLPHandleCount) == 0)
   {
      KnownDAFreeAll();
      LIBSLPPropertyCleanup();
#ifdef DEBUG
      xmalloc_deinit();
#endif
#ifdef _WIN32
      WSACleanup();
#endif
      s_HandlesInitialized = false;
   }
}
Exemple #3
0
/*=========================================================================*/
void SLPClose(SLPHandle hSLP)                                             
/*                                                                         */
/* Frees all resources associated with the handle.  If the handle was      */
/* invalid, the function returns silently.  Any outstanding synchronous    */
/* or asynchronous operations are cancelled so their callback functions    */
/* will not be called any further.                                         */
/*                                                                         */
/* SLPHandle    A SLPHandle handle returned from a call to SLPOpen().      */
/*=========================================================================*/
{
    PSLPHandleInfo   handle;

    /*------------------------------*/
    /* check for invalid parameters */
    /*------------------------------*/
    if(hSLP == 0 || *(unsigned int*)hSLP != SLP_HANDLE_SIG)
    {
        return;
    }

    handle = (PSLPHandleInfo)hSLP;

    if(handle->isAsync)
    {
        /* TODO: stop the usage of this handle (kill threads, etc) */
    }

    if(handle->langtag)
    {
        xfree(handle->langtag);
    }

    if(handle->dasock >=0)
    {
        #ifdef WIN32
        closesocket(handle->dasock);
        #else
        close(handle->dasock);
        #endif
    }

    if(handle->dascope)
    {
        xfree(handle->dascope);
    }

    if(handle->sasock >=0)
    {
        #ifdef WIN32
        closesocket(handle->sasock);
        #else
        close(handle->sasock);
        #endif
    }

    if(handle->sascope)
    {
        xfree(handle->sascope);
    }

#ifdef ENABLE_SLPv2_SECURITY
    if(handle->hspi) SLPSpiClose(handle->hspi);
#endif

    handle->sig = 0;  /* If they use the handle again, it won't be valid */

    xfree(hSLP);

    G_OpenSLPHandleCount --;
    

#if DEBUG
    /* Free additional resources if this is the last handle open */
    if(G_OpenSLPHandleCount <= 0)
    {
        G_OpenSLPHandleCount = 0;

        SLPPropertyFreeAll();
        
        KnownDAFreeAll();
        
        xmalloc_deinit();
    }
#endif

}