From ru@ucb.crimea.ua  Sun May 24 08:01:49 1998
Received: from relay.ucb.crimea.ua (relay.ucb.crimea.ua [194.93.177.113])
          by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id IAA27454
          for <FreeBSD-gnats-submit@freebsd.org>; Sun, 24 May 1998 08:01:32 -0700 (PDT)
          (envelope-from ru@ucb.crimea.ua)
Received: (from ru@localhost)
	by relay.ucb.crimea.ua (8.8.8/8.8.8) id SAA09939;
	Sun, 24 May 1998 18:01:18 +0300 (EEST)
	(envelope-from ru)
Message-Id: <199805241501.SAA09939@relay.ucb.crimea.ua>
Date: Sun, 24 May 1998 18:01:18 +0300 (EEST)
From: Ruslan Ermilov <ru@ucb.crimea.ua>
Reply-To: ru@ucb.crimea.ua
To: FreeBSD-gnats-submit@freebsd.org
Subject: libc: printf() causes errno is set to 2
X-Send-Pr-Version: 3.2

>Number:         6741
>Category:       bin
>Synopsis:       libc: printf() causes errno is set to 2
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun May 24 08:00:01 PDT 1998
>Closed-Date:    Mon May 25 00:25:53 PDT 1998
>Last-Modified:  Mon May 25 00:27:23 PDT 1998
>Originator:     Ruslan Ermilov
>Release:        FreeBSD 2.2.6-STABLE i386
>Organization:
United Commercial Bank
>Environment:

	Fresh FreeBSD 2.2.6-STABLE,
	Standard non-threaded C library.

>Description:

	Using printf(), fprintf(stdout, ...) causes global
	variable errno set to 2.
	This is only true for standard non-threaded library.
	Threaded library calls do not change errno.

>How-To-Repeat:

Try the following:
1. with standard, non-threada libc
2. with threaded library (libc_r)
3. change printf -> fprintf(stdout), then to fprintf(stderr).

#include <sys/errno.h>
#include <stdio.h>

void main(void)
{
	printf("errno=%d\n", errno);
	printf("errno=%d\n", errno);
}

>Fix:
	
	Sorry, not available yet.
>Release-Note:
>Audit-Trail:

From: Stephen McKay <syssgm@dtir.qld.gov.au>
To: Ruslan Ermilov <ru@ucb.crimea.ua>
Cc: freebsd-gnats-submit@freebsd.org, syssgm@dtir.qld.gov.au
Subject: Re: bin/6741: libc: printf() causes errno is set to 2 
Date: Mon, 25 May 1998 15:40:09 +1000

 On Sunday, 24th May 1998, Ruslan Ermilov wrote:
 
 >>Severity:       critical
 >>Priority:       high
 
 Come now!  It can't be as bad as all that!
 
 >	Using printf(), fprintf(stdout, ...) causes global
 >	variable errno set to 2.
 
 Library routines can write garbage in errno any time they want because
 errno should only be checked for system calls and designated library
 routines and only when the call returns an error indication.
 
 There is no problem here.  You just have to expect errno to change
 for no good reason.
 
 In case you are curious, the errno=2 comes from malloc() checking for
 the existance of /etc/malloc.conf.
 
 Stephen.

From: Ruslan Ermilov <ru@ucb.crimea.ua>
To: Stephen McKay <syssgm@dtir.qld.gov.au>
Cc: freebsd-gnats-submit@freebsd.org
Subject: Re: bin/6741: libc: printf() causes errno is set to 2
Date: Mon, 25 May 1998 09:07:38 +0300

 On Mon, May 25, 1998 at 03:40:09PM +1000, Stephen McKay wrote:
 > On Sunday, 24th May 1998, Ruslan Ermilov wrote:
 > 
 > >>Severity:       critical
 > >>Priority:       high
 > 
 > Come now!  It can't be as bad as all that!
 > 
 > >	Using printf(), fprintf(stdout, ...) causes global
 > >	variable errno set to 2.
 > 
 > Library routines can write garbage in errno any time they want because
 > errno should only be checked for system calls and designated library
 > routines and only when the call returns an error indication.
 > 
 > There is no problem here.  You just have to expect errno to change
 > for no good reason.
 > 
 > In case you are curious, the errno=2 comes from malloc() checking for
 > the existance of /etc/malloc.conf.
 
 Why then it is not set to 2 when I use fprintf(stderr, ...) or compile
 with libc_r?
 
 > 
 > Stephen.
 
 -- 
 Ruslan Ermilov          System Administrator
 ru@ucb.crimea.ua        United Commercial Bank
 +380-652-247647         Simferopol, Crimea
 2426679                 ICQ Network, UIN

From: Stephen McKay <syssgm@dtir.qld.gov.au>
To: Ruslan Ermilov <ru@ucb.crimea.ua>
Cc: freebsd-gnats-submit@freebsd.org, syssgm@dtir.qld.gov.au
Subject: Re: bin/6741: libc: printf() causes errno is set to 2 
Date: Mon, 25 May 1998 17:07:53 +1000

 On Monday, 25th May 1998, Ruslan Ermilov wrote:
 
 >On Mon, May 25, 1998 at 03:40:09PM +1000, Stephen McKay wrote:
 >> In case you are curious, the errno=2 comes from malloc() checking for
 >> the existance of /etc/malloc.conf.
 >
 >Why then it is not set to 2 when I use fprintf(stderr, ...) or compile
 >with libc_r?
 
 The luck of the draw?  I think you would learn a lot about the internals
 of libc by tracking this down yourself.  I don't know the answer.  But
 I don't need to know the answer since it is not a problem for errno to
 change (or not change) for no reason.  Errno has meaning only when a
 system call has failed, or when one of a few library routines that are
 documented to set errno has failed.
 
 Stephen.
State-Changed-From-To: open->closed 
State-Changed-By: phk 
State-Changed-When: Mon May 25 00:25:53 PDT 1998 
State-Changed-Why:  
The 2 returned is likely from mallocs check for /etc/malloc.conf, 
this will probably only happen on the first call. 

Anyway, unless the manpage talks about errno, expect it to be junk. 

junk can also be zero, and it may depend in a lot of factors 
>Unformatted:
