Repository: celix Updated Branches: refs/heads/feature/CELIX-272_synchronization_service_registry 07d0dfe65 -> 0133d0406
CELIX-272: Change readdir to readdir_r (reentrant) Project: http://git-wip-us.apache.org/repos/asf/celix/repo Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/ca19830e Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/ca19830e Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/ca19830e Branch: refs/heads/feature/CELIX-272_synchronization_service_registry Commit: ca19830e4a7b11f4e7705eaeadf509486c8e69d3 Parents: 07d0dfe Author: Pepijn Noltes <[email protected]> Authored: Wed Nov 11 18:02:51 2015 +0100 Committer: Pepijn Noltes <[email protected]> Committed: Wed Nov 11 18:02:51 2015 +0100 ---------------------------------------------------------------------- framework/private/src/bundle_archive.c | 55 +++++++++++++++++----------- framework/private/src/bundle_cache.c | 57 +++++++++++++++++++---------- 2 files changed, 72 insertions(+), 40 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/celix/blob/ca19830e/framework/private/src/bundle_archive.c ---------------------------------------------------------------------- diff --git a/framework/private/src/bundle_archive.c b/framework/private/src/bundle_archive.c index c1a23aa..b126617 100644 --- a/framework/private/src/bundle_archive.c +++ b/framework/private/src/bundle_archive.c @@ -187,15 +187,22 @@ celix_status_t bundleArchive_recreate(char * archiveRoot, bundle_archive_pt *bun if (archive->archiveRootDir == NULL) { status = CELIX_FRAMEWORK_EXCEPTION; } else { - struct dirent *dent; + long idx = 0; char *location = NULL; - while ((dent = readdir(archive->archiveRootDir)) != NULL) { - if (dent->d_type == DT_DIR && (strncmp(dent->d_name, "version", 7) == 0)) { - sscanf(dent->d_name, "version%*d.%ld", &idx); - } - } + struct dirent dent; + struct dirent *result; + int rc; + + rc = readdir_r(archive->archiveRootDir, &dent, &result); + + while (rc == 0 && result != NULL) { + if (dent.d_type == DT_DIR && (strncmp(dent.d_name, "version", 7) == 0)) { + sscanf(dent.d_name, "version%*d.%ld", &idx); + } + rc = readdir_r(archive->archiveRootDir, &dent, &result); + } status = CELIX_DO_IF(status, bundleArchive_getRevisionLocation(archive, 0, &location)); status = CELIX_DO_IF(status, bundleArchive_reviseInternal(archive, true, idx, location, NULL)); @@ -708,21 +715,27 @@ static celix_status_t bundleArchive_deleteTree(bundle_archive_pt archive, char * if (dir == NULL) { status = CELIX_FILE_IO_EXCEPTION; } else { - struct dirent *dp; - while ((dp = readdir(dir)) != NULL) { - if ((strcmp((dp->d_name), ".") != 0) && (strcmp((dp->d_name), "..") != 0)) { - char subdir[512]; - snprintf(subdir, sizeof(subdir), "%s/%s", directory, dp->d_name); - - if (dp->d_type == DT_DIR) { - status = bundleArchive_deleteTree(archive, subdir); - } else { - if (remove(subdir) != 0) { - status = CELIX_FILE_IO_EXCEPTION; - break; - } - } - } + + struct dirent dp; + struct dirent *result = NULL; + int rc = 0; + + rc = readdir_r(dir, &dp, &result); + while (rc == 0 && result != NULL) { + if ((strcmp((dp.d_name), ".") != 0) && (strcmp((dp.d_name), "..") != 0)) { + char subdir[512]; + snprintf(subdir, sizeof(subdir), "%s/%s", directory, dp.d_name); + + if (dp.d_type == DT_DIR) { + status = bundleArchive_deleteTree(archive, subdir); + } else { + if (remove(subdir) != 0) { + status = CELIX_FILE_IO_EXCEPTION; + break; + } + } + } + rc = readdir_r(dir, &dp, &result); } if (closedir(dir) != 0) { http://git-wip-us.apache.org/repos/asf/celix/blob/ca19830e/framework/private/src/bundle_cache.c ---------------------------------------------------------------------- diff --git a/framework/private/src/bundle_cache.c b/framework/private/src/bundle_cache.c index 6eaf5d0..efe4f01 100644 --- a/framework/private/src/bundle_cache.c +++ b/framework/private/src/bundle_cache.c @@ -74,7 +74,8 @@ celix_status_t bundleCache_destroy(bundle_cache_pt *cache) { } celix_status_t bundleCache_delete(bundle_cache_pt cache) { - return bundleCache_deleteTree(cache, cache->cacheDir); + printf("DELETING CACHE DIR: %s\n", cache->cacheDir); + return bundleCache_deleteTree(cache, cache->cacheDir); } celix_status_t bundleCache_getArchives(bundle_cache_pt cache, array_list_pt *archives) { @@ -90,19 +91,23 @@ celix_status_t bundleCache_getArchives(bundle_cache_pt cache, array_list_pt *arc if (dir != NULL) { array_list_pt list = NULL; - struct dirent *dp; arrayList_create(&list); - - while ((dp = readdir(dir)) != NULL) { - char archiveRoot[512]; - snprintf(archiveRoot, sizeof(archiveRoot), "%s/%s", cache->cacheDir, dp->d_name); + struct dirent dp; + struct dirent *result = NULL; + int rc = 0; - if (dp->d_type == DT_DIR - && (strcmp((dp->d_name), ".") != 0) - && (strcmp((dp->d_name), "..") != 0) - && (strncmp(dp->d_name, "bundle", 6) == 0) - && (strcmp(dp->d_name, "bundle0") != 0)) { + rc = readdir_r(dir, &dp, &result); + while (rc == 0 && result != NULL) { + char archiveRoot[512]; + + snprintf(archiveRoot, sizeof(archiveRoot), "%s/%s", cache->cacheDir, dp.d_name); + + if (dp.d_type == DT_DIR + && (strcmp((dp.d_name), ".") != 0) + && (strcmp((dp.d_name), "..") != 0) + && (strncmp(dp.d_name, "bundle", 6) == 0) + && (strcmp(dp.d_name, "bundle0") != 0)) { bundle_archive_pt archive = NULL; status = bundleArchive_recreate(strdup(archiveRoot), &archive); @@ -110,13 +115,23 @@ celix_status_t bundleCache_getArchives(bundle_cache_pt cache, array_list_pt *arc arrayList_add(list, archive); } } + + readdir_r(dir, &dp, &result); + } + + if (rc != 0) { + fw_log(logger, OSGI_FRAMEWORK_LOG_ERROR, "Error reading dir"); + status = CELIX_FILE_IO_EXCEPTION; + } else { + status = CELIX_SUCCESS; } closedir(dir); - *archives = list; + if (status == CELIX_SUCCESS) { + *archives = list; + } - status = CELIX_SUCCESS; } else { status = CELIX_FILE_IO_EXCEPTION; } @@ -147,13 +162,16 @@ static celix_status_t bundleCache_deleteTree(bundle_cache_pt cache, char * direc if (dir == NULL) { status = CELIX_FILE_IO_EXCEPTION; } else { - struct dirent *dp; - while ((dp = readdir(dir)) != NULL) { - if ((strcmp((dp->d_name), ".") != 0) && (strcmp((dp->d_name), "..") != 0)) { + struct dirent dp; + struct dirent *result = NULL; + int rc = 0; + rc = readdir_r(dir, &dp, &result); + while (rc == 0 && result != NULL) { + if ((strcmp((dp.d_name), ".") != 0) && (strcmp((dp.d_name), "..") != 0)) { char subdir[512]; - snprintf(subdir, sizeof(subdir), "%s/%s", directory, dp->d_name); + snprintf(subdir, sizeof(subdir), "%s/%s", directory, dp.d_name); - if (dp->d_type == DT_DIR) { + if (dp.d_type == DT_DIR) { status = bundleCache_deleteTree(cache, subdir); } else { if (remove(subdir) != 0) { @@ -162,6 +180,7 @@ static celix_status_t bundleCache_deleteTree(bundle_cache_pt cache, char * direc } } } + readdir_r(dir, &dp, &result); } if (closedir(dir) != 0) { @@ -174,7 +193,7 @@ static celix_status_t bundleCache_deleteTree(bundle_cache_pt cache, char * direc } } - framework_logIfError(logger, status, NULL, "Failed to delete tree"); + framework_logIfError(logger, status, NULL, "Failed to delete tree at dir '%s'", directory); return status; }
