thread hang up fix

This commit is contained in:
Ugo Cirmignani
2018-12-11 23:00:03 +01:00
parent 29a5e60de7
commit c8f5c9f6f0
18 changed files with 37 additions and 16 deletions

View File

@ -4,9 +4,9 @@ CC=gcc
OUTPATH=./build/
SOURCE_MODULES_PATH=./library/
#FOR DEBUG PURPOSE
#CFLAGSTEMP=-c -Wall -I. -g -O0
CFLAGSTEMP=-c -Wall -I.
#FOR DEBUG PURPOSE
CFLAGSTEMP=-c -Wall -I. -g -O0
#CFLAGSTEMP=-c -Wall -I.
OPTIMIZATION=-O3
HEADERS=-I
LIBPATH=./build/modules/
@ -38,7 +38,7 @@ end:
@echo Build process end
uFTP: uFTP.c fileManagement.o configRead.o logFunctions.o ftpCommandElaborate.o ftpData.o ftpServer.o daemon.o signals.o connection.o openSsl.o
@$(CC) $(ENABLE_LARGE_FILE_SUPPORT) $(ENABLE_OPENSSL_SUPPORT) uFTP.c $(LIBPATH)dynamicVectors.o $(LIBPATH)fileManagement.o $(LIBPATH)configRead.o $(LIBPATH)logFunctions.o $(LIBPATH)ftpCommandElaborate.o $(LIBPATH)ftpData.o $(LIBPATH)ftpServer.o $(LIBPATH)daemon.o $(LIBPATH)signals.o $(LIBPATH)connection.o $(LIBPATH)openSsl.o -o $(OUTPATH)uFTP $(LIBS)
@$(CC) $(ENABLE_LARGE_FILE_SUPPORT) $(ENABLE_OPENSSL_SUPPORT) uFTP.c $(LIBPATH)dynamicVectors.o $(LIBPATH)fileManagement.o $(LIBPATH)configRead.o $(LIBPATH)logFunctions.o $(LIBPATH)ftpCommandElaborate.o $(LIBPATH)ftpData.o $(LIBPATH)ftpServer.o $(LIBPATH)daemon.o $(LIBPATH)signals.o $(LIBPATH)connection.o $(LIBPATH)openSsl.o -o $(OUTPATH)uFTP $(LIBS)
daemon.o:
@$(CC) $(CFLAGS) $(SOURCE_MODULES_PATH)daemon.c -o $(LIBPATH)daemon.o

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -459,14 +459,17 @@ int parseCommandPasv(ftpDataType * data, int socketId)
/* Create worker thread */
void *pReturn;
int returnCode;
//printf("\n data->clients[%d].workerData.workerThread = %d",socketId, (int)data->clients[socketId].workerData.workerThread);
printf("\n data->clients[%d].workerData.workerThread = %d",socketId, (int)data->clients[socketId].workerData.workerThread);
if (data->clients[socketId].workerData.threadIsAlive == 1)
{
returnCode = pthread_cancel(data->clients[socketId].workerData.workerThread);
}
//if (data->clients[socketId].workerData.threadIsAlive == 1)
// {
returnCode = pthread_cancel(data->clients[socketId].workerData.workerThread);
printf("\npasv pthread_cancel = %d", returnCode);
//}
printf("\npasv join ");
returnCode = pthread_join(data->clients[socketId].workerData.workerThread, &pReturn);
printf("\npasv join ok");
data->clients[socketId].workerData.passiveModeOn = 1;
data->clients[socketId].workerData.activeModeOn = 0;
returnCode = pthread_create(&data->clients[socketId].workerData.workerThread, NULL, connectionWorkerHandle, (void *) &data->clients[socketId].clientProgressiveNumber);

View File

@ -55,6 +55,8 @@ void workerCleanup(void *socketId)
int theSocketId = *(int *)socketId;
int returnCode = 0;
printf("\nWorker %d cleanup", theSocketId);
#ifdef OPENSSL_ENABLED
if (ftpData.clients[theSocketId].dataChannelIsTls == 1)
{
@ -62,7 +64,7 @@ void workerCleanup(void *socketId)
{
printf("\nSSL worker Shutdown 1");
returnCode = SSL_shutdown(ftpData.clients[theSocketId].workerData.serverSsl);
printf(" return code : %d", returnCode);
printf("\nnSSL worker Shutdown 1 return code : %d", returnCode);
if (returnCode < 0)
{
@ -70,7 +72,9 @@ void workerCleanup(void *socketId)
}
else if (returnCode == 0)
{
printf("\nSSL worker Shutdown 2");
returnCode = SSL_shutdown(ftpData.clients[theSocketId].workerData.serverSsl);
printf("\nnSSL worker Shutdown 2 return code : %d", returnCode);
if (returnCode <= 0)
{
@ -107,6 +111,7 @@ void workerCleanup(void *socketId)
close(ftpData.clients[theSocketId].workerData.socketConnection);
close(ftpData.clients[theSocketId].workerData.passiveListeningSocket);
resetWorkerData(&ftpData, theSocketId, 0);
printf("\nWorker cleaned!");
}
void *connectionWorkerHandle(void * socketId)
@ -248,7 +253,7 @@ void *connectionWorkerHandle(void * socketId)
if (ftpData.clients[theSocketId].workerData.socketIsConnected > 0)
{
printf("\nWorker is waiting for commands!");
printf("\nWorker %d is waiting for commands!", theSocketId);
//Conditional lock on thread actions
pthread_mutex_lock(&ftpData.clients[theSocketId].workerData.conditionMutex);
while (ftpData.clients[theSocketId].workerData.commandReceived == 0)
@ -257,6 +262,8 @@ void *connectionWorkerHandle(void * socketId)
}
pthread_mutex_unlock(&ftpData.clients[theSocketId].workerData.conditionMutex);
printf("\nWorker %d unlocked", theSocketId);
if (ftpData.clients[theSocketId].workerData.commandReceived == 1 &&
compareStringCaseInsensitive(ftpData.clients[theSocketId].workerData.theCommandReceived, "STOR", strlen("STOR")) == 1 &&
ftpData.clients[theSocketId].fileToStor.textLen > 0)

View File

@ -233,11 +233,11 @@ int socketWorkerPrintf(ftpDataType * ftpData, int clientId, const char *__restri
#ifdef OPENSSL_ENABLED
if (ftpData->clients[clientId].workerData.passiveModeOn == 1){
theReturnCode = SSL_write(ftpData->clients[clientId].workerData.serverSsl, theBuffer, theStringSize);
printf("passive: %s", theBuffer);
printf("%s", theBuffer);
}
else if (ftpData->clients[clientId].workerData.activeModeOn == 1){
theReturnCode = SSL_write(ftpData->clients[clientId].workerData.clientSsl, theBuffer, theStringSize);
printf("Active: %s", theBuffer);
printf("%s", theBuffer);
}
#endif
}

View File

@ -1,8 +1,19 @@
#NOTES ONLY FOR DEVELOPERS
#OPENSSL TEST COMMANDS
#Required packages to compile
sudo apt-get install libssl-dev
#Remove password from a certificate
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365
openssl rsa -in key.pem -out newkey.pem
#Testing ssl
openssl s_client -starttls ftp -connect 192.168.1.237:21
sudo openssl s_server -key key.pem -cert cert.pem -accept 123
openssl s_client -connect 127.0.0.1:49473
USER username
PASS password
PROT P

View File

@ -10,7 +10,7 @@ MAXIMUM_ALLOWED_FTP_CONNECTION = 30
FTP_PORT = 21
#TCP/IP PORT SETTINGS (DEFAULT 21)
SINGLE_INSTANCE = true
SINGLE_INSTANCE = false
#Allow only one server instance (true or false)
DAEMON_MODE = false