Bug 213441 - Reading 4 bytes from 4 byte file returns 0.
Reading 4 bytes from 4 byte file returns 0.
Product: Red Hat Enterprise Linux 4
Classification: Red Hat
Component: kernel (Show other bugs)
x86_64 Linux
medium Severity medium
: ---
: ---
Assigned To: Red Hat Kernel Manager
Brian Brock
Depends On:
  Show dependency treegraph
Reported: 2006-11-01 10:06 EST by Andrew Bell
Modified: 2007-11-30 17:07 EST (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2006-11-07 16:28:21 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Andrew Bell 2006-11-01 10:06:12 EST
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20060909 Firefox/

Description of problem:
Reading 4 bytes from a file with length 4 should return 4.  It returns 0.  Tried this on NFS and local filesystem with the same results.  Other size files work file (reading 3 bytes from a three byte file returns 3, reading 5 bytes from a 5 byte file returns 5, etc.).  Very weird.

Code snippet:

  m_fd = open(filename.c_str(), O_CREAT | O_RDWR,
              S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
  if (m_fd == -1)
    return -1;
  do {
char arr[2000];
    error = read(m_fd, arr, 4);
  } while (error == EINTR);

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:
1. Make a 4 byte file with vi or some other utility.
2. Use code similar to above.
3. Check value of "error"

Actual Results:
Got 0.

Expected Results:
Got 4.

Additional info:
Comment 1 Andrew Bell 2006-11-01 10:36:47 EST
That should say "Other size files work _fine_".  Sorry for the typo.
Comment 2 Neil Horman 2006-11-07 16:28:21 EST
The sample code above is busted.  You will always go through 2 iterations of the
do..while loop when the input file is 4 bytes long (or almost always, barring no
other problems), because EINTR is defined as 4.  As such, with a 4 byte input
file we wind up reading the first 4 bytes, looping back around because error ==
EINTR, then we read 0 bytes, since we're at the EOF.

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