From owner-freebsd-bugs Sun Aug 4 14:40:23 2002 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id AC40F37B400 for ; Sun, 4 Aug 2002 14:40:02 -0700 (PDT) Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id EF98143E5E for ; Sun, 4 Aug 2002 14:40:01 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.4/8.12.4) with ESMTP id g74Le1JU025758 for ; Sun, 4 Aug 2002 14:40:01 -0700 (PDT) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.4/8.12.4/Submit) id g74Le1ok025756; Sun, 4 Aug 2002 14:40:01 -0700 (PDT) Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 74E6F37B400 for ; Sun, 4 Aug 2002 14:34:30 -0700 (PDT) Received: from www.freebsd.org (www.FreeBSD.org [216.136.204.117]) by mx1.FreeBSD.org (Postfix) with ESMTP id 2963D43E5E for ; Sun, 4 Aug 2002 14:34:30 -0700 (PDT) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.12.4/8.12.4) with ESMTP id g74LYTOT074372 for ; Sun, 4 Aug 2002 14:34:29 -0700 (PDT) (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.12.4/8.12.4/Submit) id g74LYTM6074371; Sun, 4 Aug 2002 14:34:29 -0700 (PDT) Message-Id: <200208042134.g74LYTM6074371@www.freebsd.org> Date: Sun, 4 Aug 2002 14:34:29 -0700 (PDT) From: Antti Louko To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-1.0 Subject: misc/41331: Pthread library open sets O_NONBLOCK flag and causes unnecessary EAGAIN errors especially with /dev/stdout. Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org >Number: 41331 >Category: misc >Synopsis: Pthread library open sets O_NONBLOCK flag and causes unnecessary EAGAIN errors especially with /dev/stdout. >Confidential: no >Severity: serious >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Sun Aug 04 14:40:01 PDT 2002 >Closed-Date: >Last-Modified: >Originator: Antti Louko >Release: 4.5 >Organization: >Environment: FreeBSD xxx.louko.com 4.5-RELEASE FreeBSD 4.5-RELEASE #1: Tue Mar 5 23:48:33 EET 2002 root@xxx.louko.com:/xxx/src/sys/compile/ALO i386 >Description: When using threads, the threads library (/usr/src/lib/libc_r/uthread/uthread_fd.c) sets O_NONBLOCK for each new opened file and fails to emulate the blocking write(2) correctly. This affects eg. when a program opens /dev/stdout for writing and thje reader process is slower than the writer. The writer gets EAGAIN error which shouldn't happen when the open call didn't specify O_NONBLOCK flag. >How-To-Repeat: Run the following program (compiled with gcc -pthread -o writer writer.c) and feed its output to the shell script: ./writer | sh reader.sh reader.sh: ---------------------------------------- #! /bin/sh while : do dd of=/dev/null bs=1k count=1 sleep 1 done ---------------------------------------- writer.c ---------------------------------------- #include #include #include main(int argc, char **argv) { char buf[1024]; int fd; int i; int total = 0; fd = open("/dev/stdout",O_WRONLY|O_CREAT|O_TRUNC,0666); if (fd == -1) { int e; e = errno; fprintf(stderr,"open, errno: %d\n",e); exit(1); } for(i = 0; i < sizeof(buf); i++) buf[i] = 'a' + (i % 26); for(;;) { int n; n = write(fd,buf,sizeof(buf)); if (n > 0) total += n; if (n != sizeof(buf)) { int e; e = errno; fprintf(stderr,"write, errno: %d\n",e); fprintf(stderr,"Total bytes written %d\n",total); exit(1); } } } ---------------------------------------- Run the following program (compiled with gcc -pthread -o writer writer.c) and feed its output to the shell script: ./writer | sh reader.sh reader.sh: ---------------------------------------- #! /bin/sh while : do dd of=/dev/null bs=1k count=1 sleep 1 done ---------------------------------------- writer.c ---------------------------------------- #include #include #include main(int argc, char **argv) { char buf[1024]; int fd; int i; int total = 0; fd = open("/dev/stdout",O_WRONLY|O_CREAT|O_TRUNC,0666); if (fd == -1) { int e; e = errno; fprintf(stderr,"open, errno: %d\n",e); exit(1); } for(i = 0; i < sizeof(buf); i++) buf[i] = 'a' + (i % 26); for(;;) { int n; n = write(fd,buf,sizeof(buf)); if (n > 0) total += n; if (n != sizeof(buf)) { int e; e = errno; fprintf(stderr,"write, errno: %d\n",e); fprintf(stderr,"Total bytes written %d\n",total); exit(1); } } } ---------------------------------------- Run the following program (compiled with gcc -pthread -o writer writer.c) and feed its output to the shell script: ./writer | sh reader.sh reader.sh: ---------------------------------------- #! /bin/sh while : do dd of=/dev/null bs=1k count=1 sleep 1 done ---------------------------------------- writer.c ---------------------------------------- #include #include #include main(int argc, char **argv) { char buf[1024]; int fd; int i; int total = 0; fd = open("/dev/stdout",O_WRONLY|O_CREAT|O_TRUNC,0666); if (fd == -1) { int e; e = errno; fprintf(stderr,"open, errno: %d\n",e); exit(1); } for(i = 0; i < sizeof(buf); i++) buf[i] = 'a' + (i % 26); for(;;) { int n; n = write(fd,buf,sizeof(buf)); if (n > 0) total += n; if (n != sizeof(buf)) { int e; e = errno; fprintf(stderr,"write, errno: %d\n",e); fprintf(stderr,"Total bytes written %d\n",total); exit(1); } } } ---------------------------------------- >Fix: >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message