mirror of
https://gitlab.com/apparmor/apparmor
synced 2025-09-02 07:15:18 +00:00
Add an option to create the cache directory if it is missing
Signed-off-by: John Johansen john.johansen@canonical.com Acked-by: Tyler Hicks <tyhicks@canonical.com>
This commit is contained in:
@@ -74,6 +74,7 @@ int skip_read_cache = 0;
|
|||||||
int write_cache = 0;
|
int write_cache = 0;
|
||||||
int cond_clear_cache = 1; /* only applies if write is set */
|
int cond_clear_cache = 1; /* only applies if write is set */
|
||||||
int force_clear_cache = 0; /* force clearing regargless of state */
|
int force_clear_cache = 0; /* force clearing regargless of state */
|
||||||
|
int create_cache_dir = 0; /* create the cache dir if missing? */
|
||||||
int preprocess_only = 0;
|
int preprocess_only = 0;
|
||||||
int skip_mode_force = 0;
|
int skip_mode_force = 0;
|
||||||
struct timespec mru_tstamp;
|
struct timespec mru_tstamp;
|
||||||
@@ -114,6 +115,7 @@ struct option long_options[] = {
|
|||||||
{"show-cache", 0, 0, 'k'},
|
{"show-cache", 0, 0, 'k'},
|
||||||
{"skip-bad-cache", 0, 0, 129}, /* no short option */
|
{"skip-bad-cache", 0, 0, 129}, /* no short option */
|
||||||
{"purge-cache", 0, 0, 130}, /* no short option */
|
{"purge-cache", 0, 0, 130}, /* no short option */
|
||||||
|
{"create-cache-dir", 0, 0, 131}, /* no short option */
|
||||||
{"cache-loc", 1, 0, 'L'},
|
{"cache-loc", 1, 0, 'L'},
|
||||||
{"debug", 0, 0, 'd'},
|
{"debug", 0, 0, 'd'},
|
||||||
{"dump", 1, 0, 'D'},
|
{"dump", 1, 0, 'D'},
|
||||||
@@ -158,6 +160,7 @@ static void display_usage(char *command)
|
|||||||
"-W, --write-cache Save cached profile (force with -T)\n"
|
"-W, --write-cache Save cached profile (force with -T)\n"
|
||||||
" --skip-bad-cache Don't clear cache if out of sync\n"
|
" --skip-bad-cache Don't clear cache if out of sync\n"
|
||||||
" --purge-cache Clear cache regardless of its state\n"
|
" --purge-cache Clear cache regardless of its state\n"
|
||||||
|
" --create-cache-dire Create the cache dir if missing\n"
|
||||||
"-L, --cache-loc n Set the location of the profile cache\n"
|
"-L, --cache-loc n Set the location of the profile cache\n"
|
||||||
"-q, --quiet Don't emit warnings\n"
|
"-q, --quiet Don't emit warnings\n"
|
||||||
"-v, --verbose Show profile names as they load\n"
|
"-v, --verbose Show profile names as they load\n"
|
||||||
@@ -542,6 +545,9 @@ static int process_arg(int c, char *optarg)
|
|||||||
case 130:
|
case 130:
|
||||||
force_clear_cache = 1;
|
force_clear_cache = 1;
|
||||||
break;
|
break;
|
||||||
|
case 131:
|
||||||
|
create_cache_dir = 1;
|
||||||
|
break;
|
||||||
case 'L':
|
case 'L':
|
||||||
cacheloc = strdup(optarg);
|
cacheloc = strdup(optarg);
|
||||||
break;
|
break;
|
||||||
@@ -1168,6 +1174,7 @@ static int create_cache(const char *cachedir, const char *path,
|
|||||||
if (cond_clear_cache && clear_cache_files(cacheloc) != 0)
|
if (cond_clear_cache && clear_cache_files(cacheloc) != 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
|
create_file:
|
||||||
f = fopen(path, "w");
|
f = fopen(path, "w");
|
||||||
if (f) {
|
if (f) {
|
||||||
if (fwrite(features, strlen(features), 1, f) != 1 )
|
if (fwrite(features, strlen(features), 1, f) != 1 )
|
||||||
@@ -1181,7 +1188,9 @@ static int create_cache(const char *cachedir, const char *path,
|
|||||||
|
|
||||||
error:
|
error:
|
||||||
/* does the dir exist? */
|
/* does the dir exist? */
|
||||||
if (stat(cachedir, &stat_file) == -1) {
|
if (stat(cachedir, &stat_file) == -1 && create_cache_dir) {
|
||||||
|
if (mkdir(cachedir, 0700) == 0)
|
||||||
|
goto create_file;
|
||||||
if (show_cache)
|
if (show_cache)
|
||||||
PERROR(_("Can't create cache directory: %s\n"), cachedir);
|
PERROR(_("Can't create cache directory: %s\n"), cachedir);
|
||||||
} else if (!S_ISDIR(stat_file.st_mode)) {
|
} else if (!S_ISDIR(stat_file.st_mode)) {
|
||||||
|
Reference in New Issue
Block a user