Re: open FIFO erro
- From: "kondal" <kondal04@xxxxxxxxx>
- Date: 25 Sep 2006 02:55:52 -0700
The problem is with the FIFO_SERVER macro
I suppose you do not have permissions to create a /tmp/fifoserver fifo
file.
If that is not the problem then the issue is with the fifo permissions.
you donot have either read or write permissions for the fifo file. The
mode is made and with umask.
try using mkfifo(FIFO_SERVER,O_CREAT|O_EXCL|S_IRWXU)
-kondal
freegnu wrote:
hi all , i have a test program, which the prarent process write "hello
world" to a FIFO , and the child process read it form the FIFO,and printf it
on the screem.
but when i run the test program, it open the FIFO,there some problem happen.
the prarent process hand up on open(), and
the child process has error take place
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#define FIFO_SERVER "/tmp/fifoserver"
main(int argc,char** argv)
{
int fd;
char w_buf[1024] = "hello world";
char r_buf[1024];
int real_wnum;
memset(w_buf,0,1024);
if((mkfifo(FIFO_SERVER,O_CREAT|O_EXCL)<0)&&(errno!=EEXIST))
printf("cannot create fifoserver\n");
if(fd==-1)
if(errno==ENXIO)
printf("open error; no reading process\n");
if(fork() > 0)
{
if ((fd = open(FIFO_SERVER,O_WRONLY,0)) < 0) // hand up on open()
{
printf("parent open error\n");
if(EEXIST == errno)printf("pEEXIST\n");
if(EACCES == errno)printf("pEACCES\n");
if(EROFS == errno)printf("pEROFS\n");
if(EFAULT == errno)printf("pEFAULT\n");
if(EINVAL == errno)printf("pEINVAL\n");
if(ENAMETOOLONG == errno)printf("pENAMETOOLONG\n");
if(ENOTDIR == errno)printf("pENOTDIR\n");
if(ENOMEM == errno)printf("pENOMEM\n");
if(ELOOP == errno)printf("pELOOP\n");
if(EIO == errno)printf("pEIO\n");
}
real_wnum=write(fd,w_buf,15);
if(real_wnum==-1)
{
if(errno==EAGAIN)
printf("write to fifo error; try later\n");
}else{
printf("real write num is %d\n",real_wnum);
}
}else{
if ((fd = open(FIFO_SERVER,O_RDONLY,0)) < 0)
{
printf("child open error\n");
if(EEXIST == errno)printf("cEEXIST\n");
if(EACCES == errno)printf("cEACCES\n");// the errno happen, it print out
cEACCES
if(EROFS == errno)printf("cEROFS\n");
if(EFAULT == errno)printf("cEFAULT\n");
if(EINVAL == errno)printf("cEINVAL\n");
if(ENAMETOOLONG == errno)printf("cENAMETOOLONG\n");
if(ENOTDIR == errno)printf("cENOTDIR\n");
if(ENOMEM == errno)printf("cENOMEM\n");
if(ELOOP == errno)printf("cELOOP\n");
if(EIO == errno)printf("cEIO\n");
}
read(fd, r_buf, 100);
printf("%s\n", r_buf);
}
}
.
- References:
- open FIFO erro
- From: freegnu
- open FIFO erro
- Prev by Date: Re: one-to-one client server design
- Next by Date: how to write a structure in a shared mem segment.
- Previous by thread: open FIFO erro
- Next by thread: Re: open FIFO erro
- Index(es):
Relevant Pages
|