LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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 09-14-2009, 08:35 PM   #1
hellgirl
LQ Newbie
 
Registered: Sep 2009
Location: tulsa, ok
Distribution: n/o
Posts: 5

Rep: Reputation: 0
open local file error when creating file descriptor


I have a error message when I ran my program

that I couldn't open my local file.


I have two files

first one is called client, second one is called server

I am using named pipes to sent a message from client to the other file called server

in client I
used mknod() to create the two named pipes, one for read, one for write

and created new thread in client

using fork() spawned a child process that executed the server file


both named pipes are opened

the client file got the message from the user

and sent it through the named pipes to the server file

when the server receives the message , it needs to verfify it is correct

in the server file, a local file descriptor is created to read and send
this verifing message when it is not correct




but I am getting an OPEN() error

when I tried to open this shared local array buff

and attach it to a file descriptor
where the message is kept

why do I get this error

in server file

int main()
{
/*both named pipes are open*/

rfd=open(IFIO1,0);
wfd=open(IFIO2,1);

server(rfd,wfd);
}

void server(int rfd, int wfd)
{
int localfile;
char buff[max];
char buff2[max];

n=read(rfd,buff,max);

if ((localfile = open(buff,0)) < 0) /*error line I have question*/
{


/* we got a open error */
/* now tell the IPC Client */

sprintf(buff2,"Filename %s Failed on Open Terminating", buff);

n=strlen(buff2);
buff2[n]='\0';


if(write(wfd, buff2, n) != n)
{

/* write error on the IPC descriptor */
 
Old 09-14-2009, 10:03 PM   #2
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,126
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
before you do the sprintf you might want to perror("open failed") to find out what caused the open to fail
 
  


Reply



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
Too many file open - How can we define Max limit of file descriptor janeshb Linux - Server 11 09-29-2009 10:41 AM
How to run two task and open the same fd(file descriptor) peterhuang Linux - Software 2 05-21-2008 05:03 AM
How many open file descriptor possible in RHEL 4.4 mani77_iitr Red Hat 2 12-12-2007 08:30 AM
LVM error: File Descriptor left open kapil.hazarika Linux - Software 1 06-18-2007 08:03 PM
Low open file descriptor limit Suse 9.2 kryten SUSE / openSUSE 3 12-20-2004 12:20 AM

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

All times are GMT -5. The time now is 04:08 AM.

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
Open Source Consulting | Domain Registration