sox-devel@lists.sourceforge.net unofficial mirror
 help / color / mirror / code / Atom feed
From: "Måns Rullgård" <mans@mansr.com>
To: Eric Wong <normalperson@yhbt.net>
Cc: sox-devel@lists.sourceforge.net
Subject: Re: [WIP/PATCH] restart writes on EINTR
Date: Fri, 10 Jun 2022 20:05:44 +0100	[thread overview]
Message-ID: <yw1xv8t88hkn.fsf@mansr.com> (raw)
In-Reply-To: <20220605210727.GA9582@dcvr> (Eric Wong's message of "Sun, 5 Jun 2022 21:07:27 +0000")

Eric Wong <normalperson@yhbt.net> 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 = fwrite(buf, (size_t) 1, len, (FILE*)ft->fp);
> -  if (ret != len) {
> -    lsx_fail_errno(ft, errno, "error writing output file");
> -    clearerr((FILE*)ft->fp); /* Allows us to seek back to write header */
> +  FILE *fp = (FILE*)ft->fp;
> +  const char *c = (const char *)buf;
> +  size_t ret = fwrite(c, 1, len, fp);
> +
> +  while (ret != len) {
> +    switch (errno) {
> +    case EINTR:
> +      len -= ret;
> +      c += ret;
> +      ret = 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 += 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åns Rullgård


_______________________________________________
SoX-devel mailing list
SoX-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sox-devel

  reply	other threads:[~2022-06-10 19:25 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-05 21:07 [WIP/PATCH] restart writes on EINTR Eric Wong
2022-06-10 19:05 ` Måns Rullgård [this message]
2022-06-11  2:17   ` Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://lists.sourceforge.net/lists/listinfo/sox-devel

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=yw1xv8t88hkn.fsf@mansr.com \
    --to=sox-devel@lists.sourceforge.net \
    --cc=normalperson@yhbt.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/sox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).