Commit 18513780 authored by Benoit Steiner's avatar Benoit Steiner

Debut de gestion des cas tordu dans la gestion du changement de VLAN

(reprise apres crah, corruption de base, etc...)

Bugs fixes dans la gestion de la base du VLANbridge (fonction
GetBaseRecord corrigee).


Benny
parent a3d7d341
...@@ -45,7 +45,6 @@ struct s_Sender sender; ...@@ -45,7 +45,6 @@ struct s_Sender sender;
#define MOD_NAME MOD_VLANBRIDGE #define MOD_NAME MOD_VLANBRIDGE
int ConfigBridge(FILE* hCfgFile, char** pstrLogFile, char** pstrPort) int ConfigBridge(FILE* hCfgFile, char** pstrLogFile, char** pstrPort)
{ {
char* strVarName = NULL; char* strVarName = NULL;
...@@ -69,7 +68,7 @@ int ConfigBridge(FILE* hCfgFile, char** pstrLogFile, char** pstrPort) ...@@ -69,7 +68,7 @@ int ConfigBridge(FILE* hCfgFile, char** pstrLogFile, char** pstrPort)
if (iRc == CFG_OK && !strcmp(strVarName, "Port")) if (iRc == CFG_OK && !strcmp(strVarName, "Port"))
{ {
*pstrPort = strVarVal; *pstrPort = strVarVal;
Log(LOG_NOTE, MOD_NAME, "Default port is %s", *pstrPort); Log(LOG_NOTE, MOD_NAME, "Default port is %s", *pstrPort);
} }
else if (iRc == CFG_OK && !strcmp(strVarName, "Log")) else if (iRc == CFG_OK && !strcmp(strVarName, "Log"))
{ {
......
...@@ -165,9 +165,36 @@ struct s_Record* FindInBase(struct s_Base* psbBase, struct sockaddr_in* psaHost) ...@@ -165,9 +165,36 @@ struct s_Record* FindInBase(struct s_Base* psbBase, struct sockaddr_in* psaHost)
}; };
/***************************************************************************/
/* Return the niumber of entries in the base */
/***************************************************************************/
inline int GetBaseSize(struct s_Base* psbBase) inline int GetBaseSize(struct s_Base* psbBase)
{ {
ASSERT(psbBase); ASSERT(psbBase);
return psbBase->iSize; return psbBase->iSize;
} }
/***************************************************************************/
/* Retrieve an element given by its index from the base */
/***************************************************************************/
struct s_Record* GetBaseRecord(struct s_Base* psbBase, unsigned int uiPos)
{
struct s_Cell* pcCurrent = &psbBase->cFirst;
int iIndex = 0;
ASSERT(psbBase);
if (uiPos >= psbBase->iSize)
return NULL;
else
{
while (iIndex <= uiPos)
{
iIndex++;
pcCurrent = pcCurrent->pcNext;
}
}
return pcCurrent->psrJob;
}
...@@ -40,5 +40,6 @@ int AddToBase(struct s_Base* psbBase, struct s_Record* psrJob); ...@@ -40,5 +40,6 @@ int AddToBase(struct s_Base* psbBase, struct s_Record* psrJob);
int DeleteFromBase(struct s_Base* psbBase, struct sockaddr_in psaHost); int DeleteFromBase(struct s_Base* psbBase, struct sockaddr_in psaHost);
struct s_Record* FindInBase(struct s_Base* psbBase, struct sockaddr_in* psaHost); struct s_Record* FindInBase(struct s_Base* psbBase, struct sockaddr_in* psaHost);
int GetBaseSize(struct s_Base* psbBase); int GetBaseSize(struct s_Base* psbBase);
struct s_Record* GetBaseRecord(struct s_Base* psbBase, unsigned int iPos);
#endif #endif
...@@ -46,7 +46,7 @@ struct s_Fifo* FifoCreate() ...@@ -46,7 +46,7 @@ struct s_Fifo* FifoCreate()
pthread_cond_init(&psfFifo->FifoSignal, NULL); pthread_cond_init(&psfFifo->FifoSignal, NULL);
} }
else else
Log(LOG_ERROR, MOD_NAME, "Could not create fifo"); Log(LOG_ERROR, MOD_NAME, "Could not create FIFO");
return psfFifo; return psfFifo;
} }
...@@ -57,11 +57,11 @@ struct s_Fifo* FifoCreate() ...@@ -57,11 +57,11 @@ struct s_Fifo* FifoCreate()
/***************************************************************************/ /***************************************************************************/
int FifoDestroy(struct s_Fifo* psfFifo) int FifoDestroy(struct s_Fifo* psfFifo)
{ {
pthread_mutex_destroy(&psfFifo->FifoLock); int iRc = pthread_mutex_destroy(&psfFifo->FifoLock);
pthread_cond_destroy(&psfFifo->FifoSignal); iRc |= pthread_cond_destroy(&psfFifo->FifoSignal);
free(psfFifo); free(psfFifo);
return 0; return iRc;
} }
...@@ -130,12 +130,9 @@ int FifoPull(struct s_Fifo* psfFifo, struct s_Request** psrTask) ...@@ -130,12 +130,9 @@ int FifoPull(struct s_Fifo* psfFifo, struct s_Request** psrTask)
{ {
if (psfFifo->iSize == 0) if (psfFifo->iSize == 0)
{ {
// printf("FIFO: %p, psfFifo->iSize == 0\n", psfFifo);
/* Wait for something to be pushed in the stack */ /* Wait for something to be pushed in the stack */
iRc = pthread_cond_wait(&psfFifo->FifoSignal, &psfFifo->FifoLock); iRc = pthread_cond_wait(&psfFifo->FifoSignal, &psfFifo->FifoLock);
} }
// printf("Msg received\n");
/* Release the lock */ /* Release the lock */
iRc |= pthread_mutex_unlock(&psfFifo->FifoLock); iRc |= pthread_mutex_unlock(&psfFifo->FifoLock);
......
...@@ -142,7 +142,12 @@ int Receive(struct s_Listener* share) ...@@ -142,7 +142,12 @@ int Receive(struct s_Listener* share)
struct s_Request* psrRequest = NULL; struct s_Request* psrRequest = NULL;
int iConnectionOK = 1; int iConnectionOK = 1;
int iIndex; int iIndex;
pthread_cond_t condl;
pthread_mutex_t mutexl;
pthread_mutex_init (&mutexl, NULL);
pthread_cond_init (&condl, NULL);
ASSERT(share); ASSERT(share);
Log (LOG_NOTE, MOD_NAME, "Waiting for VLANserver requests"); Log (LOG_NOTE, MOD_NAME, "Waiting for VLANserver requests");
...@@ -217,6 +222,9 @@ void *ListenerThread(void *arg) ...@@ -217,6 +222,9 @@ void *ListenerThread(void *arg)
ASSERT(arg); ASSERT(arg);
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
#ifdef DEBUG #ifdef DEBUG
Log (LOG_NOTE, MOD_NAME, "Listener thread is running"); Log (LOG_NOTE, MOD_NAME, "Listener thread is running");
#endif #endif
...@@ -283,8 +291,10 @@ int CancelListener (struct s_Listener* pslListener) ...@@ -283,8 +291,10 @@ int CancelListener (struct s_Listener* pslListener)
{ {
Log(LOG_NOTE, MOD_NAME, "Stopping listener thread"); Log(LOG_NOTE, MOD_NAME, "Stopping listener thread");
iRc = pthread_cancel(pslListener->tid); iRc = pthread_cancel(pslListener->tid);
printf("listner canceled\n");
/* Synchronise ourselves with the destruction of the thread */ /* Synchronise ourselves with the destruction of the thread */
iRc |= pthread_join(pslListener->tid, NULL); iRc |= pthread_join(pslListener->tid, NULL);
printf("listner joined\n");
/* When the thread is cancelled while waiting for a a socket, it relocks /* When the thread is cancelled while waiting for a a socket, it relocks
the ConnectionLock, so that the sender thread cannot anymore work for the ConnectionLock, so that the sender thread cannot anymore work for
it shares the ConnectionLock with the listener */ it shares the ConnectionLock with the listener */
......
...@@ -49,7 +49,7 @@ int OpenLog (char* strLogName) ...@@ -49,7 +49,7 @@ int OpenLog (char* strLogName)
{ {
iRc = 1; iRc = 1;
/* For debug purposes (Message will be printed to screen) */ /* For debug purposes (Message will be printed to screen) */
Log (LOG_ERROR, MOD_VLANBRIDGE, "Unable to open %s log file: %%\n", Log (LOG_ERROR, MOD_VLANBRIDGE, "Unable to open %s log file: %%",
strLogName, strerror(errno)); strLogName, strerror(errno));
} }
else else
...@@ -75,7 +75,7 @@ int CloseLog () ...@@ -75,7 +75,7 @@ int CloseLog ()
iRc = fclose (fdLogFile); iRc = fclose (fdLogFile);
if (iRc) /* For debug purposes (Message will be printed to screen) */ if (iRc) /* For debug purposes (Message will be printed to screen) */
Log (LOG_WARN, MOD_VLANBRIDGE, "Unable to close log file: %s\n", Log (LOG_WARN, MOD_VLANBRIDGE, "Unable to close log file: %s",
strerror(errno)); strerror(errno));
/* Release the mutex */ /* Release the mutex */
...@@ -86,7 +86,7 @@ int CloseLog () ...@@ -86,7 +86,7 @@ int CloseLog ()
iRc = 1; iRc = 1;
/* For debug purposes (Message will be printed to screen) */ /* For debug purposes (Message will be printed to screen) */
Log (LOG_ERROR, MOD_VLANBRIDGE, Log (LOG_ERROR, MOD_VLANBRIDGE,
"Unable to close log file: file not opened\n"); "Unable to close log file: file not opened");
} }
return iRc; return iRc;
......
...@@ -32,6 +32,8 @@ ...@@ -32,6 +32,8 @@
/* Used to communicate with the sender thread */ /* Used to communicate with the sender thread */
extern struct s_Sender sender; extern struct s_Sender sender;
/* DfltVLAN got from cfgfile */
extern int iVLANDflt;
#define MOD_NAME MOD_MANAGER #define MOD_NAME MOD_MANAGER
...@@ -87,8 +89,8 @@ int StartTask (struct s_Manager* psmManager, struct s_Request* psrRequest) ...@@ -87,8 +89,8 @@ int StartTask (struct s_Manager* psmManager, struct s_Request* psrRequest)
/* Store the address of the field to avoid a new lookup in the base */ /* Store the address of the field to avoid a new lookup in the base */
psrRequest->psRecord = psrHostStatus; psrRequest->psRecord = psrHostStatus;
/* This is not the first request of this client */ /* No potential misconfiguration detected so far */
psrRequest->iFirstTime = 0; psrRequest->iMisconfig = 0;
/* Compare the request with the data in the stack and modify it if needed */ /* Compare the request with the data in the stack and modify it if needed */
if (psrRequest->iVLANsrc != psrHostStatus->iCurrentVLAN) if (psrRequest->iVLANsrc != psrHostStatus->iCurrentVLAN)
...@@ -96,11 +98,13 @@ int StartTask (struct s_Manager* psmManager, struct s_Request* psrRequest) ...@@ -96,11 +98,13 @@ int StartTask (struct s_Manager* psmManager, struct s_Request* psrRequest)
Log(LOG_WARN, MOD_NAME, "%s is on VLAN %d in our database, in VLAN %d for VLANserver", Log(LOG_WARN, MOD_NAME, "%s is on VLAN %d in our database, in VLAN %d for VLANserver",
inet_ntoa(psrRequest->saClientIP.sin_addr), psrHostStatus->iCurrentVLAN, inet_ntoa(psrRequest->saClientIP.sin_addr), psrHostStatus->iCurrentVLAN,
psrRequest->iVLANsrc); psrRequest->iVLANsrc);
psrRequest->iMisconfig = 1;
psrRequest->iVLANsrc = psrHostStatus->iCurrentVLAN; psrRequest->iVLANsrc = psrHostStatus->iCurrentVLAN;
} }
// if (memcmp(&psrRequest->saClientMAC, &psrHostStatus->saClientMAC, // if (memcmp(&psrRequest->saClientMAC, &psrHostStatus->saClientMAC,
// sizeof(psrRequest->saClientMAC)) // sizeof(psrRequest->saClientMAC))
// { // {
// psrRequest->iMisconfig = 1;
// psrHostStatus->saClientMAC = psrRequest->saClientMAC; // psrHostStatus->saClientMAC = psrRequest->saClientMAC;
// Log(LOG_WARN, MOD_NAME, "MAC error, problems will arise\n"); // Log(LOG_WARN, MOD_NAME, "MAC error, problems will arise\n");
// } // }
...@@ -108,9 +112,17 @@ int StartTask (struct s_Manager* psmManager, struct s_Request* psrRequest) ...@@ -108,9 +112,17 @@ int StartTask (struct s_Manager* psmManager, struct s_Request* psrRequest)
} }
else else
{ {
/* This is the first request of this client */ /* Check for potential further problems */
psrRequest->iFirstTime = 1; if (psrRequest->iVLANsrc != iVLANDflt)
{
/* For us, this host is on DfltVLAN whatever the VLANserver says */
psrRequest->iVLANsrc = iVLANDflt;
/* But this could lead to pbs */
psrRequest->iMisconfig = 1;
}
else
psrRequest->iMisconfig = 0;
/* Add an entry in the base and store its address in the request */ /* Add an entry in the base and store its address in the request */
Log(LOG_NOTE, MOD_NAME, "Host does not exist in database: adding it"); Log(LOG_NOTE, MOD_NAME, "Host does not exist in database: adding it");
psrRequest->psRecord = malloc(sizeof(struct s_Base)); psrRequest->psRecord = malloc(sizeof(struct s_Base));
...@@ -149,7 +161,12 @@ int FinishTask (struct s_Manager* psmManager, struct s_Request* psrTask) ...@@ -149,7 +161,12 @@ int FinishTask (struct s_Manager* psmManager, struct s_Request* psrTask)
#endif #endif
/* Save client status to database */ /* Save client status to database */
psrTask->psRecord->iCurrentVLAN = psrTask->iVLANdst; if (psrTask->iStatus == VLAN_ROUTE_OK)
psrTask->psRecord->iCurrentVLAN = psrTask->iVLANdst;
/* else
the configuration is the same as before the request, nothing to save */
/* We now accept another request for that client */
psrTask->psRecord->iThread = 0; psrTask->psRecord->iThread = 0;
/* Warn VLANserver */ /* Warn VLANserver */
...@@ -161,21 +178,25 @@ int FinishTask (struct s_Manager* psmManager, struct s_Request* psrTask) ...@@ -161,21 +178,25 @@ int FinishTask (struct s_Manager* psmManager, struct s_Request* psrTask)
/***************************************************************************/ /***************************************************************************/
/* Wait for all tasks the manager has to monitor to finish */ /* Wait for all tasks the manager has to monitor to finish */
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!! A REFAIRE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
/***************************************************************************/ /***************************************************************************/
int FinishAllTasks(struct s_Manager* psmConfig) int FinishAllTasks(struct s_Manager* psmConfig)
{ {
int iRc = 0; int iRc = 0, iIndex = 0;
int iRunningPerformers = 0; int iRunningPerformers = 0;
struct s_Request* psrFinishedJob = NULL; struct s_Request* psrFinishedJob = NULL;
ASSERT(psmConfig); ASSERT(psmConfig);
/* Count performers that are currently running */ /* Count performers that are currently running */
iRunningPerformers = GetBaseSize(psmConfig->psbBase); if (GetBaseSize(psmConfig->psbBase) > 0)
{
// printf("Base addresss: %p\n", psmConfig->psbBase); for(iIndex = 0; iIndex < GetBaseSize(psmConfig->psbBase); iIndex++)
{
if (GetBaseRecord(psmConfig->psbBase, iIndex)->iThread != 0)
iRunningPerformers++;
}
}
Log(LOG_NOTE, MOD_NAME, "Waiting for the %d running performers to finish", Log(LOG_NOTE, MOD_NAME, "Waiting for the %d running performers to finish",
iRunningPerformers); iRunningPerformers);
...@@ -368,8 +389,7 @@ inline int CancelManager(struct s_Manager* psmManager) ...@@ -368,8 +389,7 @@ inline int CancelManager(struct s_Manager* psmManager)
psrRequest = malloc(sizeof(struct s_Request)); psrRequest = malloc(sizeof(struct s_Request));
iRc = pthread_mutex_lock (&psmManager->WorkLock); iRc = pthread_mutex_lock (&psmManager->WorkLock);
// printf ("Got lock\n"); // printf ("Got lock\n");
if (iRc) if (iRc)
Log(LOG_ERROR, MOD_NAME, "Could not lock mutex: %s", strerror(iRc)); Log(LOG_ERROR, MOD_NAME, "Could not lock mutex: %s", strerror(iRc));
...@@ -426,6 +446,9 @@ int FreeManager(struct s_Manager* psmManager) ...@@ -426,6 +446,9 @@ int FreeManager(struct s_Manager* psmManager)
// printf("Base destroyed\n"); // printf("Base destroyed\n");
iRc = FifoDestroy(psmManager->psfWaitingJobs);
if (iRc)
Log(LOG_ERROR, MOD_NAME, "Unable to free manager FIFO");
iRc |= pthread_mutex_destroy (&psmManager->WorkLock); iRc |= pthread_mutex_destroy (&psmManager->WorkLock);
iRc |= pthread_cond_destroy (&psmManager->WorkSignal); iRc |= pthread_cond_destroy (&psmManager->WorkSignal);
......
...@@ -413,8 +413,6 @@ int InitArp(FILE* hCfgFile) ...@@ -413,8 +413,6 @@ int InitArp(FILE* hCfgFile)
/***************************************************************************/ /***************************************************************************/
/* */ /* */
/* BEWARE: We never have route to DFLT_VLAN, for we use the default route */
/* to forward packets to this VLAN */
/* We always try to keep ARP and route tables synchronised, so we */ /* We always try to keep ARP and route tables synchronised, so we */
/* test that routing operations were OK before updating the ARP table */ /* test that routing operations were OK before updating the ARP table */
/* If something goes wrong, we try to go back to previous config */ /* If something goes wrong, we try to go back to previous config */
...@@ -440,13 +438,17 @@ int UpdateTables (struct s_Request* psrJob) ...@@ -440,13 +438,17 @@ int UpdateTables (struct s_Request* psrJob)
} }
/* Delete previous entries */ /* Delete previous entries */
if (!iRc && psrJob->iFirstTime != 1) if (!iRc)
{ {
/* We never have route to DFLT_VLAN, for we use the default route to forward
packets to this VLAN */
if (psrJob->iVLANsrc != iVLANDflt) if (psrJob->iVLANsrc != iVLANDflt)
iRc = Route_Del(iSockFd, &psrJob->saClientIP, strMapToDev[psrJob->iVLANsrc]); iRc = Route_Del(iSockFd, &psrJob->saClientIP, strMapToDev[psrJob->iVLANsrc]);
if (!iRc) /* To keep the entries consistent */ /* !iRc to keep the entries consistent and if VLANsrc == VLANdst, there is not
iRc = Arp_Del(&psrJob->saClientIP, strMapToDev[psrJob->iVLANsrc], iSockFd); entry to delete on VLANdst unless it is the first time */
if (!iRc && (psrJob->iVLANdst != psrJob->iVLANsrc))
iRc = Arp_Del(&psrJob->saClientIP, strMapToDev[psrJob->iVLANdst], iSockFd);
} }
/* If both entries where deleted or none existed, add the new ones */ /* If both entries where deleted or none existed, add the new ones */
...@@ -457,12 +459,11 @@ int UpdateTables (struct s_Request* psrJob) ...@@ -457,12 +459,11 @@ int UpdateTables (struct s_Request* psrJob)
if (iRc) if (iRc)
{ {
/* Error: Cancel all modifications /* Error: Cancel all modifications */
As it won't be the first time anymore, create entries in the ARP and routing if (psrJob->iVLANdst != psrJob->iVLANsrc)
tables even if they didn't exist before the request */ iRc |= Arp_Add(&psrJob->saClientIP, strMapToDev[psrJob->iVLANdst], iSockFd);
iRc |= Arp_Add(&psrJob->saClientIP, strMapToDev[psrJob->iVLANsrc], iSockFd);
if (psrJob->iVLANsrc != iVLANDflt) if (psrJob->iVLANsrc != iVLANDflt)
iRc = Route_Add(iSockFd, &psrJob->saClientIP, strMapToDev[psrJob->iVLANsrc]); iRc |= Route_Add(iSockFd, &psrJob->saClientIP, strMapToDev[psrJob->iVLANsrc]);
} }
else else
{ {
...@@ -470,12 +471,13 @@ int UpdateTables (struct s_Request* psrJob) ...@@ -470,12 +471,13 @@ int UpdateTables (struct s_Request* psrJob)
If VLANdst == VLANsrc, we won't proxy for the host on the VLAN on which If VLANdst == VLANsrc, we won't proxy for the host on the VLAN on which
it stays, so don't add any entry */ it stays, so don't add any entry */
if (psrJob->iVLANdst != psrJob->iVLANsrc) if (psrJob->iVLANdst != psrJob->iVLANsrc)
iRc = Arp_Add(&psrJob->saClientIP, strMapToDev[psrJob->iVLANdst], iSockFd); iRc = Arp_Add(&psrJob->saClientIP, strMapToDev[psrJob->iVLANsrc], iSockFd);
if (iRc) if (iRc)
{ {
/* Error: cancel all modifications even if it's the first time */ /* Error: cancel all modifications */
iRc = Arp_Add(&psrJob->saClientIP, strMapToDev[psrJob->iVLANsrc], iSockFd); if (psrJob->iVLANdst != psrJob->iVLANsrc)
iRc = Arp_Add(&psrJob->saClientIP, strMapToDev[psrJob->iVLANdst], iSockFd);
if (psrJob->iVLANdst != iVLANDflt) if (psrJob->iVLANdst != iVLANDflt)
iRc |= Route_Del(iSockFd, &psrJob->saClientIP, strMapToDev[psrJob->iVLANdst]); iRc |= Route_Del(iSockFd, &psrJob->saClientIP, strMapToDev[psrJob->iVLANdst]);
if (psrJob->iVLANsrc != iVLANDflt) if (psrJob->iVLANsrc != iVLANDflt)
...@@ -578,15 +580,16 @@ void* PerformerThread (void* pvArg) ...@@ -578,15 +580,16 @@ void* PerformerThread (void* pvArg)
} }
/* Synchronise with the VLAN change */ /* Synchronise with the VLAN change */
else if ((iRc = Pinger_DetectMove (&spPingerCfg, &iHasMoved))) else if ((iRc = Pinger_DetectMove(&spPingerCfg, &iHasMoved)))
{ {
psrJob->iStatus = VLAN_ERROR; psrJob->iStatus = VLAN_ERROR;
Log (LOG_ERROR, MOD_NAME, "Could not ping %s: aborting", Log (LOG_ERROR, MOD_NAME, "Could not ping %s: aborting",
inet_ntoa(psrJob->saClientIP.sin_addr)); inet_ntoa(psrJob->saClientIP.sin_addr));
} }
/* Check the client has moved before updating the bridge config */ /* Check the client has moved before updating the bridge config
else if (iHasMoved == 0) Only rely on that if no misconfiguration was detected */
else if (iHasMoved == 0 && psrJob->iMisconfig == 0)
{ {
Log (LOG_WARN, MOD_NAME, "%s has not moved: aborting", Log (LOG_WARN, MOD_NAME, "%s has not moved: aborting",
inet_ntoa(psrJob->saClientIP.sin_addr)); inet_ntoa(psrJob->saClientIP.sin_addr));
...@@ -596,7 +599,8 @@ void* PerformerThread (void* pvArg) ...@@ -596,7 +599,8 @@ void* PerformerThread (void* pvArg)
/* Update the bridge tables */ /* Update the bridge tables */
else else
{ {
/* Change routing and ARP tables */ /* Change routing and ARP tables
This process is done in order to try to repare misconfigurations */
iRc = UpdateTables(psrJob); iRc = UpdateTables(psrJob);
if (iRc) if (iRc)
...@@ -685,9 +689,10 @@ int RunPerformer (struct s_Request* psrPerfId) ...@@ -685,9 +689,10 @@ int RunPerformer (struct s_Request* psrPerfId)
/***************************************************************************/ /***************************************************************************/
int FreePerformer (const struct s_Request* psrPerfId) int FreePerformer (const struct s_Request* psrPerfId)
{ {
int iRc = pthread_join (psrPerfId->ptId, NULL); int iRc;
ASSERT(psrPerfId); ASSERT(psrPerfId);
iRc = pthread_join(psrPerfId->ptId, NULL);
if (iRc) if (iRc)
Log (LOG_NOTE, MOD_NAME, "Cannot join thread %d: %s", Log (LOG_NOTE, MOD_NAME, "Cannot join thread %d: %s",
......
...@@ -29,7 +29,7 @@ struct s_Request ...@@ -29,7 +29,7 @@ struct s_Request
/* Internal information used by the VLANbridge threads */ /* Internal information used by the VLANbridge threads */
pthread_t ptId; /* Id of the performer that will handle the request */ pthread_t ptId; /* Id of the performer that will handle the request */
int iNextStep; /* What must we do next ? */ int iNextStep; /* What must we do next ? */
int iFirstTime; /* Is this the first request of that client ? */ int iMisconfig; /* Did we detect a potential misconfiguration ? */
struct s_Record* psRecord; /* Corresponding entry in the database*/ struct s_Record* psRecord; /* Corresponding entry in the database*/
}; };
......
...@@ -170,6 +170,11 @@ int Answer(struct s_Sender *share) ...@@ -170,6 +170,11 @@ int Answer(struct s_Sender *share)
int iRc = 0; int iRc = 0;
int iConnectionOK = 1 ; int iConnectionOK = 1 ;
pthread_cond_t conds;
pthread_mutex_t mutexs;
pthread_mutex_init (&mutexs, NULL);
pthread_cond_init (&conds, NULL);
ASSERT(share); ASSERT(share);
while (iConnectionOK > 0) while (iConnectionOK > 0)
...@@ -220,7 +225,10 @@ void* SenderThread (void* arg) ...@@ -220,7 +225,10 @@ void* SenderThread (void* arg)
int iRc = 0; int iRc = 0;
ASSERT(arg); ASSERT(arg);
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
#ifdef DEBUG #ifdef DEBUG
Log (LOG_NOTE, MOD_NAME, "Sender thread is running"); Log (LOG_NOTE, MOD_NAME, "Sender thread is running");
#endif #endif
...@@ -290,10 +298,11 @@ int CancelSender(struct s_Sender* pssSender) ...@@ -290,10 +298,11 @@ int CancelSender(struct s_Sender* pssSender)
Log(LOG_NOTE, MOD_NAME, "Stopping sender thread"); Log(LOG_NOTE, MOD_NAME, "Stopping sender thread");
iRc = pthread_cancel(pssSender->tid); iRc = pthread_cancel(pssSender->tid);
printf("Sender thread canceled\n");
/* Synchronise ourselves with the destruction of the thread, to avoid to destroy /* Synchronise ourselves with the destruction of the thread, to avoid to destroy
the condition while the sender is waiting on it */ the condition while the sender is waiting on it */
iRc |= pthread_join(pssSender->tid, NULL); iRc |= pthread_join(pssSender->tid, NULL);
printf("Sender thread joined\n");
/* When the thread is cancelled while waiting for a a socket, it relocks /* When the thread is cancelled while waiting for a a socket, it relocks
the ConnectionLock, so that the sender thread cannot anymore work for the ConnectionLock, so that the sender thread cannot anymore work for
it shares the ConnectionLock with the listener */ it shares the ConnectionLock with the listener */
...@@ -319,6 +328,7 @@ int FreeSender(struct s_Sender* pssSender) ...@@ -319,6 +328,7 @@ int FreeSender(struct s_Sender* pssSender)
if (pssSender->tid != 0) if (pssSender->tid != 0)
{ {
iRc = pthread_cond_destroy(&pssSender->WakeUpSignal); iRc = pthread_cond_destroy(&pssSender->WakeUpSignal);
iRc |= FifoDestroy(pssSender->psfWaitingAnswers);
if (!iRc) if (!iRc)
Log(LOG_NOTE, MOD_NAME, "Sender thread destroyed"); Log(LOG_NOTE, MOD_NAME, "Sender thread destroyed");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment