|
From: <cli...@li...> - 2007-06-25 19:11:28
|
Revision: 70
http://cligg.svn.sourceforge.net/cligg/?rev=70&view=rev
Author: sithhell
Date: 2007-06-25 12:11:25 -0700 (Mon, 25 Jun 2007)
Log Message:
-----------
some bug fixes, more will follow
Modified Paths:
--------------
src/bin/cligg.c
src/bin/cligg_eventhandler.c
src/bin/cligg_ipc.c
src/bin/cligg_modulehandler.c
src/lib/cligg_btree.c
src/lib/cligg_hashmap.c
Modified: src/bin/cligg.c
===================================================================
--- src/bin/cligg.c 2007-06-22 08:09:00 UTC (rev 69)
+++ src/bin/cligg.c 2007-06-25 19:11:25 UTC (rev 70)
@@ -90,8 +90,8 @@
static int quit_cligg(void *data)
{
/* Clean up */
+ cligg_del_modulehandler();
cligg_delete_handler();
- cligg_del_modulehandler();
cligg_ipc_stop();
fprintf(stderr, "Good Bye!\n");
Modified: src/bin/cligg_eventhandler.c
===================================================================
--- src/bin/cligg_eventhandler.c 2007-06-22 08:09:00 UTC (rev 69)
+++ src/bin/cligg_eventhandler.c 2007-06-25 19:11:25 UTC (rev 70)
@@ -26,6 +26,9 @@
char *str = ((char *)((cligg_event_function *)data)->name);
unsigned long hash = 0;
int c;
+
+ if(str == NULL) return 0;
+
while((c = *str++))
hash = c + (hash << 6) + (hash << 16) - hash;
Modified: src/bin/cligg_ipc.c
===================================================================
--- src/bin/cligg_ipc.c 2007-06-22 08:09:00 UTC (rev 69)
+++ src/bin/cligg_ipc.c 2007-06-25 19:11:25 UTC (rev 70)
@@ -60,9 +60,18 @@
int cligg_ipc_stop(void)
{
+ void *ret_val = NULL;
+
unlink(SOCKET_NAME);
close(fd);
- return TRUE;
+ /* FIXME: implement clean thread exit way */
+ /*pthread_cancel(ipc_loop);
+ pthread_detach(ipc_loop);
+ pthread_join(ipc_loop, &ret_val);*/
+ if(ret_val == NULL)
+ return EXIT_SUCCESS;
+
+ return EXIT_FAILURE;
}
static void *cligg_ipc(void *data)
@@ -75,9 +84,9 @@
char **test;
int send = FALSE;
int size;
+ int i = 0;
while(1) {
- int i = 0;
len = sizeof(un);
if((clifd = accept(fd, (struct sockaddr *)&un, &len)) < 0) {
perror("accept");
@@ -94,12 +103,17 @@
if(strcmp(message[0], "list_modules") == 0) {
test = cligg_list_modules(&size);
write(clifd, &size, sizeof(int));
+ i = 0;
+ printf("%s %x\n", test[size], test[size]);
while(test[i] != NULL) {
size = strlen(test[i]);
test[i][size] = 0;
- size = write(clifd, test[i], PATH_MAX);
+ printf("%s %x %x\n", test[i], test[i], test);
+ size = write(clifd, test[0], PATH_MAX);
+ free(test[i]);
i++;
}
+ free(test);
send = TRUE;
}
else
Modified: src/bin/cligg_modulehandler.c
===================================================================
--- src/bin/cligg_modulehandler.c 2007-06-22 08:09:00 UTC (rev 69)
+++ src/bin/cligg_modulehandler.c 2007-06-25 19:11:25 UTC (rev 70)
@@ -53,6 +53,7 @@
{
int ret = TRUE;
cligg_module *new = cligg_module_new(path);
+ void *handle;
printf("\n\nloading module ...\n");
@@ -85,7 +86,8 @@
return FALSE;
}*/
- new->handle = dlopen(path, RTLD_LAZY);
+ handle = dlopen(path, RTLD_LAZY);
+ new->handle = handle;
if(!new->handle) {
fprintf(stderr, "Error loading module: %s\n", dlerror());
cligg_module_del(new);
@@ -160,35 +162,50 @@
char **cligg_list_modules(int *size)
{
- char **list;
+ char **list = NULL;
char *path;
int i = 0;
int len;
- int total = 0;
cligg_list_element *tmp;
if(size == NULL) return NULL;
- list = (char **)malloc(module_list->size * sizeof(char *) + 1);
+ if(pthread_mutex_lock(&module_lock) != 0) {
+ fprintf(stderr, "Couldn't obtain module lock!\n");
+ cligg_module_del(tmp);
+ dlerror();
+ return FALSE;
+ }
+
+ list = (char **)malloc((module_list->size+1) * sizeof(char *));
if(list == NULL) return 0;
tmp = module_list->first;
while(tmp != NULL) {
path = ((cligg_module *)tmp->data)->path;
len = strlen(path);
- total += len;
- list[i] = (char *)malloc(len * sizeof(char));
- if(list[i] == NULL) return 0;
+ list[i] = (char *)malloc((len+1) * sizeof(char));
+ if(list[i] == NULL) {
+ list = NULL;
+ break;
+ }
strcpy(list[i], path);
i++;
tmp = tmp->next;
}
- list[i] = NULL;
+ if(list != NULL) list[i] = NULL;
*size = module_list->size;
+ if(pthread_mutex_unlock(&module_lock) != 0) {
+ fprintf(stderr, "Couldn't unlock module lock!\n");
+ cligg_module_del(tmp);
+ dlerror();
+ return FALSE;
+ }
+
return list;
}
Modified: src/lib/cligg_btree.c
===================================================================
--- src/lib/cligg_btree.c 2007-06-22 08:09:00 UTC (rev 69)
+++ src/lib/cligg_btree.c 2007-06-25 19:11:25 UTC (rev 70)
@@ -45,6 +45,9 @@
del(tree->root, tree->free_func);
+ tree->root = NULL;
+ tree->current = NULL;
+
tree->size = 0;
}
Modified: src/lib/cligg_hashmap.c
===================================================================
--- src/lib/cligg_hashmap.c 2007-06-22 08:09:00 UTC (rev 69)
+++ src/lib/cligg_hashmap.c 2007-06-25 19:11:25 UTC (rev 70)
@@ -9,6 +9,7 @@
int a = ((cligg_hashmap_element *)_a)->hash;
int b = ((cligg_hashmap_element *)_b)->hash;
int test = a-b;
+
if(test < 0)
return -1;
if(test > 0)
@@ -48,12 +49,14 @@
cligg_hashmap_clear(cligg_hashmap *map)
{
cligg_btree_clear(map->map);
+ map->map = NULL;
}
CLIGG void
cligg_hashmap_del(cligg_hashmap *map)
{
cligg_btree_del(map->map);
+ map->map = NULL;
free(map);
map = NULL;
}
@@ -63,10 +66,14 @@
void *data)
{
cligg_hashmap_element *new = cligg_hashmap_element_new(data, map->free_func, map->hash_func);
+ int ret;
if(!new)
return FALSE;
- return cligg_btree_add_element(map->map, new);
+
+ ret = cligg_btree_add_element(map->map, new);
+ /*cligg_hashmap_element_delete(new);*/
+ return ret;
}
CLIGG int
@@ -74,10 +81,16 @@
void *data)
{
cligg_hashmap_element *del = cligg_hashmap_element_new(data, map->free_func, map->hash_func);
+ int ret;
+
+ printf("%d\n", sizeof(cligg_hashmap_element));
if(!del)
return FALSE;
- return cligg_btree_del_element(map->map, del);
+ ret = cligg_btree_del_element(map->map, del);
+ /*cligg_hashmap_element_delete(del);*/
+ free(del);
+ return ret;
}
CLIGG void
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|