Bug 213441 - Reading 4 bytes from 4 byte file returns 0.
Summary: Reading 4 bytes from 4 byte file returns 0.
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Enterprise Linux 4
Classification: Red Hat
Component: kernel
Version: 4.0
Hardware: x86_64
OS: Linux
medium
medium
Target Milestone: ---
: ---
Assignee: Red Hat Kernel Manager
QA Contact: Brian Brock
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2006-11-01 15:06 UTC by Andrew Bell
Modified: 2007-11-30 22:07 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2006-11-07 21:28:21 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)

Description Andrew Bell 2006-11-01 15:06:12 UTC
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.7) Gecko/20060909 Firefox/1.5.0.7

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):
kernel-2.6.9-22.0.1.EL

How reproducible:
Always


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 15:36:47 UTC
That should say "Other size files work _fine_".  Sorry for the typo.

Comment 2 Neil Horman 2006-11-07 21:28:21 UTC
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.