[apparmor] [PATCH v2 20/42] parser: Add features comparison function
John Johansen
john.johansen at canonical.com
Tue Mar 10 16:59:22 UTC 2015
On 03/06/2015 01:48 PM, Tyler Hicks wrote:
> This is a simple aa_features equality test. Placing it behind a function
> call allows us to do something more complex than a simple string
> comparison later.
>
> Signed-off-by: Tyler Hicks <tyhicks at canonical.com>
Acked-by: John Johansen <john.johansen at canonical.com>
> ---
> parser/features.c | 13 +++++++++++++
> parser/features.h | 1 +
> parser/policy_cache.c | 5 +----
> 3 files changed, 15 insertions(+), 4 deletions(-)
>
> diff --git a/parser/features.c b/parser/features.c
> index 2b81564..07d6e6c 100644
> --- a/parser/features.c
> +++ b/parser/features.c
> @@ -286,3 +286,16 @@ const char *aa_features_get_string(aa_features *features)
> {
> return features->string;
> }
> +
> +/**
> + * aa_features_is_equal - equality test for two features
> + * @features1: the first features (can be NULL)
> + * @features2: the second features (can be NULL)
> + *
> + * Returns: true if they're equal, false if they're not or either are NULL
> + */
> +bool aa_features_is_equal(aa_features *features1, aa_features *features2)
> +{
> + return features1 && features2 &&
> + strcmp(features1->string, features2->string) == 0;
> +}
> diff --git a/parser/features.h b/parser/features.h
> index 100f460..a0c177f 100644
> --- a/parser/features.h
> +++ b/parser/features.h
> @@ -28,5 +28,6 @@ int aa_features_new_from_kernel(aa_features **features);
> aa_features *aa_features_ref(aa_features *features);
> void aa_features_unref(aa_features *features);
> const char *aa_features_get_string(aa_features *features);
> +bool aa_features_is_equal(aa_features *features1, aa_features *features2);
>
> #endif /* __AA_FEATURES_H */
> diff --git a/parser/policy_cache.c b/parser/policy_cache.c
> index 8d34f34..27c83c1 100644
> --- a/parser/policy_cache.c
> +++ b/parser/policy_cache.c
> @@ -252,10 +252,7 @@ int setup_cache(aa_features *kernel_features, const char *cacheloc)
>
> kernel_features_string = aa_features_get_string(kernel_features);
> if (!aa_features_new(&cache_features, cache_features_path)) {
> - const char *cache_features_string;
> -
> - cache_features_string = aa_features_get_string(cache_features);
> - if (strcmp(kernel_features_string, cache_features_string) != 0) {
> + if (!aa_features_is_equal(kernel_features, cache_features)) {
> if (write_cache && cond_clear_cache) {
> if (create_cache(cacheloc, cache_features_path,
> kernel_features_string))
>
More information about the AppArmor
mailing list