lkml.org 
[lkml]   [1996]   [Oct]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
Subjectflock weirdness
I got some strange results when toying with flock() the other day:
(included is a small program)

#include <stdio.h>
#include <sys/file.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>

main() {
int fd, err;

fd = open("test", O_RDONLY);
if(fd > 0) {
do {
errno = 0;
err = flock(fd, LOCK_EX|LOCK_NB);
if(err == -1)
fprintf(stderr, "errno=%d(%s)\n", errno, strerror(errno));
sleep(2);
} while(errno != 0);
}
}

I first lock the file (test) with 1 process. Then run this program.
errno=2(Try again)
errno=11(Try again)
errno=11(Try again)
errno=11(Try again)

Why is errno 2 (ENOENT) the first time ? even tho strerror gives the correct
results. According to the man pages the only error it can return is
EWOULDBLOCK (EAGAIN).

Just wondering.

regards, Harald

\
 
 \ /
  Last update: 2005-03-22 13:38    [W:0.027 / U:0.464 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site