This function allows for a policy cache to be removed without having a previously instatiated aa_policy_cache object. It simply works off of a path.
Signed-off-by: Tyler Hicks <[email protected]> --- parser/parser_main.c | 2 +- parser/policy_cache.c | 18 ++++++++++++------ parser/policy_cache.h | 2 +- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/parser/parser_main.c b/parser/parser_main.c index 2de8edd..00b0bad 100644 --- a/parser/parser_main.c +++ b/parser/parser_main.c @@ -901,7 +901,7 @@ int main(int argc, char *argv[]) } if (force_clear_cache) { - if (clear_cache_files(cacheloc)) { + if (aa_policy_cache_remove(cacheloc)) { PERROR(_("Failed to clear cache files (%s): %s\n"), cacheloc, strerror(errno)); return 1; diff --git a/parser/policy_cache.c b/parser/policy_cache.c index f5061b1..d6abbdd 100644 --- a/parser/policy_cache.c +++ b/parser/policy_cache.c @@ -110,17 +110,12 @@ static int clear_cache_cb(DIR *dir, const char *path, struct stat *st, return 0; } -int clear_cache_files(const char *path) -{ - return dirat_for_each(NULL, path, NULL, clear_cache_cb); -} - static int create_cache(aa_policy_cache *policy_cache, aa_features *features) { struct stat stat_file; autofclose FILE * f = NULL; - if (clear_cache_files(policy_cache->path) != 0) + if (aa_policy_cache_remove(policy_cache->path)) goto error; create_file: @@ -363,3 +358,14 @@ int aa_policy_cache_create(aa_policy_cache *policy_cache) { return create_cache(policy_cache, policy_cache->kernel_features); } + +/** + * aa_policy_cache_remove - removes all policy cache files under a path + * @path: the path to a policy cache directory + * + * Returns: 0 on success, -1 on error with errno set + */ +int aa_policy_cache_remove(const char *path) +{ + return dirat_for_each(NULL, path, NULL, clear_cache_cb); +} diff --git a/parser/policy_cache.h b/parser/policy_cache.h index 7192939..4267d9a 100644 --- a/parser/policy_cache.h +++ b/parser/policy_cache.h @@ -41,7 +41,6 @@ extern int debug_cache; void set_mru_tstamp(struct timespec t); void update_mru_tstamp(FILE *file, const char *path); bool valid_cached_file_version(const char *cachename); -int clear_cache_files(const char *path); char *cache_filename(const char *cachedir, const char *basename); void valid_read_cache(const char *cachename); int cache_hit(const char *cachename); @@ -57,5 +56,6 @@ aa_policy_cache *aa_policy_cache_ref(aa_policy_cache *policy_cache); void aa_policy_cache_unref(aa_policy_cache *policy_cache); bool aa_policy_cache_is_valid(aa_policy_cache *policy_cache); int aa_policy_cache_create(aa_policy_cache *policy_cache); +int aa_policy_cache_remove(const char *path); #endif /* __AA_POLICY_CACHE_H */ -- 2.1.0 -- AppArmor mailing list [email protected] Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/apparmor
