This service will be undergoing maintenance at 00:00 UTC, 2017-10-23 It is expected to last about 30 minutes
Bug 490822 - [RHEL4] Optimizing Causes Incorrect "errno"
[RHEL4] Optimizing Causes Incorrect "errno"
Status: CLOSED ERRATA
Product: Red Hat Enterprise Linux 4
Classification: Red Hat
Component: glibc (Show other bugs)
4.7
All Linux
low Severity medium
: rc
: ---
Assigned To: Andreas Schwab
BaseOS QE
:
Depends On: 490821
Blocks:
  Show dependency treegraph
 
Reported: 2009-03-18 03:49 EDT by CAI Qian
Modified: 2016-11-24 10:36 EST (History)
5 users (show)

See Also:
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:
Cloudforms Team: ---


Attachments (Terms of Use)


External Trackers
Tracker ID Priority Status Summary Last Updated
Sourceware 3493 None None None Never

  None (edit)
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

Note You need to log in before you can comment on or make changes to this bug.