Re: open FIFO erro



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);
}
}

.



Relevant Pages

  • [git patches] net driver fixes, and a new driver
    ... address of board private structure ... * the Rx FIFO should be large enough to accommodate at least ... static int check_module_parm ...
    (Linux-Kernel)
  • [PATCH] kfifo reorganization for a generic interface
    ... this is the first part of the new generic kfifo interfaces. ... The current kernel fifo API is not very widely used, ... goto exit; ... int bluetooth_power; ...
    (Linux-Kernel)
  • select() strangeness.
    ... TEST_FIFO is a fifo created with mkfifo in the current directory. ... int main ... if (FD_ISSET(fd, &rfds)) { ... info: opening fd ...
    (comp.unix.programmer)
  • Re: Opening fifo in write only mode
    ... I am trying to write/read a fifo using two different process. ... int main ... int main(int argc, char *argv) ... Why open call in client blocks? ...
    (comp.unix.programmer)
  • Re: open FIFO erro
    ... world" to a FIFO, and the child process read it form the FIFO,and printf it ... but when i run the test program, it open the FIFO,there some problem happen. ... You must open the fifo for reading before you attempt to write to it for writing. ... It's probably safest to open it before the fork and then close the reader ...
    (comp.os.linux.development.apps)