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: AS6130 216.105.38.0/24 X-Spam-Status: No, score=-3.9 required=3.0 tests=AWL,BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id CFFE01F4D7 for ; Fri, 10 Jun 2022 19:25:12 +0000 (UTC) Authentication-Results: dcvr.yhbt.net; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=sourceforge.net header.i=@sourceforge.net header.b="fyke9QgO"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=sf.net header.i=@sf.net header.b="C8h+fF06"; dkim-atps=neutral Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.94.2) (envelope-from ) id 1nzkFi-0006QD-LR; Fri, 10 Jun 2022 19:25:03 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nzkFf-0006Pb-IR for sox-devel@lists.sourceforge.net; Fri, 10 Jun 2022 19:25:00 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:Content-Type:MIME-Version :Message-ID:In-Reply-To:Date:References:Subject:Cc:To:From:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=LAj77Pm7ehyLxlUCVWypQ6rj/fKG1Dw21ygO4hDhEqU=; b=fyke9QgOMeuIrIrm6n8okz7vtR t+3CUJu/Js73bq5cHfo+ItoUrdtbvfqzIzPW0MNRPxPdFfyq0PljHXuI3yubazp2F2aiBABTp9ZqY DUDj6LMLeas8asKtrvVbuiffqOhLx4ZPTQPNb5vHnPpcL/bDyTn7e9mNCOHhqFgs7+mI=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:Content-Type:MIME-Version:Message-ID: In-Reply-To:Date:References:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=LAj77Pm7ehyLxlUCVWypQ6rj/fKG1Dw21ygO4hDhEqU=; b=C8h+fF0680ysauBf962Pp3oK1y KpCB3h4tUyUSzqo6W3uGvdipIiBPBYlZCoh0tRg7b7IbdE7iJXIjjEKW7v6HwO6Dhv7NysKALdKgw ITZj3qQxWwA5pdlTGx8EtM/mNystvha0M8wh1Zg9+n/BN7pub8TcalcQy4mScwdj/y+M=; Received: from unicorn.mansr.com ([81.2.72.234]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.94.2) id 1nzkFb-0004EI-2t for sox-devel@lists.sourceforge.net; Fri, 10 Jun 2022 19:24:59 +0000 Received: from raven.mansr.com (raven.mansr.com [81.2.72.235]) by unicorn.mansr.com (Postfix) with ESMTPS id 777A415360; Fri, 10 Jun 2022 20:05:44 +0100 (BST) Received: by raven.mansr.com (Postfix, from userid 51770) id 5167421A3D6; Fri, 10 Jun 2022 20:05:44 +0100 (BST) From: =?iso-8859-1?Q?M=E5ns_Rullg=E5rd?= To: Eric Wong References: <20220605210727.GA9582@dcvr> Date: Fri, 10 Jun 2022 20:05:44 +0100 In-Reply-To: <20220605210727.GA9582@dcvr> (Eric Wong's message of "Sun, 5 Jun 2022 21:07:27 +0000") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Headers-End: 1nzkFb-0004EI-2t Subject: Re: [WIP/PATCH] restart writes on EINTR X-BeenThere: sox-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: sox-devel@lists.sourceforge.net Cc: sox-devel@lists.sourceforge.net Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Errors-To: sox-devel-bounces@lists.sourceforge.net Eric Wong writes: > Only compile-tested, and I gotta run out for a bit and my not > return alive. I just noticed some EINTR errors while writing to > pipes and haven't dealt with stdio or C in ages at this point. > > diff --git a/src/formats_i.c b/src/formats_i.c > index 7048040d..d4082cc5 100644 > --- a/src/formats_i.c > +++ b/src/formats_i.c > @@ -129,10 +129,21 @@ int lsx_padbytes(sox_format_t * ft, size_t n) > */ > size_t lsx_writebuf(sox_format_t * ft, void const * buf, size_t len) > { > - size_t ret =3D fwrite(buf, (size_t) 1, len, (FILE*)ft->fp); > - if (ret !=3D len) { > - lsx_fail_errno(ft, errno, "error writing output file"); > - clearerr((FILE*)ft->fp); /* Allows us to seek back to write header */ > + FILE *fp =3D (FILE*)ft->fp; > + const char *c =3D (const char *)buf; > + size_t ret =3D fwrite(c, 1, len, fp); > + > + while (ret !=3D len) { > + switch (errno) { > + case EINTR: > + len -=3D ret; > + c +=3D ret; > + ret =3D fwrite(c, 1, len, fp); > + break; > + default: > + lsx_fail_errno(ft, errno, "error writing output file"); > + clearerr(fp); /* Allows us to seek back to write header */ > + } > } > ft->tell_off +=3D ret; > return ret; The return value and ft->tell_off will be wrong in case the fwrite() was restarted. What did you do that caused the EINTR error? -- = M=E5ns Rullg=E5rd _______________________________________________ SoX-devel mailing list SoX-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sox-devel