move freeing IPC resources in separate function

This commit is contained in:
Sergey Popov 2011-12-14 18:13:42 +04:00
parent 16d950f98d
commit 85f8da54a5
3 changed files with 11 additions and 8 deletions

View File

@ -78,3 +78,10 @@ void ipc_init()
unsigned char ipc_child_stack[16384]; unsigned char ipc_child_stack[16384];
ipc_clone_pid=clone(ipc_queue_loop,ipc_child_stack+8192,CLONE_VM,NULL); 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);
}

View File

@ -1,7 +1,5 @@
#include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/io.h> #include <sys/io.h>
#include <sys/wait.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <fcntl.h> #include <fcntl.h>
@ -209,9 +207,7 @@ void signal_handler(int signum)
void free_resources() void free_resources()
{ {
// Stop IPC loop and remove IPC queue // Stop IPC loop and remove IPC queue
kill(ipc_clone_pid,SIGTERM); ipc_free();
waitpid(ipc_clone_pid,NULL,__WCLONE);
remove_queue(qid);
// free config structure // free config structure
cfg_free(cfg); cfg_free(cfg);
// free gammu structure // free gammu structure
@ -247,8 +243,6 @@ void signal_handler(int signum)
closelog(); closelog();
// free resources // free resources
free_resources(); free_resources();
// remove IPC message queue
remove_queue(qid);
// //
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }

View File

@ -5,6 +5,8 @@
#define DEBUG_BASE 1 #define DEBUG_BASE 1
#define DEBUG_ALL 2 #define DEBUG_ALL 2
#include <sys/types.h>
#include <sys/wait.h>
#include <signal.h> #include <signal.h>
#include <stdbool.h> #include <stdbool.h>
#include <string.h> #include <string.h>
@ -34,7 +36,7 @@ extern bool check_gammu_error(GSM_Error err);
extern bool gammu_init(); extern bool gammu_init();
extern bool gammu_send_sms(const char* message); extern bool gammu_send_sms(const char* message);
extern void ipc_init(); extern void ipc_init();
extern int remove_queue(int qid); extern void ipc_free();
extern int send_message(int qid, mymsgbuf* qbuf); extern int send_message(int qid, mymsgbuf* qbuf);
// External variables // External variables