186 lines
5.1 KiB
C
186 lines
5.1 KiB
C
/* snsRtpHook.c - Socket Name Service hook for RTP deletion */
|
|
|
|
/*
|
|
* Copyright (c) 2004-2007, 2009, 2011, 2013 Wind River Systems, Inc.
|
|
*
|
|
* The right to copy, distribute, modify or otherwise make use
|
|
* of this software may be licensed only pursuant to the terms
|
|
* of an applicable Wind River license agreement.
|
|
*/
|
|
|
|
/*
|
|
modification history
|
|
--------------------
|
|
01g,16sep13,f_f fix static overrun (WIND00435182)
|
|
01f,19jul11,shi LP64 conversion
|
|
01e,03dec09,cww Moved rtp funcbind pointers
|
|
01d,20jun07,ebh remove unnecessary variable taskId in snsRtpHookInit
|
|
01c,08mar06,ebh correct typo as per code review
|
|
01b,12jan05,bwa added check for presence of RTP hooks (SPR105673).
|
|
01a,02sep04,ymz created (moved from snsLib.c)
|
|
*/
|
|
|
|
/*
|
|
DESCRIPTION
|
|
|
|
This file contains routines to invoke socket name service (SNS) to
|
|
cleanup service records when the RTP where the service resides is deleted.
|
|
|
|
During the SNS initialization, SNS adds a routine to the RTP delete hook.
|
|
The initialization process preallocates a socket used by SNS to receive RTP
|
|
delete events.
|
|
When a RTP is deleted, the SNS hook is invoked. The routine sends an
|
|
asynchronous message to the SNS server asking for cleanup.
|
|
|
|
The routines in this file runs in the kernel, no matter whether the SNS
|
|
server is running in the kernel or in a RTP.
|
|
|
|
\NOMANUAL
|
|
*/
|
|
|
|
/* includes */
|
|
|
|
#include <vxWorks.h>
|
|
#include <rtpLibCommon.h>
|
|
#include <stdio.h>
|
|
#include <taskLib.h>
|
|
#include <sockLib.h>
|
|
#include <private/rtpLibP.h>
|
|
#include <dsi/private/salClientP.h>
|
|
#include <dsi/private/snsLibP.h>
|
|
|
|
/* locals */
|
|
|
|
LOCAL int snsCleanUpSockFd; /* socket to sns server to request cleanup */
|
|
|
|
/* forward declarations */
|
|
|
|
LOCAL void snsCleanupRtnInit (void);
|
|
LOCAL void snsCleanupHook (const RTP_ID rtpId, const int exitCode);
|
|
|
|
|
|
/*******************************************************************************
|
|
*
|
|
* snsRtpHookInit - initialize the cleanup mechanism
|
|
*
|
|
* This function initializes the cleanup mechanism. A task is spawned so the
|
|
* vxWorks system initialization process does not get delayed.
|
|
*
|
|
* RETURNS: OK if initialization completes, ERROR otherwise.
|
|
*
|
|
* \NOMANUAL
|
|
*/
|
|
|
|
STATUS snsRtpHookInit
|
|
(
|
|
int pri /* task priority */
|
|
)
|
|
{
|
|
if (_func_rtpDeleteHookAdd == NULL)
|
|
{
|
|
printf ("Can't initialize SNS cleanup subsystem.\n"
|
|
"RTP hooks not present in the system.\n");
|
|
return (ERROR);
|
|
}
|
|
|
|
if((taskSpawn ("tSnsCleanupInit",
|
|
pri, /* priority */
|
|
0, /* task options */
|
|
20000, /* stack space */
|
|
(FUNCPTR) snsCleanupRtnInit,
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0 )) == TASK_ID_ERROR)
|
|
{
|
|
printf(" Cannot spawn SNS cleanup init task...\n");
|
|
return ERROR;
|
|
}
|
|
return OK;
|
|
}
|
|
|
|
/*******************************************************************************
|
|
*
|
|
* snsCleanupRtnInit - initializes SNS cleanup hook
|
|
*
|
|
* This routine initializes SNS cleanup mechanism by setting up RTP
|
|
* deletion hook and attaching a connection to the SNS server.
|
|
*
|
|
* RETURNS: OK if the initialization is successful, ERROR otherwise.
|
|
*
|
|
* \NOMANUAL
|
|
*/
|
|
|
|
LOCAL void snsCleanupRtnInit (void)
|
|
{
|
|
int i; /* number of attempts attaching to SNS server */
|
|
|
|
if ( _func_rtpHandleIdGet == NULL)
|
|
{
|
|
printf(" SNS cleanup init failed...\n");
|
|
return;
|
|
}
|
|
|
|
for (i=0; i<SNS_INIT_RETRY; i++)
|
|
{
|
|
|
|
/* wait if sns server is not started yet */
|
|
|
|
if ((snsCleanUpSockFd = salSnsClientCreate ()) <0)
|
|
taskDelay (SNS_INIT_TIMEOUT*10);
|
|
else
|
|
{
|
|
if (_func_rtpDeleteHookAdd (snsCleanupHook, FALSE) != OK)
|
|
{
|
|
salSnsClientDelete (snsCleanUpSockFd);
|
|
snsCleanUpSockFd = -1;
|
|
printf(" Cannot install SNS cleanup hook...\n");
|
|
return;
|
|
}
|
|
|
|
/* snsCleanUpSockFd remains opened, no close mechanism
|
|
* see comments in snsCleanupHook routine
|
|
*/
|
|
|
|
return;
|
|
}
|
|
}
|
|
|
|
printf(" SNS cleanup init failed...\n");
|
|
|
|
return;
|
|
}
|
|
|
|
/*******************************************************************************
|
|
*
|
|
* snsCleanupHook - notify SNS server a rtp is being deleted.
|
|
*
|
|
* This routine notifies SNS server that a RTP is being deleted.
|
|
*
|
|
* RETURNS: N/A.
|
|
*
|
|
* \NOMANUAL
|
|
*/
|
|
|
|
LOCAL void snsCleanupHook
|
|
(
|
|
const RTP_ID rtpId, /* rtp being deleted */
|
|
const int exitCode
|
|
)
|
|
|
|
{
|
|
SNS_SERV_CLEANUP_MSG msg;
|
|
|
|
msg.cmd = SNS_CMD_CLEANUP;
|
|
msg.rtpId = (long) _func_rtpHandleIdGet (rtpId);
|
|
|
|
(void) send (snsCleanUpSockFd, (void *) &msg, sizeof (SNS_SERV_CLEANUP_MSG),
|
|
MSG_DONTWAIT);
|
|
|
|
/* we do not check if send is fails, just keep sending
|
|
* the alternative is to close the socket and remove delete hook,
|
|
* but it is not safe to delete the hook within the hook routine (the
|
|
* next hook in the hook array may get skipped to call),
|
|
* so we take the policy of doing nothing.
|
|
*/
|
|
|
|
return;
|
|
}
|