diff --git a/daemon/yasnd-ipc.c b/daemon/yasnd-ipc.c index 3386240..ef5e11d 100644 --- a/daemon/yasnd-ipc.c +++ b/daemon/yasnd-ipc.c @@ -1,11 +1,12 @@ #include #include +#include #include "yasnd.h" #include "yasnd-gammu.h" #include "yasnd-log.h" -pid_t ipc_clone_pid; +pthread_t ipc_main_handle; pid_t ipc_sms_read_clone_pid=-1; // pid of thread, that checks for new incoming SMS int qid=-1; // IPC queue id @@ -55,12 +56,8 @@ int remove_queue( int qid ) return 0; } -int ipc_queue_loop() +void* ipc_queue_loop(void* param) { - // set default signal handlers - signal(SIGTERM,SIG_DFL); - signal(SIGHUP,SIG_DFL); - // mymsgbuf qbuf; while(1) { @@ -68,7 +65,7 @@ int ipc_queue_loop() if (result==-1) { log_event("Error: finishing IPC loop process..."); - return 1; + return (void*)1; } char dbg_txt[150]; sprintf(dbg_txt,"Read IPC message - Type: %ld Text: %s", qbuf.mtype, qbuf.mtext); @@ -129,8 +126,10 @@ int ipc_sms_reading_loop() void ipc_init() { qid = open_queue(); - unsigned char ipc_child_stack[16384]; - ipc_clone_pid=clone(ipc_queue_loop,ipc_child_stack+8192,CLONE_VM,NULL); + if(pthread_create(&ipc_main_handle,NULL,ipc_queue_loop, NULL) != 0) + { + 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); @@ -139,8 +138,7 @@ void ipc_init() void ipc_free() { - kill(ipc_clone_pid,SIGTERM); - waitpid(ipc_clone_pid,NULL,__WCLONE); + pthread_cancel(ipc_main_handle); kill(ipc_sms_read_clone_pid,SIGTERM); waitpid(ipc_sms_read_clone_pid,NULL,__WCLONE); remove_queue(qid);