Loading cmds/idmap/scan.cpp +17 −4 Original line number Original line Diff line number Diff line #include <dirent.h> #include <dirent.h> #include <inttypes.h> #include <inttypes.h> #include <sys/file.h> #include <sys/stat.h> #include <sys/stat.h> #include "idmap.h" #include "idmap.h" Loading Loading @@ -35,16 +36,31 @@ namespace { bool writePackagesList(const char *filename, const SortedVector<Overlay>& overlayVector) bool writePackagesList(const char *filename, const SortedVector<Overlay>& overlayVector) { { FILE* fout = fopen(filename, "w"); // the file is opened for appending so that it doesn't get truncated // before we can guarantee mutual exclusion via the flock FILE* fout = fopen(filename, "a"); if (fout == NULL) { if (fout == NULL) { return false; return false; } } if (TEMP_FAILURE_RETRY(flock(fileno(fout), LOCK_EX)) != 0) { fclose(fout); return false; } if (TEMP_FAILURE_RETRY(ftruncate(fileno(fout), 0)) != 0) { TEMP_FAILURE_RETRY(flock(fileno(fout), LOCK_UN)); fclose(fout); return false; } for (size_t i = 0; i < overlayVector.size(); ++i) { for (size_t i = 0; i < overlayVector.size(); ++i) { const Overlay& overlay = overlayVector[i]; const Overlay& overlay = overlayVector[i]; fprintf(fout, "%s %s\n", overlay.apk_path.string(), overlay.idmap_path.string()); fprintf(fout, "%s %s\n", overlay.apk_path.string(), overlay.idmap_path.string()); } } TEMP_FAILURE_RETRY(fflush(fout)); TEMP_FAILURE_RETRY(flock(fileno(fout), LOCK_UN)); fclose(fout); fclose(fout); // Make file world readable since Zygote (running as root) will read // Make file world readable since Zygote (running as root) will read Loading Loading @@ -171,9 +187,6 @@ int idmap_scan(const char *target_package_name, const char *target_apk_path, { { String8 filename = String8(idmap_dir); String8 filename = String8(idmap_dir); filename.appendPath("overlays.list"); filename.appendPath("overlays.list"); if (unlink(filename.string()) != 0 && errno != ENOENT) { return EXIT_FAILURE; } SortedVector<Overlay> overlayVector; SortedVector<Overlay> overlayVector; const size_t N = overlay_dirs->size(); const size_t N = overlay_dirs->size(); Loading libs/androidfw/AssetManager.cpp +13 −0 Original line number Original line Diff line number Diff line Loading @@ -35,6 +35,9 @@ #include <utils/threads.h> #include <utils/threads.h> #include <utils/Timers.h> #include <utils/Timers.h> #include <utils/Trace.h> #include <utils/Trace.h> #ifndef _WIN32 #include <sys/file.h> #endif #include <assert.h> #include <assert.h> #include <dirent.h> #include <dirent.h> Loading Loading @@ -767,6 +770,12 @@ void AssetManager::addSystemOverlays(const char* pathOverlaysList, return; return; } } #ifndef _WIN32 if (TEMP_FAILURE_RETRY(flock(fileno(fin), LOCK_SH)) != 0) { fclose(fin); return; } #endif char buf[1024]; char buf[1024]; while (fgets(buf, sizeof(buf), fin)) { while (fgets(buf, sizeof(buf), fin)) { // format of each line: // format of each line: Loading Loading @@ -797,6 +806,10 @@ void AssetManager::addSystemOverlays(const char* pathOverlaysList, const_cast<AssetManager*>(this)->mZipSet.addOverlay(targetPackagePath, oap); const_cast<AssetManager*>(this)->mZipSet.addOverlay(targetPackagePath, oap); } } } } #ifndef _WIN32 TEMP_FAILURE_RETRY(flock(fileno(fin), LOCK_UN)); #endif fclose(fin); fclose(fin); } } Loading Loading
cmds/idmap/scan.cpp +17 −4 Original line number Original line Diff line number Diff line #include <dirent.h> #include <dirent.h> #include <inttypes.h> #include <inttypes.h> #include <sys/file.h> #include <sys/stat.h> #include <sys/stat.h> #include "idmap.h" #include "idmap.h" Loading Loading @@ -35,16 +36,31 @@ namespace { bool writePackagesList(const char *filename, const SortedVector<Overlay>& overlayVector) bool writePackagesList(const char *filename, const SortedVector<Overlay>& overlayVector) { { FILE* fout = fopen(filename, "w"); // the file is opened for appending so that it doesn't get truncated // before we can guarantee mutual exclusion via the flock FILE* fout = fopen(filename, "a"); if (fout == NULL) { if (fout == NULL) { return false; return false; } } if (TEMP_FAILURE_RETRY(flock(fileno(fout), LOCK_EX)) != 0) { fclose(fout); return false; } if (TEMP_FAILURE_RETRY(ftruncate(fileno(fout), 0)) != 0) { TEMP_FAILURE_RETRY(flock(fileno(fout), LOCK_UN)); fclose(fout); return false; } for (size_t i = 0; i < overlayVector.size(); ++i) { for (size_t i = 0; i < overlayVector.size(); ++i) { const Overlay& overlay = overlayVector[i]; const Overlay& overlay = overlayVector[i]; fprintf(fout, "%s %s\n", overlay.apk_path.string(), overlay.idmap_path.string()); fprintf(fout, "%s %s\n", overlay.apk_path.string(), overlay.idmap_path.string()); } } TEMP_FAILURE_RETRY(fflush(fout)); TEMP_FAILURE_RETRY(flock(fileno(fout), LOCK_UN)); fclose(fout); fclose(fout); // Make file world readable since Zygote (running as root) will read // Make file world readable since Zygote (running as root) will read Loading Loading @@ -171,9 +187,6 @@ int idmap_scan(const char *target_package_name, const char *target_apk_path, { { String8 filename = String8(idmap_dir); String8 filename = String8(idmap_dir); filename.appendPath("overlays.list"); filename.appendPath("overlays.list"); if (unlink(filename.string()) != 0 && errno != ENOENT) { return EXIT_FAILURE; } SortedVector<Overlay> overlayVector; SortedVector<Overlay> overlayVector; const size_t N = overlay_dirs->size(); const size_t N = overlay_dirs->size(); Loading
libs/androidfw/AssetManager.cpp +13 −0 Original line number Original line Diff line number Diff line Loading @@ -35,6 +35,9 @@ #include <utils/threads.h> #include <utils/threads.h> #include <utils/Timers.h> #include <utils/Timers.h> #include <utils/Trace.h> #include <utils/Trace.h> #ifndef _WIN32 #include <sys/file.h> #endif #include <assert.h> #include <assert.h> #include <dirent.h> #include <dirent.h> Loading Loading @@ -767,6 +770,12 @@ void AssetManager::addSystemOverlays(const char* pathOverlaysList, return; return; } } #ifndef _WIN32 if (TEMP_FAILURE_RETRY(flock(fileno(fin), LOCK_SH)) != 0) { fclose(fin); return; } #endif char buf[1024]; char buf[1024]; while (fgets(buf, sizeof(buf), fin)) { while (fgets(buf, sizeof(buf), fin)) { // format of each line: // format of each line: Loading Loading @@ -797,6 +806,10 @@ void AssetManager::addSystemOverlays(const char* pathOverlaysList, const_cast<AssetManager*>(this)->mZipSet.addOverlay(targetPackagePath, oap); const_cast<AssetManager*>(this)->mZipSet.addOverlay(targetPackagePath, oap); } } } } #ifndef _WIN32 TEMP_FAILURE_RETRY(flock(fileno(fin), LOCK_UN)); #endif fclose(fin); fclose(fin); } } Loading