Discussion:
mkfifo: unix command vs C library
(too old to reply)
m***@yahoo.com
2006-08-22 23:40:50 UTC
Permalink
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.
Bela Lubkin
2006-08-23 15:38:10 UTC
Permalink
Post by m***@yahoo.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.
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?
Post by m***@yahoo.com
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.
Post by m***@yahoo.com
Bela<
Bob Bailin
2006-08-23 16:08:11 UTC
Permalink
Post by m***@yahoo.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.
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
m***@yahoo.com
2006-08-23 18:15:21 UTC
Permalink
Post by Bob Bailin
Post by m***@yahoo.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.
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?
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.

Loading...