|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [RFC OPW] libxl: Use LOG and LOGE macros in READ_WRITE_EXACTLY macro
The new coding style makes use of the LOG* family of convenience
macros. They rely on the availability of a libxl__gc gc*, but making
it available can make the code more complicated. In this case I
think it does so especially, and I'd like to ask if it's worth
changing in this case and in similar cases.
Suggested-by: Ian Campbell <Ian.Campbell@xxxxxxxxxx>
Signed-off-by: Kelley Nielsen <kelleynnn@xxxxxxxxx>
---
tools/libxl/libxl_utils.c | 30 +++++++++++++++++++++++-------
1 file changed, 23 insertions(+), 7 deletions(-)
diff --git a/tools/libxl/libxl_utils.c b/tools/libxl/libxl_utils.c
index 135778f..4238316 100644
--- a/tools/libxl/libxl_utils.c
+++ b/tools/libxl/libxl_utils.c
@@ -363,33 +363,49 @@ int libxl_read_file_contents(libxl_ctx *ctx, const char
*filename,
#define READ_WRITE_EXACTLY(rw, zero_is_eof, constdata) \
\
- int libxl_##rw##_exactly(libxl_ctx *ctx, int fd, \
+ int libxl_##rw##_exactly(libxl_ctx *ctx, int fd, \
constdata void *data, ssize_t sz, \
const char *source, const char *what) { \
+ GC_INIT(ctx); \
ssize_t got; \
+ int ret = 0; \
\
while (sz > 0) { \
got = rw(fd, data, sz); \
if (got == -1) { \
if (errno == EINTR) continue; \
- if (!ctx) return errno; \
- LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "failed to " #rw "
%s%s%s", \
+ if (!ctx) \
+ { \
+ ret = errno; \
+ goto out; \
+ } \
+ LOGE(ERROR, "failed to " #rw " %s%s%s", \
what?what:"", what?" from ":"", source); \
- return errno; \
+ ret = errno; \
+ goto out; \
} \
if (got == 0) { \
- if (!ctx) return EPROTO; \
- LIBXL__LOG(ctx, LIBXL__LOG_ERROR,
\
+ if (!ctx) \
+ { \
+ ret = EPROTO; \
+ goto out; \
+ } \
+ LOG(ERROR, \
zero_is_eof \
? "file/stream truncated reading %s%s%s" \
: "file/stream write returned 0! writing %s%s%s", \
what?what:"", what?" from ":"", source); \
- return EPROTO; \
+ ret = EPROTO; \
+ goto out; \
} \
sz -= got; \
data = (char*)data + got; \
} \
return 0; \
+ \
+ out: \
+ GC_FREE; \
+ return ret; \
}
READ_WRITE_EXACTLY(read, 1, /* */)
--
1.8.1.2
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |