From 3490ff789a9375d3047c6580f24a55157ebef4f0 Mon Sep 17 00:00:00 2001 From: Timo Teräs Date: Mon, 13 Apr 2015 09:41:49 +0300 Subject: fix tee io error handling use ERR_PTR mechanism, and handle it at all places. --- src/database.c | 2 +- src/io.c | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/database.c b/src/database.c index b71c9df..364b4df 100644 --- a/src/database.c +++ b/src/database.c @@ -2586,7 +2586,7 @@ static int apk_db_unpack_pkg(struct apk_database *db, apk_blob_push_blob(&b, tmpprefix); apk_pkg_format_cache_pkg(b, pkg); cache_bs = apk_bstream_tee(bs, db->cache_fd, tmpcacheitem, NULL, NULL); - if (cache_bs != NULL) + if (!IS_ERR_OR_NULL(cache_bs)) bs = cache_bs; else apk_warning(PKG_VER_FMT": unable to cache: %s", diff --git a/src/io.c b/src/io.c index 765afc5..fa8a048 100644 --- a/src/io.c +++ b/src/io.c @@ -421,22 +421,24 @@ static void tee_close(void *stream, size_t *size) struct apk_bstream *apk_bstream_tee(struct apk_bstream *from, int atfd, const char *to, apk_progress_cb cb, void *cb_ctx) { struct apk_tee_bstream *tbs; - int fd; + int fd, r; if (IS_ERR_OR_NULL(from)) return ERR_CAST(from); fd = openat(atfd, to, O_CREAT | O_RDWR | O_TRUNC | O_CLOEXEC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); if (fd < 0) { + r = errno; from->close(from, NULL); - return NULL; + return ERR_PTR(-r); } tbs = malloc(sizeof(struct apk_tee_bstream)); if (!tbs) { + r = errno; close(fd); from->close(from, NULL); - return NULL; + return ERR_PTR(-r); } tbs->bs = (struct apk_bstream) { -- cgit v1.2.3-60-g2f50