Operating System - Linux
1753868 Members
7479 Online
108809 Solutions
New Discussion юеВ

Re: read() fails with "Not enough space"

 
SOLVED
Go to solution
Fabio Barillari
New Member

read() fails with "Not enough space"

Hi all!
My C program got quit after a read() on a file. The read() failed and the strerror(errno) reported тАЬNot enough spaceтАЭ (ENOMEM).

From the man documentation it seems the read() api cannot return with an ENOMEM error code.

Should I check system resources (swap space, memory) or most likely is this error related to code error and/or file corruption?

Thanks,
Fabio
7 REPLIES 7
A. Clay Stephenson
Acclaimed Contributor

Re: read() fails with "Not enough space"

The read() system call cannot set errno = ENOMEM (12) because it does no checking to see if the size of the buffer is smaller than the number of bytes read. Such an error could result in a segmentation violation. You should be aware that errno is not automatically reset to 0 between system calls, so the ENOMEM is almost certainly an artifact of an earlier system call. What I suspect happened is that an earlier malloc(), calloc(), or realloc() failed and returned a NULL pointer that was not detected as an error and set errno = ENOMEM. When the read failed, what value was actually returned?
If it ain't broke, I can fix that.
IT_2007
Honored Contributor

Re: read() fails with "Not enough space"

check if /tmp is having enough space or not?
Run bdf /tmp
A. Clay Stephenson
Acclaimed Contributor

Re: read() fails with "Not enough space"

The write() system call can set errno = ENOMEM but not the read() system call; errno = ENOMEM can result from a failed write() system call but fundamentally, an error occurred earlier that was ignored and you are seeing an artifact of that failure.
If it ain't broke, I can fix that.
Fabio Barillari
New Member

Re: read() fails with "Not enough space"

Srini,
Thank you for your answer├в ┬ж the /tmp is empty.

Clay,
I├в m trying to understand the issue with my C program reading few logs and source code.
From the code I see, the program that:
- Starts a child process. From log I can see the child starts successfully.
- Blocks signals and locks a region of the file (lseek() + fnctl())
- lseek() and read() the first record (head of the file) successfully
- and then
- lseek() return a value different from -1 (so I guess it goes success)
- and read() fails

It is a logical fail.. I mean I expect it read 4 bytes├в ┬ж and if read() < 4 I report an error up├в ┬ж

I have a doubt ├в ┬жis it possible that I├в m passing to the lseek(*,*,SEEK_SET) a value greater then the actual file size and it is not returning ├в 1 ?

Thanks
Fabio


A. Clay Stephenson
Acclaimed Contributor
Solution

Re: read() fails with "Not enough space"

Lseek() returns the offset from the beginning of the file so it is working as expected. Read would only set errno if it returns -1 --- which is not true in your case. You are probably seeking to the (or very near to) end of file and there is simply not enough remaining data to satisfy your read request. That condition does not set errno so I repeat, your errno = ENOMEM is an artifact of an (probably much) earlier
system call. You are letting a failed system call go ignored.
If it ain't broke, I can fix that.
Sandman!
Honored Contributor

Re: read() fails with "Not enough space"

If your C program is short you can post it here (or actually attach it) so that it can be looked at.

thanks!
Fabio Barillari
New Member

Re: read() fails with "Not enough space"

Unfortunately, the program code is too long to be posted here.
However, from your answers I understood I have to look for the problem in a different place in the code.

Thanks to all.
Fabio