mirror of
https://gitlab.com/apparmor/apparmor
synced 2025-08-30 22:05:27 +00:00
Moves the cache clearing logic into the create cache routine, because if
we are writing a new cache .features file the cache dir should be cleared out. Signed-off-by: John Johansen <john.johansen@canonical.com> Acked-by: Tyler Hicks <tyhicks@canonical.com>
This commit is contained in:
@@ -1159,20 +1159,39 @@ static int clear_cache_files(const char *path)
|
||||
return dirat_for_each(NULL, path, NULL, clear_cache_cb);
|
||||
}
|
||||
|
||||
static int create_cache(const char *path, const char *features)
|
||||
static int create_cache(const char *cachedir, const char *path,
|
||||
const char *features)
|
||||
{
|
||||
struct stat stat_file;
|
||||
FILE * f = NULL;
|
||||
|
||||
if (cond_clear_cache && clear_cache_files(cacheloc) != 0)
|
||||
goto error;
|
||||
|
||||
f = fopen(path, "w");
|
||||
if (f) {
|
||||
if (fwrite(features, strlen(features), 1, f) != 1 )
|
||||
goto fail;
|
||||
goto error;
|
||||
|
||||
fclose(f);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
error:
|
||||
/* does the dir exist? */
|
||||
if (stat(cachedir, &stat_file) == -1) {
|
||||
if (show_cache)
|
||||
PERROR(_("Can't create cache directory: %s\n"), cachedir);
|
||||
} else if (!S_ISDIR(stat_file.st_mode)) {
|
||||
if (show_cache)
|
||||
PERROR(_("File in cache directory location: %s\n"), cachedir);
|
||||
} else {
|
||||
if (show_cache)
|
||||
PERROR(_("Can't update cache directory: %s\n"), cachedir);
|
||||
}
|
||||
|
||||
return 0;
|
||||
fail:
|
||||
if (show_cache)
|
||||
PERROR("Cache write disabled: cannot create %s\n", path);
|
||||
write_cache = 0;
|
||||
@@ -1218,12 +1237,10 @@ static void setup_flags(void)
|
||||
get_flags_string(&cache_flags, cache_features_path);
|
||||
if (cache_flags) {
|
||||
if (strcmp(flags_string, cache_flags) != 0) {
|
||||
if (write_cache && cond_clear_cache) {
|
||||
if (clear_cache_files(cacheloc) ||
|
||||
create_cache(cache_features_path,
|
||||
flags_string)) {
|
||||
if (write_cache) {
|
||||
if (create_cache(cacheloc, cache_features_path,
|
||||
flags_string))
|
||||
skip_read_cache = 1;
|
||||
}
|
||||
} else {
|
||||
if (show_cache)
|
||||
PERROR("Cache read/write disabled: %s does not match %s\n", FLAGS_FILE, cache_features_path);
|
||||
@@ -1234,7 +1251,7 @@ static void setup_flags(void)
|
||||
free(cache_flags);
|
||||
cache_flags = NULL;
|
||||
} else if (write_cache) {
|
||||
create_cache(cache_features_path, flags_string);
|
||||
create_cache(cacheloc, cache_features_path, flags_string);
|
||||
}
|
||||
|
||||
free(cache_features_path);
|
||||
|
Reference in New Issue
Block a user