From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-2.7 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, UNWANTED_LANGUAGE_BODY shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id AA0F01FAF0 for ; Mon, 12 Dec 2022 11:40:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1670845256; bh=d6SaKz9Y0sIPjMGTE0m11ijyH42LhxF7qaOaPHvFJ0s=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Okd0oGhzRcg5ScXzc0SPgNlsO9fQSt8ALV7D/wgI3Yr49QXPd0lWyFtfdgIjoqeO9 ZDRAQ2MUmqWrqS7IqS8nwub9VdFfNFd7ns9BJRVI6STVgmafChdezQz03ypxihY/tU eOvRp6FzmJrqAFir6jfwvS8BRiCgIJcDuf+XFkZ4= From: Eric Wong To: mwrap-perl@80x24.org Subject: [PATCH 2/5] httpd: consolidate open_memstream error checking Date: Mon, 12 Dec 2022 11:40:53 +0000 Message-Id: <20221212114056.9615-3-e@80x24.org> In-Reply-To: <20221212114056.9615-1-e@80x24.org> References: <20221212114056.9615-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: This adds error reporting to a few places where I forgot to print errno on open_memstream failures. --- mwrap_httpd.h | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/mwrap_httpd.h b/mwrap_httpd.h index b55bb02..b0adf6a 100644 --- a/mwrap_httpd.h +++ b/mwrap_httpd.h @@ -201,14 +201,19 @@ static enum mw_qev h1_send_flush(struct mw_h1 *h1) return h1->persist ? MW_QEV_RD : h1_close(h1); } +static FILE *memstream_new(struct mw_membuf *mb) +{ + FILE *fp = open_memstream(&mb->ptr, &mb->len); + if (!fp) fprintf(stderr, "open_memstream: %m\n"); + return fp; +} + static FILE *wbuf_new(struct mw_membuf *mb) { static const struct mw_wbuf pad; - FILE *fp = open_memstream(&mb->ptr, &mb->len); + FILE *fp = memstream_new(mb); if (fp) /* pad space is populated before h1_send_flush */ fwrite(&pad, 1, sizeof(pad), fp); - else - fprintf(stderr, "open_memstream: %m\n"); return fp; } @@ -432,11 +437,8 @@ static off_t write_loc_name(FILE *fp, const struct src_loc *l) static struct h1_src_loc *accumulate(unsigned long min, size_t *hslc, FILE *lp) { struct mw_membuf mb; - FILE *fp = open_memstream(&mb.ptr, &mb.len); - if (!fp) { - fprintf(stderr, "open_memstream: %m\n"); - return NULL; - } + FILE *fp = memstream_new(&mb); + if (!fp) return NULL; rcu_read_lock(); struct cds_lfht *t = CMM_LOAD_SHARED(totals); struct cds_lfht_iter iter; @@ -488,7 +490,7 @@ static enum mw_qev each_at(struct mw_h1 *h1, struct mw_h1req *h1r) if (!l) return h1_404(h1); struct mw_membuf lname; - FILE *lp = open_memstream(&lname.ptr, &lname.len); + FILE *lp = memstream_new(&lname); if (!lp) return h1_close(h1); if (write_loc_name(lp, l) < 0) return h1_close(h1); if (err_close(lp)) @@ -540,7 +542,8 @@ static enum mw_qev each_gt(struct mw_h1 *h1, struct mw_h1req *h1r, size_t hslc; struct mw_membuf ln; - FILE *lp = open_memstream(&ln.ptr, &ln.len); + FILE *lp = memstream_new(&ln); + if (!lp) return h1_close(h1); struct h1_src_loc *hslv = accumulate(min, &hslc, lp); if (!hslv) return h1_close(h1); @@ -845,11 +848,8 @@ static int poll_add(struct mw_h1d *h1d, int fd, short events) struct pollfd pfd; if (!h1d->pfp) { - h1d->pfp = open_memstream(&h1d->pbuf.ptr, &h1d->pbuf.len); - if (!h1d->pfp) { - fprintf(stderr, "open_memstream: %m\n"); - return -1; - } + h1d->pfp = memstream_new(&h1d->pbuf); + if (!h1d->pfp) return -1; } pfd.fd = fd; pfd.events = events;