CELIX-280: 280 fixed deployment_admin shutdown
Project: http://git-wip-us.apache.org/repos/asf/celix/repo Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/6c938519 Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/6c938519 Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/6c938519 Branch: refs/heads/feature/CELIX-269_depman Commit: 6c9385199bf2bb026c4919b2def71d2eda4f0ff0 Parents: 9550e63 Author: Bjoern Petri <bpe...@apache.org> Authored: Sun Oct 25 16:00:57 2015 +0100 Committer: Bjoern Petri <bpe...@apache.org> Committed: Sun Oct 25 16:00:57 2015 +0100 ---------------------------------------------------------------------- deployment_admin/private/src/deployment_admin.c | 24 ++++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/celix/blob/6c938519/deployment_admin/private/src/deployment_admin.c ---------------------------------------------------------------------- diff --git a/deployment_admin/private/src/deployment_admin.c b/deployment_admin/private/src/deployment_admin.c index 7a78012..7e936e4 100644 --- a/deployment_admin/private/src/deployment_admin.c +++ b/deployment_admin/private/src/deployment_admin.c @@ -67,7 +67,7 @@ static void* deploymentAdmin_poll(void *deploymentAdmin); celix_status_t deploymentAdmin_download(deployment_admin_pt admin, char * url, char **inputFile); size_t deploymentAdmin_writeData(void *ptr, size_t size, size_t nmemb, FILE *stream); static celix_status_t deploymentAdmin_deleteTree(char * directory); -celix_status_t deploymentAdmin_readVersions(deployment_admin_pt admin, array_list_pt *versions); +celix_status_t deploymentAdmin_readVersions(deployment_admin_pt admin, array_list_pt versions); celix_status_t deploymentAdmin_stopDeploymentPackageBundles(deployment_admin_pt admin, deployment_package_pt target); celix_status_t deploymentAdmin_updateDeploymentPackageBundles(deployment_admin_pt admin, deployment_package_pt source); @@ -145,6 +145,10 @@ celix_status_t deploymentAdmin_create(bundle_context_pt context, deployment_admi celix_status_t deploymentAdmin_destroy(deployment_admin_pt admin) { celix_status_t status = CELIX_SUCCESS; + admin->running = false; + + celixThread_join(admin->poller, NULL); + hash_map_iterator_pt iter = hashMapIterator_create(admin->packages); while (hashMapIterator_hasNext(iter)) { @@ -214,7 +218,9 @@ static void *deploymentAdmin_poll(void *deploymentAdmin) { while (admin->running) { //poll ace array_list_pt versions = NULL; - deploymentAdmin_readVersions(admin, &versions); + arrayList_create(&versions); + + deploymentAdmin_readVersions(admin, versions); char *last = arrayList_get(versions, arrayList_size(versions) - 1); @@ -299,10 +305,12 @@ static void *deploymentAdmin_poll(void *deploymentAdmin) { } } } + sleep(5); + + arrayList_destroy(versions); } - celixThread_exit(NULL); return NULL; } @@ -329,9 +337,9 @@ size_t deploymentAdmin_parseVersions(void *contents, size_t size, size_t nmemb, return realsize; } -celix_status_t deploymentAdmin_readVersions(deployment_admin_pt admin, array_list_pt *versions) { +celix_status_t deploymentAdmin_readVersions(deployment_admin_pt admin, array_list_pt versions) { celix_status_t status = CELIX_SUCCESS; - arrayList_create(versions); + CURL *curl; CURLcode res; curl = curl_easy_init(); @@ -353,12 +361,14 @@ celix_status_t deploymentAdmin_readVersions(deployment_admin_pt admin, array_lis char *last; char *token = strtok_r(chunk.memory, "\n", &last); while (token != NULL) { - arrayList_add(*versions, strdup(token)); + arrayList_add(versions, strdup(token)); token = strtok_r(NULL, "\n", &last); } } - + if (chunk.memory) { + free(chunk.memory); + } return status; }