bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

ENODATA required [Re: system.h cleanups


From: Jim Meyering
Subject: ENODATA required [Re: system.h cleanups
Date: Thu, 08 Oct 2009 20:11:24 +0200

Eric Blake wrote:
> OK to commit these cleanups?  Maybe we should push on Bruno to add ENODATA to
> gnulib's <errno.h> replacement, particularly since you are now considering
> using ENODATA for SELinux errors.  While the system.h version allows
> compilation, it would be better to have a dedicated errno rather than -1, as
> well as strerror support, if some other platform happens to encounter the
> SELinux path that sets ENODATA.

Good point.

Bruno, I have written wrappers for getfilecon, lgetfilecon,
and fgetfilecon each of which uses ENODATA to distinguish
a particular failure mode from ENOTSUP:

  http://thread.gmane.org/gmane.comp.gnu.coreutils.bugs/18378/focus=18420

FYI, here's part of the change,
from a new file named lib/getfilecon.c:

/* getfilecon, lgetfilecon, and fgetfilecon can all misbehave, be it
   via an old version of libselinux where these would return 0 and set the
   result context to NULL, or via a modern kernel+lib operating on a file
   from a disk whose attributes were set by a kernel from around 2006.
   In that latter case, the functions return a length of 10 for the
   "unlabeled" context.  Map both failures to a return value of -1, and
   set errno to ENOTSUP in the first case, and ENODATA in the latter.  */

static inline int
map_to_failure (int ret, security_context_t *con)
{
  if (ret == 0)
    {
      errno = ENOTSUP;
      return -1;
    }

  if (ret == 10 && strcmp (*con, "unlabeled") == 0)
    {
      freecon (*con);
      errno = ENODATA;
      return -1;
    }

  return ret;
}

int
rpl_getfilecon (char const *file, security_context_t *con)
{
  int ret = getfilecon (file, con);
  return map_to_failure (ret, con);
}

int
rpl_lgetfilecon (char const *file, security_context_t *con)
{
  int ret = lgetfilecon (file, con);
  return map_to_failure (ret, con);
}

int
rpl_fgetfilecon (int fd, security_context_t *con)
{
  int ret = fgetfilecon (fd, con);
  return map_to_failure (ret, con);
}
------------------------------------

It would not be a big loss to change that sole use of ENODATA to ENOTSUP,

  #ifndef ENODATA
  # define ENODATA ENOTSUP
  #endif

but if it's easy to add support for ENODATA in the errno module,
I'd prefer that, since the API for the getfilecon functions does
mention ENODATA, and returning ENOTSUP here would be misleading.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]