LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-05-2013, 05:20 AM   #1
manjuhr
LQ Newbie
 
Registered: Aug 2013
Posts: 2

Rep: Reputation: Disabled
sendfile() fails with regular files on RHEL5.10


Hello All,

I am executing following program on RHEL5.10, sendfile() is failing with errno:22

uname -rvio
2.6.18-366.el5 #1 SMP Fri Jul 19 13:36:15 EDT 2013 ppc64 GNU/Linux

#include <sys/sendfile.h>
#include <err.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main( int argc, char *argv[] )
{
int in_file, out_file;

if ( argc != 3 )
{
fprintf( stderr, "usage: %s <in-file> <out-file>\n", argv[0] );
exit( 1 );
}

if (( in_file = open( argv[1], O_RDONLY )) == -1 ) err( 1, "open" );
if (( out_file = open( argv[2], O_WRONLY | O_CREAT | O_TRUNC, 0644 )) == -1 )
err( 1, "open(2)" );

if ( sendfile( out_file, in_file, NULL, 4 ) == -1 ) err( 1, "sendfile" );

exit( 0 );
}


Here sendfile fails with : EINVAL

> part of strace output:
----------------------------------------------------------------------
open("input_file", O_RDONLY) = 3
open("output_file", O_WRONLY|O_CREAT|O_TRUNC, 0644) = 4
sendfile(4, 3, NULL, 4) = -1 EINVAL (Invalid argument)
-----------------------------------------------------------------------

Please, let me know if sendfile() supports regular files on "2.6.18-366.el5"

Thanks in advance

Last edited by manjuhr; 08-05-2013 at 05:45 AM.
 
Old 08-05-2013, 12:22 PM   #2
salsalinux
LQ Newbie
 
Registered: May 2013
Location: Utah
Distribution: Mint, Debian, CentOS
Posts: 10

Rep: Reputation: Disabled
Do you have permissions to the files that you are giving as arguments?
 
Old 08-05-2013, 12:27 PM   #3
salsalinux
LQ Newbie
 
Registered: May 2013
Location: Utah
Distribution: Mint, Debian, CentOS
Posts: 10

Rep: Reputation: Disabled
For what it's worth, I copied your code and compiled it, and it worked for me. I created in.txt, and out.txt, and ran the program with those 2 files as arguments, and here is the last portion of strace:

...
open("in.txt", O_RDONLY) = 3
open("out.txt", O_WRONLY|O_CREAT|O_TRUNC, 0644) = 4
sendfile(4, 3, NULL, 4) = 4
exit_group(0) = ?

However, I am running kernel 2.6.38-8-generic #42-Ubuntu SMP x86_64

The man page for sendfile says about the error code EINVAL: Descriptor is not valid or locked, or an mmap(2)-like operation is not available for in_fd.

You can find other info about it in the man page that may be useful for your particular files.

Last edited by salsalinux; 08-05-2013 at 12:32 PM.
 
1 members found this post helpful.
Old 08-05-2013, 01:49 PM   #4
manjuhr
LQ Newbie
 
Registered: Aug 2013
Posts: 2

Original Poster
Rep: Reputation: Disabled
Hi,

Thanks for quick reply ...

The input and output files have read/write permissions.

I tested code on "3.0.80-0.7-ppc64 #1 SMP Tue Jun 25 18:32:49 UTC 2013 (25740f8) ppc64 GNU/Linux" and test passes.

I am seeing the issue only : "Linux 2.6.18-366.el5 #1 SMP Fri Jul 19 13:36:15 EDT 2013 ppc64 ppc64 ppc64 GNU/Linux"

Regarding man page: There is a reference to kernel release -
---------------------
Presently (Linux 2.6.9): in_fd, must correspond to a file which supports mmap(2)-like operations (i.e., it cannot be a socket); and out_fd must refer to a socket.
---------------------

Following link also mentions "sendfile()" supports regular file only after "since Linux 2.6.33".
Link: http://marc.info/?l=linux-man&m=129767829918385

So want to know if sendfile() supports regular file for "fd_out".

Last edited by manjuhr; 08-07-2013 at 04:33 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] vncviewer fails to connect after applying latest RHEL5 maintenance bret Linux - Server 3 08-17-2012 02:15 PM
[SOLVED] Delete regular files (not hidden files) with find + rm in one line older than 15 Virtuose Linux - Newbie 1 01-08-2011 06:24 PM
RHEL5 server fails to install x86_64 but 32bit okay? spaceace13666 Red Hat 10 09-18-2008 07:12 AM
ssh fails when ldap is started on my RHEL5 smallbook Linux - Server 8 06-17-2008 10:02 PM
Xserver fails to start w/ 8600gt on rhel5 okinhim Linux - Hardware 0 03-14-2008 07:38 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:08 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration