summaryrefslogtreecommitdiff
path: root/src/database.c
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2011-05-27 16:49:25 +0300
committerTimo Teräs <timo.teras@iki.fi>2011-05-27 16:49:25 +0300
commit95555ede4d732878d576415e5d338b0104b78ad6 (patch)
tree46c3d178e32f75480f834be897ce2b03f1a3bbd2 /src/database.c
parent38e54240a38266c0c1864e51e4ca7468a429646e (diff)
downloadapk-tools-95555ede4d732878d576415e5d338b0104b78ad6.tar.gz
apk-tools-95555ede4d732878d576415e5d338b0104b78ad6.tar.bz2
apk-tools-95555ede4d732878d576415e5d338b0104b78ad6.tar.xz
apk-tools-95555ede4d732878d576415e5d338b0104b78ad6.zip
db: more fix for read-only cache remounting
remount to read-write before trying to create the cache directory subdirs. fix a fd leak that might prevent remounting back to rw.
Diffstat (limited to 'src/database.c')
-rw-r--r--src/database.c31
1 files changed, 14 insertions, 17 deletions
diff --git a/src/database.c b/src/database.c
index 0fc59df..9617b4e 100644
--- a/src/database.c
+++ b/src/database.c
@@ -1218,10 +1218,22 @@ int apk_db_open(struct apk_database *db, struct apk_db_options *dbopts)
db->cache_dir = apk_linked_cache_dir;
db->cache_fd = fd;
+ if ((dbopts->open_flags & (APK_OPENF_WRITE | APK_OPENF_CACHE_WRITE)) &&
+ fstatvfs(fd, &stvfs) == 0 && (stvfs.f_flag & ST_RDONLY) != 0) {
+ /* remount cache read-write */
+ db->cache_remount_dir = find_mountpoint(db->root_fd, db->cache_dir);
+ if (db->cache_remount_dir == NULL) {
+ apk_warning("Unable to find cache directory mount point");
+ } else if (do_remount(db->cache_remount_dir, "rw") != 0) {
+ free(db->cache_remount_dir);
+ db->cache_remount_dir = NULL;
+ apk_error("Unable to remount cache read-write");
+ r = EROFS;
+ goto ret_r;
+ }
+ }
mkdirat(db->cache_fd, "tmp", 0644);
db->cachetmp_fd = openat(db->cache_fd, "tmp", O_RDONLY | O_CLOEXEC);
- if (fstatvfs(fd, &stvfs) == 0 && (stvfs.f_flag & ST_RDONLY) != 0)
- db->ro_cache = 1;
} else {
if (fd >= 0)
close(fd);
@@ -1264,21 +1276,6 @@ int apk_db_open(struct apk_database *db, struct apk_db_options *dbopts)
}
}
- if ((dbopts->open_flags & (APK_OPENF_WRITE | APK_OPENF_CACHE_WRITE)) &&
- db->ro_cache) {
- /* remount cache read-write */
- db->cache_remount_dir = find_mountpoint(db->root_fd, db->cache_dir);
- if (db->cache_remount_dir == NULL) {
- apk_warning("Unable to find cache directory mount point");
- } else if (do_remount(db->cache_remount_dir, "rw") != 0) {
- free(db->cache_remount_dir);
- db->cache_remount_dir = NULL;
- apk_error("Unable to remount cache read-write");
- r = EROFS;
- goto ret_r;
- }
- }
-
if (!(dbopts->open_flags & APK_OPENF_NO_SYS_REPOS)) {
list_for_each_entry(repo, &dbopts->repository_list, list) {
r = apk_db_add_repository(db, APK_BLOB_STR(repo->url));