From: Rich Felker <dalias@libc.org>
To: musl@lists.openwall.com
Subject: Re: Making stdio writes robust/recoverable under errors
Date: Fri, 29 May 2015 10:08:35 -0400 [thread overview]
Message-ID: <20150529140835.GG17573@brightrain.aerifal.cx> (raw)
In-Reply-To: <20150529135300.GD17573@brightrain.aerifal.cx>
[-- Attachment #1: Type: text/plain, Size: 649 bytes --]
On Fri, May 29, 2015 at 09:53:00AM -0400, Rich Felker wrote:
> An attached test program demonstrates the issue. It assumes Linux 64k
> pipe buffers so it's not appropriate for inclusion in tests in its
> current form, but it gets the job done where it works. It attempts to
> send 128k over a pipe via write followed by a series of fwrite retries
> that are interrupted by signals that cause EINTR; thanks to the
> kernel's pipe buffer semantics, there's basically no timing/race
> aspect involved. With current musl, I get only 130560 across the pipe;
> with the above line removed, I get all 131072.
And here is the missing attachment. :-)
Rich
[-- Attachment #2: fwrite_intr.c --]
[-- Type: text/plain, Size: 934 bytes --]
#include <pthread.h>
#include <stdio.h>
#include <signal.h>
#include <string.h>
#include <unistd.h>
#include <sys/time.h>
char bigbuf[65536];
void *thr(void *ptr)
{
int *p = ptr;
char tmp[256];
size_t l, t=0;
for (;;) {
l = read(p[0], tmp, sizeof tmp);
if (l <= 0) break;
t += l;
}
printf("read %zu\n", t);
}
void dummy(int sig)
{
}
int main()
{
int testpipe[2];
pipe(testpipe);
FILE *f = fdopen(testpipe[1], "w");
struct sigaction sa = { .sa_handler = dummy };
sigaction(SIGALRM, &sa, 0);
//alarm(1);
setitimer(ITIMER_REAL, &(struct itimerval){ .it_interval.tv_usec = 10000, .it_value.tv_usec = 10000 }, 0);
char *p = bigbuf;
size_t n = sizeof bigbuf, l;
memset(p, 42, n);
write(testpipe[1], p, n);
l = fwrite(p, 1, 512, f);
p+=l, n-=l;
l = fwrite(p, 1, n, f);
pthread_t td;
pthread_create(&td, 0, thr, testpipe);
while (p+=l, n-=l)
l = fwrite(p, 1, n, f);
fclose(f);
pthread_join(td, 0);
}
next prev parent reply other threads:[~2015-05-29 14:08 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-29 13:53 Rich Felker
2015-05-29 14:08 ` Rich Felker [this message]
2015-05-29 14:36 ` Rich Felker
2015-06-05 21:14 ` Rich Felker
2015-06-05 21:47 ` Laurent Bercot
2015-06-06 5:32 ` Rich Felker
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-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150529140835.GG17573@brightrain.aerifal.cx \
--to=dalias@libc.org \
--cc=musl@lists.openwall.com \
/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://git.vuxu.org/mirror/musl/
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 NNTP newsgroup(s).