In the case that fd is -1, preserve errno and don't attempt to set
CLOEXEC.
Note that the implementation can still fail, as it ignores fcntl()
errors and may not set CLOEXEC properly. Update the documentation
accordingly until it is fixed.
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
CC: Ian Campbell <Ian.Campbell@citrix.com>
CC: Ian Jackson <Ian.Jackson@eu.citrix.com>
CC: Wei Liu <wei.liu2@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
---
Fixing the fnctl() error issue involves more TUITs than I currently
have.
New in v4
libxl__carefd *libxl__carefd_opened(libxl_ctx *ctx, int fd)
{
libxl__carefd *cf = 0;
+ int saved_errno = errno;
- cf = libxl__carefd_record(ctx, fd);
+ if (fd >= 0)
+ cf = libxl__carefd_record(ctx, fd);
libxl__carefd_unlock();
+ errno = saved_errno;
return cf;
}
_hidden libxl__carefd *libxl__carefd_record(libxl_ctx *ctx, int fd);
/* Combines _record and _unlock in a single call. If fd==-1,
- * still does the unlock, but returns 0. Cannot fail. */
+ * still does the unlock, but returns 0. */
_hidden libxl__carefd *libxl__carefd_opened(libxl_ctx *ctx, int fd);
/* Works just like close(2). You may pass NULL, in which case it's