mkfifo: unix command vs C library - SCO

This is a discussion on mkfifo: unix command vs C library - SCO ; When I create FIFO typing $ mkfifo -m 0666 fifo.tmp or in my program use system call (which is the same) my program that uses FIFO is working just fine. But when I code FIFO creation using C library call ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: mkfifo: unix command vs C library

  1. mkfifo: unix command vs C library

    When I create FIFO typing

    $ mkfifo -m 0666 fifo.tmp

    or in my program use system call (which is the same)
    my program that uses FIFO is working just fine.

    But when I code FIFO creation using C library call
    if(mkfifo(FIFO, 0666) < 0)
    {
    perror("MKFIFO Error");
    exit(1);
    }
    the resulting FIFO's behavoir is strange.
    Every time I open it for read its i-node is changing and nothing works.

    I am puzzled by this i-node change.

    Here is open for read part of my code:

    if((fd = open(FIFO, O_RDONLY|O_NONBLOCK)) < 0)
    {
    perror("OPEN Error");
    return(-1);
    }
    if((val = fcntl(fd, F_GETFL, 0)) == -1)
    return(-1);
    val &= ~O_NONBLOCK;
    if(fcntl(fd, F_SETFL, val) == -1)
    return(-1);

    I can live with system call, but would really want to know what is the
    reason for C library to behave so strange.
    Tested on OSR507, SCO UNIX Development System Release 5.2.0A
    What do I miss?
    Any pointers would be appreciated.


  2. Re: mkfifo: unix command vs C library

    migurus@yahoo.com wrote:

    > When I create FIFO typing
    >
    > $ mkfifo -m 0666 fifo.tmp
    >
    > or in my program use system call (which is the same)
    > my program that uses FIFO is working just fine.
    >
    > But when I code FIFO creation using C library call
    > if(mkfifo(FIFO, 0666) < 0)
    > {
    > perror("MKFIFO Error");
    > exit(1);
    > }
    > the resulting FIFO's behavoir is strange.
    > Every time I open it for read its i-node is changing and nothing works.
    >
    > I am puzzled by this i-node change.
    >
    > Here is open for read part of my code:
    >
    > if((fd = open(FIFO, O_RDONLY|O_NONBLOCK)) < 0)
    > {
    > perror("OPEN Error");
    > return(-1);
    > }
    > if((val = fcntl(fd, F_GETFL, 0)) == -1)
    > return(-1);
    > val &= ~O_NONBLOCK;
    > if(fcntl(fd, F_SETFL, val) == -1)
    > return(-1);
    >
    > I can live with system call, but would really want to know what is the
    > reason for C library to behave so strange.
    > Tested on OSR507, SCO UNIX Development System Release 5.2.0A


    Your question is mostly well-formed, except I can't understand what you
    mean by "the resulting FIFO's behavoir is strange. Every time I open it
    for read its i-node is changing and nothing works."! What do you mean
    the inode is changing -- do you do fstat() on the fd returned from
    open(), and the value of the st_ino field changes?

    > What do I miss?
    > Any pointers would be appreciated.


    What's missing is a complete program that demonstrates the problem. It
    sounds like a 10-line program would do. Post source for a whole
    compilable program, show the output it produces for you, and point out
    which output seems wrong and what you think it should have looked like
    if it worked right.

    I wrote the simple program:

    main() { mkfifo("foo", 0666); }

    Running this multiple times, the inode for "foo" does not change.
    `truss mkfoo` shows that the system call is returning EEXIST, as I would
    expect. Notice that my test program has no error checking or anything
    -- for this sort of debugging, this eliminates many possible sources of
    confusion. `truss` shows me what it's doing adequately without bulking
    up the test source.

    >Bela<


  3. Re: mkfifo: unix command vs C library


    wrote in message
    news:1156290050.870903.45540@b28g2000cwb.googlegro ups.com...
    > When I create FIFO typing
    >
    > $ mkfifo -m 0666 fifo.tmp
    >
    > or in my program use system call (which is the same)
    > my program that uses FIFO is working just fine.
    >
    > But when I code FIFO creation using C library call
    > if(mkfifo(FIFO, 0666) < 0)
    > {
    > perror("MKFIFO Error");
    > exit(1);
    > }
    > the resulting FIFO's behavoir is strange.
    > Every time I open it for read its i-node is changing and nothing works.
    >
    > I am puzzled by this i-node change.
    >
    > Here is open for read part of my code:
    >
    > if((fd = open(FIFO, O_RDONLY|O_NONBLOCK)) < 0)
    > {
    > perror("OPEN Error");
    > return(-1);
    > }
    > if((val = fcntl(fd, F_GETFL, 0)) == -1)
    > return(-1);
    > val &= ~O_NONBLOCK;
    > if(fcntl(fd, F_SETFL, val) == -1)
    > return(-1);
    >
    > I can live with system call, but would really want to know what is the
    > reason for C library to behave so strange.
    > Tested on OSR507, SCO UNIX Development System Release 5.2.0A
    > What do I miss?
    > Any pointers would be appreciated.
    >


    What is FIFO set to in your mkfifo call?
    Are the results exactly the same when you:
    ls -l fifo.tmp
    and
    ls -l {whatever FIFO is set to}
    ?

    Do you have the same problem if you use mknod instead of mkfifo?

    Bob



  4. Re: mkfifo: unix command vs C library


    Bob Bailin wrote:
    > wrote in message
    > news:1156290050.870903.45540@b28g2000cwb.googlegro ups.com...
    > > When I create FIFO typing
    > >
    > > $ mkfifo -m 0666 fifo.tmp
    > >
    > > or in my program use system call (which is the same)
    > > my program that uses FIFO is working just fine.
    > >
    > > But when I code FIFO creation using C library call
    > > if(mkfifo(FIFO, 0666) < 0)
    > > {
    > > perror("MKFIFO Error");
    > > exit(1);
    > > }
    > > the resulting FIFO's behavoir is strange.
    > > Every time I open it for read its i-node is changing and nothing works.
    > >
    > > I am puzzled by this i-node change.
    > >
    > > Here is open for read part of my code:
    > >
    > > if((fd = open(FIFO, O_RDONLY|O_NONBLOCK)) < 0)
    > > {
    > > perror("OPEN Error");
    > > return(-1);
    > > }
    > > if((val = fcntl(fd, F_GETFL, 0)) == -1)
    > > return(-1);
    > > val &= ~O_NONBLOCK;
    > > if(fcntl(fd, F_SETFL, val) == -1)
    > > return(-1);
    > >
    > > I can live with system call, but would really want to know what is the
    > > reason for C library to behave so strange.
    > > Tested on OSR507, SCO UNIX Development System Release 5.2.0A
    > > What do I miss?
    > > Any pointers would be appreciated.
    > >

    >
    > What is FIFO set to in your mkfifo call?
    > Are the results exactly the same when you:
    > ls -l fifo.tmp
    > and
    > ls -l {whatever FIFO is set to}
    > ?
    >
    > Do you have the same problem if you use mknod instead of mkfifo?
    >
    > Bob


    Thanks to all who replied.
    I found a bad typo in my code that made the program to re-create fifo
    when it should not. Sorry for not checking my code thoroughly before
    posting, my bad.


+ Reply to Thread