This service will be undergoing maintenance at 00:00 UTC, 2016-08-01. It is expected to last about 1 hours

Bug 490822

Summary: [RHEL4] Optimizing Causes Incorrect "errno"
Product: Red Hat Enterprise Linux 4 Reporter: CAI Qian <caiqian>
Component: glibcAssignee: Andreas Schwab <schwab>
Status: CLOSED ERRATA QA Contact: BaseOS QE <qe-baseos-auto>
Severity: medium Docs Contact:
Priority: low    
Version: 4.7CC: drepper.fsp, ebachalo, jakub, pmuller
Target Milestone: rc   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: glibc-2.3.4-2.50 Doc Type: Bug Fix
Doc Text:
Previously, the sysconf() function was declared to examine only its arguments and have no effects except the return value. However, since it also potentially updates the global "errno" variable, this update corrects this declaration to remove the "const" attribute to ensure that the "errno" variable contains the expected value.
Story Points: ---
Clone Of: 490821 Environment:
Last Closed: 2011-02-16 09:28:58 EST Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Bug Depends On: 490821    
Bug Blocks:    

Description CAI Qian 2009-03-18 03:49:54 EDT
+++ This bug was initially created as a clone of Bug #490821 +++

Description of problem:
If compile the following program with -O2. The "errno" is incorrect.

#include <stdio.h>
#include <errno.h>
#include <unistd.h>

int
main(void)
{
  int retval;

  errno = 0;
  retval = sysconf(-1);
  printf ("retval = %d, errno = %d\n", retval, errno);

  return 0;
}

# gcc -O2 errno.c -o errno
# ./errno
retval = -1, errno = 0

Without compilation optimization, it works fine.
# gcc errno.c -o errno
# ./errno
retval = -1, errno = 22

It is also fine even with -O2, if remove the line "errno = 0;" from the program.

RHEL4-U7 has the same problem.

Version-Release number of selected component (if applicable):
gcc-4.1.2-44.el5
gcc-3.4.6-10

How reproducible:
always

Steps to Reproduce:
1. compile the reproducer with -O2
2. run the reproducer.
  
Actual results:
retval = -1, errno = 0

Expected results:
retval = -1, errno = 22

Additional info:
Comment 1 Jakub Jelinek 2009-03-18 05:30:50 EDT
That's because sysconf used to have const attribute up to 2006-11-09.
Comment 4 Jaromir Hradilek 2011-01-19 05:43:32 EST
    Technical note added. If any revisions are required, please edit the "Technical Notes" field
    accordingly. All revisions will be proofread by the Engineering Content Services team.
    
    New Contents:
Previously, the sysconf() function was declared to examine only its arguments and have no effects except the return value. However, since it also potentially updates the global "errno" variable, this update corrects this declaration to remove the "const" attribute to ensure that the "errno" variable contains the expected value.
Comment 5 errata-xmlrpc 2011-02-16 09:28:58 EST
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on therefore solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.

http://rhn.redhat.com/errata/RHBA-2011-0248.html