migrate last clone call(needed to properly handle incoming SMS messages) to pthread

This commit is contained in:
Sergey Popov 2012-04-06 13:25:22 +04:00
parent 5f63c76d0a
commit 51c8931cbd

View File

@ -7,7 +7,7 @@
#include "yasnd-log.h"
pthread_t ipc_main_handle;
pid_t ipc_sms_read_clone_pid=-1; // pid of thread, that checks for new incoming SMS
pthread_t ipc_sms_read_handle; // handle of thread, that checks for new incoming SMS
int qid=-1; // IPC queue id
int open_queue()
@ -107,12 +107,8 @@ void* ipc_queue_loop(void* param)
}
int ipc_sms_reading_loop()
void* ipc_sms_reading_loop(void* param)
{
// set default signal handlers
signal(SIGTERM,SIG_DFL);
signal(SIGHUP,SIG_DFL);
//
while(1)
{
sleep(30); /* wait 30 seconds */
@ -131,15 +127,16 @@ void ipc_init()
log_event("Main IPC event thread creation failed");
}
// start loop, that handles new incoming SMS
unsigned char sms_child_stack[16384];
ipc_sms_read_clone_pid=clone(ipc_sms_reading_loop,sms_child_stack+8192,CLONE_VM,NULL);
if(pthread_create(&ipc_sms_read_handle,NULL,ipc_sms_reading_loop, NULL) != 0)
{
log_event("Failed to create thread for incoming SMS parsing");
}
//
}
void ipc_free()
{
pthread_cancel(ipc_main_handle);
kill(ipc_sms_read_clone_pid,SIGTERM);
waitpid(ipc_sms_read_clone_pid,NULL,__WCLONE);
pthread_cancel(ipc_sms_read_handle);
remove_queue(qid);
}