On 02/16/2012 07:39 PM, Jim Meyering wrote:

> diff --git a/src/ls.c b/src/ls.c

> +/* st_dev of the most recently processed device for which
> +   we've found that getfilecon or lgetfilecon fails with
> +   e.g., ENOTSUP or EOPNOTSUPP.  */
> +static dev_t selinux_challenged_device;
> +
> +/* Cache getfilecon failure, when it's trivial to do.
> +   Like getfilecon, but when F's st_dev says it's on a known-
> +   SELinux-challenged file system, fail with ENOTSUP immediately.  */
> +static int
> +getfilecon_cache (char const *file, struct fileinfo *f)
> +{
> +  if (f->stat.st_dev == selinux_challenged_device)
> +    {
> +      errno = ENOTSUP;
> +      return -1;
> +    }
> +  int r = getfilecon (file, &f->scontext);
> +  if (r < 0 && errno_unsupported (errno))
> +    selinux_challenged_device = f->stat.st_dev;
> +  return r;
> +}
> +
> +/* Cache lgetfilecon failure, when it's trivial to do.
> +   Like lgetfilecon, but when F's st_dev says it's on a known-
> +   SELinux-challenged file system, fail with ENOTSUP immediately.  */
> +static int
> +lgetfilecon_cache (char const *file, struct fileinfo *f)
> +{
> +  if (f->stat.st_dev == selinux_challenged_device)
> +    {
> +      errno = ENOTSUP;
> +      return -1;
> +    }
> +  int r = lgetfilecon (file, &f->scontext);
> +  if (r < 0 && errno_unsupported (errno))
> +    selinux_challenged_device = f->stat.st_dev;
> +  return r;
> +}

I'd be inclined to refactor the above 2 functions to one like:

static int
getfilecon_cache (char const *file, struct fileinfo *f, bool do_deref)
{
  /* st_dev of the most recently processed device for which we've
     found that [l]getfilecon fails indicating lack of support.  */
  static dev_t unsupported_device;

  if (f->stat.st_dev == unsupported_device)
    {
      errno = ENOTSUP;
      return -1;
    }
  int r = (do_deref ? getfilecon : lgetfilecon) (file, &f->scontext);
  if (r < 0 && errno_unsupported (errno))
    unsupported_device = f->stat.st_dev;
  return r;
}

>>From 796b05173ad9d34a3403e2201152a1a81fd973a1 Mon Sep 17 00:00:00 2001
> From: Jim Meyering <[email protected]>
> Date: Mon, 13 Feb 2012 12:05:40 +0100
> Subject: [PATCH 2/3] ls: also cache ACL- and CAP-querying syscall failures

patch series are not apparent in git shortlog summaries etc.,
so I'd s/also//

looks good!

cheers,
Pádraig.

Reply via email to