From 85f8da54a511d2ff8a1c17e6aa5a74d8c6a0a8fa Mon Sep 17 00:00:00 2001 From: Sergey Popov Date: Wed, 14 Dec 2011 18:13:42 +0400 Subject: [PATCH] move freeing IPC resources in separate function --- yasnd-ipc.c | 7 +++++++ yasnd.c | 8 +------- yasnd.h | 4 +++- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/yasnd-ipc.c b/yasnd-ipc.c index c337b63..9571359 100644 --- a/yasnd-ipc.c +++ b/yasnd-ipc.c @@ -78,3 +78,10 @@ void ipc_init() unsigned char ipc_child_stack[16384]; ipc_clone_pid=clone(ipc_queue_loop,ipc_child_stack+8192,CLONE_VM,NULL); } + +void ipc_free() +{ + kill(ipc_clone_pid,SIGTERM); + waitpid(ipc_clone_pid,NULL,__WCLONE); + remove_queue(qid); +} diff --git a/yasnd.c b/yasnd.c index 38a0009..8c968f8 100644 --- a/yasnd.c +++ b/yasnd.c @@ -1,7 +1,5 @@ -#include #include #include -#include #include #include #include @@ -209,9 +207,7 @@ void signal_handler(int signum) void free_resources() { // Stop IPC loop and remove IPC queue - kill(ipc_clone_pid,SIGTERM); - waitpid(ipc_clone_pid,NULL,__WCLONE); - remove_queue(qid); + ipc_free(); // free config structure cfg_free(cfg); // free gammu structure @@ -247,8 +243,6 @@ void signal_handler(int signum) closelog(); // free resources free_resources(); - // remove IPC message queue - remove_queue(qid); // exit(EXIT_SUCCESS); } diff --git a/yasnd.h b/yasnd.h index 9c0d6cc..0010412 100644 --- a/yasnd.h +++ b/yasnd.h @@ -5,6 +5,8 @@ #define DEBUG_BASE 1 #define DEBUG_ALL 2 +#include +#include #include #include #include @@ -34,7 +36,7 @@ extern bool check_gammu_error(GSM_Error err); extern bool gammu_init(); extern bool gammu_send_sms(const char* message); extern void ipc_init(); -extern int remove_queue(int qid); +extern void ipc_free(); extern int send_message(int qid, mymsgbuf* qbuf); // External variables