Commit 608de04f authored by Robert Ricci's avatar Robert Ricci

Fix a bug relating to multiple handles - the cleanup function should

only be called after we're done with _all_ handles. So, add a simple
count of how many handles we've given out, and only call cleanup on
the last one to get unregistered.
parent 17d1b0d2
...@@ -32,6 +32,12 @@ ...@@ -32,6 +32,12 @@
static char hostname[MAXHOSTNAMELEN]; static char hostname[MAXHOSTNAMELEN];
static char ipaddr[32]; static char ipaddr[32];
/*
* Count of how many handles are in use, so that we can avoid cleaning up until
* the last one is unregistered
*/
static int handles_in_use = 0;
/* /*
* Register with the testbed event system. NAME specifies the name of * Register with the testbed event system. NAME specifies the name of
* the event server. Returns a pointer to a handle that may be passed * the event server. Returns a pointer to a handle that may be passed
...@@ -158,6 +164,11 @@ event_register(char *name, int threaded) ...@@ -158,6 +164,11 @@ event_register(char *name, int threaded)
handle->server = server; handle->server = server;
handle->status = status; handle->status = status;
/*
* Keep track of how many handles we have outstanding
*/
handles_in_use++;
return handle; return handle;
} }
...@@ -184,6 +195,8 @@ event_unregister(event_handle_t handle) ...@@ -184,6 +195,8 @@ event_unregister(event_handle_t handle)
return 0; return 0;
} }
TRACE("disconnect completed\n");
/* Clean up: */ /* Clean up: */
if (elvin_handle_free(handle->server, handle->status) == 0) { if (elvin_handle_free(handle->server, handle->status) == 0) {
...@@ -191,12 +204,21 @@ event_unregister(event_handle_t handle) ...@@ -191,12 +204,21 @@ event_unregister(event_handle_t handle)
elvin_error_fprintf(stderr, handle->status); elvin_error_fprintf(stderr, handle->status);
return 0; return 0;
} }
if (handle->cleanup(1, handle->status) == 0) {
ERROR("could not clean up Elvin state: "); TRACE("free completed\n");
elvin_error_fprintf(stderr, handle->status);
return 0; if (handles_in_use == 1) {
if (handle->cleanup(1, handle->status) == 0) {
ERROR("could not clean up Elvin state: ");
elvin_error_fprintf(stderr, handle->status);
return 0;
}
TRACE("cleanup completed\n");
} }
handles_in_use--;
free(handle); free(handle);
return 1; return 1;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment