summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2021-06-21 13:01:55 +0300
committerTimo Teräs <timo.teras@iki.fi>2021-07-23 15:07:12 +0300
commit2a8eb8132acba74d81f81a9bb8082714af77ce6c (patch)
tree59856618c5f26a45357e726113d49efb30143d37
parent92ed56ea8c831a5cc67f219421b0ad8dbad34eee (diff)
downloadapk-tools-2a8eb8132acba74d81f81a9bb8082714af77ce6c.tar.gz
apk-tools-2a8eb8132acba74d81f81a9bb8082714af77ce6c.tar.bz2
apk-tools-2a8eb8132acba74d81f81a9bb8082714af77ce6c.tar.xz
apk-tools-2a8eb8132acba74d81f81a9bb8082714af77ce6c.zip
db: check syscall errors in update_permissions()
-rw-r--r--src/database.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/database.c b/src/database.c
index e930f10..80f393d 100644
--- a/src/database.c
+++ b/src/database.c
@@ -1980,9 +1980,15 @@ int apk_db_run_script(struct apk_database *db, char *fn, char **argv)
return 0;
}
-static int update_permissions(apk_hash_item item, void *ctx)
+struct update_permissions_ctx {
+ struct apk_database *db;
+ unsigned int errors;
+};
+
+static int update_permissions(apk_hash_item item, void *pctx)
{
- struct apk_database *db = (struct apk_database *) ctx;
+ struct update_permissions_ctx *ctx = pctx;
+ struct apk_database *db = ctx->db;
struct apk_db_dir *dir = (struct apk_db_dir *) item;
struct stat st;
int r;
@@ -1993,9 +1999,11 @@ static int update_permissions(apk_hash_item item, void *ctx)
r = fstatat(db->root_fd, dir->name, &st, AT_SYMLINK_NOFOLLOW);
if (r < 0 || (st.st_mode & 07777) != (dir->mode & 07777))
- fchmodat(db->root_fd, dir->name, dir->mode, 0);
+ if (fchmodat(db->root_fd, dir->name, dir->mode, 0) < 0)
+ ctx->errors++;
if (r < 0 || st.st_uid != dir->uid || st.st_gid != dir->gid)
- fchownat(db->root_fd, dir->name, dir->uid, dir->gid, 0);
+ if (fchownat(db->root_fd, dir->name, dir->uid, dir->gid, 0) < 0)
+ ctx->errors++;
return 0;
}
@@ -2006,6 +2014,9 @@ void apk_db_update_directory_permissions(struct apk_database *db)
struct apk_db_dir_instance *diri;
struct apk_db_dir *dir;
struct hlist_node *dc, *dn;
+ struct update_permissions_ctx ctx = {
+ .db = db,
+ };
list_for_each_entry(ipkg, &db->installed.packages, installed_pkgs_list) {
hlist_for_each_entry_safe(diri, dc, dn, &ipkg->owned_dirs, pkg_dirs_list) {
@@ -2020,7 +2031,8 @@ void apk_db_update_directory_permissions(struct apk_database *db)
apk_db_dir_apply_diri_permissions(diri);
}
}
- apk_hash_foreach(&db->installed.dirs, update_permissions, db);
+ apk_hash_foreach(&db->installed.dirs, update_permissions, &ctx);
+ if (ctx.errors) apk_error("%d errors updating directory permissions", ctx.errors);
}
int apk_db_cache_active(struct apk_database *db)