Commit 7e3814a2 authored by Benoit Steiner's avatar Benoit Steiner

Corrige un dernier bug dans la gestion du changement de vlan

Ajoute du code crade pour voir ou est l'erreur dans la cancellation des
threads

renomme VLANbridge.[c,h] en vlanbridge.[c,h]

2/3 autres trucs que j'ai oublie :)

Benny
parent 18513780
......@@ -44,7 +44,7 @@ LIB += -lpthread
############ Beginning of the files description section ############
OBJ = \
VLANbridge.o \
vlanbridge.o \
manager.o \
listener.o \
sender.o \
......
......@@ -99,8 +99,7 @@ int DestroyBase(struct s_Base* psbBase)
/***************************************************************************/
/* Add an element at the end of the list (before the 'last' element) */
/***************************************************************************/
/* Add an element at the end of the list (before the 'last' element) *//***************************************************************************/
int AddToBase(struct s_Base* psbBase, struct s_Record* psrNewMember)
{
int iRc = 0;
......@@ -110,7 +109,6 @@ int AddToBase(struct s_Base* psbBase, struct s_Record* psrNewMember)
ASSERT(psrNewMember);
// printf("Adding to base\n");
if ((pcNewCell = (struct s_Cell *)malloc(sizeof(struct s_Cell))) > 0)
{
......
......@@ -14,6 +14,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <pthread.h>
#include <string.h>
#include <net/if.h>
#include <netinet/in.h>
......@@ -58,7 +59,11 @@ struct s_Fifo* FifoCreate()
int FifoDestroy(struct s_Fifo* psfFifo)
{
int iRc = pthread_mutex_destroy(&psfFifo->FifoLock);
printf("FIFO mutex destruction: %s\n", strerror(iRc));
iRc |= pthread_cond_destroy(&psfFifo->FifoSignal);
printf("FIFO cond destruction: iRc %d, %s\n", iRc, strerror(iRc));
free(psfFifo);
return iRc;
......
......@@ -291,10 +291,10 @@ int CancelListener (struct s_Listener* pslListener)
{
Log(LOG_NOTE, MOD_NAME, "Stopping listener thread");
iRc = pthread_cancel(pslListener->tid);
printf("listner canceled\n");
printf("listner canceled with iRc %d\n", iRc);
/* Synchronise ourselves with the destruction of the thread */
iRc |= pthread_join(pslListener->tid, NULL);
printf("listner joined\n");
printf("listner joined with iRc %d\n", iRc);
/* When the thread is cancelled while waiting for a a socket, it relocks
the ConnectionLock, so that the sender thread cannot anymore work for
it shares the ConnectionLock with the listener */
......@@ -321,6 +321,8 @@ int FreeListener(struct s_Listener* pslListener)
{
iRc |= pthread_cond_destroy(&pslListener->WakeUpSignal);
printf("Listener cond destroyed with iRc %d\n", iRc);
/* No more listener is running */
pslListener->tid = 0;
......
......@@ -75,8 +75,6 @@ int StartTask (struct s_Manager* psmManager, struct s_Request* psrRequest)
if (psrHostStatus != NULL)
{
// printf ("Host found in database\n");
/* Don't want to deal with 2 requests for the same host at the same time */
if (psrHostStatus->iThread != 0)
{
......@@ -101,13 +99,6 @@ int StartTask (struct s_Manager* psmManager, struct s_Request* psrRequest)
psrRequest->iMisconfig = 1;
psrRequest->iVLANsrc = psrHostStatus->iCurrentVLAN;
}
// if (memcmp(&psrRequest->saClientMAC, &psrHostStatus->saClientMAC,
// sizeof(psrRequest->saClientMAC))
// {
// psrRequest->iMisconfig = 1;
// psrHostStatus->saClientMAC = psrRequest->saClientMAC;
// Log(LOG_WARN, MOD_NAME, "MAC error, problems will arise\n");
// }
}
}
else
......@@ -127,6 +118,7 @@ int StartTask (struct s_Manager* psmManager, struct s_Request* psrRequest)
Log(LOG_NOTE, MOD_NAME, "Host does not exist in database: adding it");
psrRequest->psRecord = malloc(sizeof(struct s_Base));
psrRequest->psRecord->saHost = psrRequest->saClientIP;
psrRequest->psRecord->iCurrentVLAN = iVLANDflt;
iRc = AddToBase(psmManager->psbBase, psrRequest->psRecord);
}
......
......@@ -42,6 +42,12 @@ extern pthread_mutex_t ConnectionLock;
#define MOD_NAME MOD_SENDER
void clean_toto(void* pvSenderFifo)
{
pthread_cond_signal(&((struct s_Fifo*)pvSenderFifo)->FifoSignal);
// pthread_mutex_trylock(&ConnectionLock);
pthread_mutex_unlock(&ConnectionLock);
}
/***************************************************************************/
......@@ -226,6 +232,8 @@ void* SenderThread (void* arg)
ASSERT(arg);
pthread_cleanup_push(&clean_toto, sender->psfWaitingAnswers);
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
......@@ -278,6 +286,8 @@ void* SenderThread (void* arg)
}
}
pthread_cleanup_pop(0);
/* Exit the thread returning the NULL value */
pthread_exit(NULL);
}
......@@ -298,16 +308,16 @@ int CancelSender(struct s_Sender* pssSender)
Log(LOG_NOTE, MOD_NAME, "Stopping sender thread");
iRc = pthread_cancel(pssSender->tid);
printf("Sender thread canceled\n");
printf("Sender thread canceled with iRc %d and error %s\n", iRc, strerror(errno));
/* Synchronise ourselves with the destruction of the thread, to avoid to destroy
the condition while the sender is waiting on it */
iRc |= pthread_join(pssSender->tid, NULL);
printf("Sender thread joined\n");
printf("Sender thread joined with iRc %d and error %s\n", iRc, strerror(errno));
/* When the thread is cancelled while waiting for a a socket, it relocks
the ConnectionLock, so that the sender thread cannot anymore work for
it shares the ConnectionLock with the listener */
pthread_mutex_trylock(&ConnectionLock);
pthread_mutex_unlock(&ConnectionLock);
// pthread_mutex_trylock(&ConnectionLock);
// pthread_mutex_unlock(&ConnectionLock);
}
else
Log(LOG_WARN, MOD_NAME, "Could not stop sender, none is running");
......@@ -328,8 +338,11 @@ int FreeSender(struct s_Sender* pssSender)
if (pssSender->tid != 0)
{
iRc = pthread_cond_destroy(&pssSender->WakeUpSignal);
printf("Sender thread cond destoyed with iRc %d and error %s\n", iRc, strerror(errno));
iRc |= FifoDestroy(pssSender->psfWaitingAnswers);
printf("Sender thread FIFO destoyed with iRc %d and error %s\n", iRc, strerror(errno));
if (!iRc)
Log(LOG_NOTE, MOD_NAME, "Sender thread destroyed");
else
......
......@@ -10,12 +10,11 @@
#include "signal.h"
#include "log.h"
#include "VLANbridge.h"
#include "vlanbridge.h"
#define MOD_NAME MOD_VLANBRIDGE
/* */
void SigHup(int iCrap)
{
......
......@@ -30,7 +30,7 @@
#include "sender.h"
#include "manager.h"
#include "connect.h"
#include "VLANbridge.h"
#include "vlanbridge.h"
/* Handle datas for the thread managing VLANserver requests */
......
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