diff options
author | Timo Teräs <timo.teras@iki.fi> | 2021-06-21 13:01:55 +0300 |
---|---|---|
committer | Timo Teräs <timo.teras@iki.fi> | 2021-06-21 13:02:12 +0300 |
commit | 0683b069ba8b4da6ca456a28a4435daec6d52f69 (patch) | |
tree | e2a59ddcb017f5b9f4b5b2a90acc03d9f6329464 /src | |
parent | 22281fb4b583a5969a9c902c008e336e7cc421ff (diff) | |
download | apk-tools-0683b069ba8b4da6ca456a28a4435daec6d52f69.tar.gz apk-tools-0683b069ba8b4da6ca456a28a4435daec6d52f69.tar.bz2 apk-tools-0683b069ba8b4da6ca456a28a4435daec6d52f69.tar.xz apk-tools-0683b069ba8b4da6ca456a28a4435daec6d52f69.zip |
db: check syscall errors in update_permissions()
Diffstat (limited to 'src')
-rw-r--r-- | src/database.c | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/src/database.c b/src/database.c index a0e2fd9..db5015e 100644 --- a/src/database.c +++ b/src/database.c @@ -1945,9 +1945,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; @@ -1958,19 +1964,25 @@ 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; } void apk_db_update_directory_permissions(struct apk_database *db) { + struct apk_out *out = &db->ctx->out; struct apk_installed_package *ipkg; 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) { @@ -1985,7 +1997,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_err(out, "%d errors updating directory permissions", ctx.errors); } int apk_db_cache_active(struct apk_database *db) |