From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/7820 Path: news.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: Making stdio writes robust/recoverable under errors Date: Fri, 29 May 2015 10:08:35 -0400 Message-ID: <20150529140835.GG17573@brightrain.aerifal.cx> References: <20150529135300.GD17573@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="xs+9IvWevLaxKUtW" X-Trace: ger.gmane.org 1432908534 24942 80.91.229.3 (29 May 2015 14:08:54 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 29 May 2015 14:08:54 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-7832-gllmg-musl=m.gmane.org@lists.openwall.com Fri May 29 16:08:53 2015 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1YyKxu-0003y4-Of for gllmg-musl@m.gmane.org; Fri, 29 May 2015 16:08:50 +0200 Original-Received: (qmail 28434 invoked by uid 550); 29 May 2015 14:08:49 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 28409 invoked from network); 29 May 2015 14:08:48 -0000 Content-Disposition: inline In-Reply-To: <20150529135300.GD17573@brightrain.aerifal.cx> User-Agent: Mutt/1.5.21 (2010-09-15) Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:7820 Archived-At: --xs+9IvWevLaxKUtW Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 --xs+9IvWevLaxKUtW Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="fwrite_intr.c" #include #include #include #include #include #include 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); } --xs+9IvWevLaxKUtW--