* fcntl() bug? if called second times!
@ 2003-01-13 17:48 Heiko Elger
2003-01-13 18:48 ` Pavel Tsekov
0 siblings, 1 reply; 2+ messages in thread
From: Heiko Elger @ 2003-01-13 17:48 UTC (permalink / raw)
To: cygwin; +Cc: ente59
Hello,
I try to comiple an run the distcc package - but I get errors while running.
I figured out, tha the problems are the fcntl() calls - perhaps
ther is a bug in cygwin?
The following code runs differently in cygwin and linux.
If I want ro lock the whole file twice, but still the same process, I will
get an "permission denied" error on cygwin.
The same code works on linux!
===> Cygwin console
heiko@HEIKO ~/src/fslock
$ ./fslocktest
Lock 1
Lock 2
lock failed: fslocktest.txt: Permission denied
===> linux console
heiko@linux:~/src/fslock> ./fslocktest
Lock 1
Lock 2
Below is the code to reproduce the error.
I'm using the following software:
- Windows XP Professional Ver 5.1 Build 2600 Service Pack 1
CYGWIN=ntsec
- Cygwin DLL version info:
DLL version: 1.3.18
DLL epoch: 19
DLL bad signal mask: 19005
DLL old termios: 5
DLL malloc env: 28
API major: 0
API minor: 69
Shared data: 3
DLL identifier: cygwin1
Mount registry: 2
Cygnus registry name: Cygnus Solutions
Cygwin registry name: Cygwin
Program options name: Program Options
Cygwin mount registry name: mounts v2
Cygdrive flags: cygdrive flags
Cygdrive prefix: cygdrive prefix
Cygdrive default prefix:
Build date: Wed Dec 25 15:37:50 EST 2002
Shared id: cygwin1S3
- Linux: Suse 8.1
Perhaps someone can give me a hint ...
Best regards
Heiko Elger
------------ snip - snip - snip --------------------
/*
make CFLAGS="-Wall -g -O0" testfcntl.c
*/
int main(int argc, char** argv, char** envp)
{
int fd ;
char* fname = "fslocktest.txt";
int rc;
struct flock lockparam;
lockparam.l_type = F_WRLCK;
lockparam.l_whence = SEEK_SET;
lockparam.l_start = 0;
lockparam.l_len = 0; /* whole file */
fd = open(fname, O_WRONLY|O_CREAT, 0600);
if (fd == -1 && errno != EEXIST)
{
printf("failed to creat %s: %s", fname, strerror(errno));
return errno;
}
printf("Lock 1\n");
rc = fcntl(fd, F_SETLK, &lockparam);
if (rc==-1)
{
printf("lock failed: %s: %s", fname, strerror(errno));
return errno;
}
printf("Lock 2\n");
rc = fcntl(fd, F_SETLK, &lockparam);
if (rc==-1)
{
printf("lock failed: %s: %s", fname, strerror(errno));
return errno;
}
close(fd);
return 0;
}
------------ snip - snip - snip --------------------
Heiko Elger
,,,
(o o)
+------------------------oOO--(_)--OOo----------------------------+
| |
| Email: heiko.elger.spam@gmx.de |
| |
| bitte .spam in der Email-Adresse entfernen |
| please remove .spam |
| |
| .oo0O O0oo. |
| ( ) ( ) |
+-------------------------\ (-----) /-----------------------------+
\_) (_/
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: fcntl() bug? if called second times!
2003-01-13 17:48 fcntl() bug? if called second times! Heiko Elger
@ 2003-01-13 18:48 ` Pavel Tsekov
0 siblings, 0 replies; 2+ messages in thread
From: Pavel Tsekov @ 2003-01-13 18:48 UTC (permalink / raw)
To: Heiko Elger; +Cc: cygwin, ente59
Hello,
Cygwin doesn't support advisory file locking. It implements file locking
via the Win32 api LockFile*. Find out more here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/lockfile.asp
And more specifically this part:
[...]
Locking a portion of a file for shared access denies all processes write
access to the specified region of the file, including the process that
first locks the region. All processes can read the locked region.
[...]
In fact I think the Win32 error code returned in this case is
ERROR_LOCK_VIOLATION and Cygwin translates it to EACCESS.
Some time before I started porting sendmail to Cygwin and met this
problem. I decided to try to implement something like advisory file
locking for Cygwin back then but lack of time prevented me from doing so
:(
On Mon, 13 Jan 2003, Heiko Elger wrote:
> Hello,
>
> I try to comiple an run the distcc package - but I get errors while running.
> I figured out, tha the problems are the fcntl() calls - perhaps
> ther is a bug in cygwin?
> The following code runs differently in cygwin and linux.
> If I want ro lock the whole file twice, but still the same process, I will
> get an "permission denied" error on cygwin.
> The same code works on linux!
>
> ===> Cygwin console
> heiko@HEIKO ~/src/fslock
> $ ./fslocktest
> Lock 1
> Lock 2
> lock failed: fslocktest.txt: Permission denied
>
> ===> linux console
> heiko@linux:~/src/fslock> ./fslocktest
> Lock 1
> Lock 2
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2003-01-13 17:48 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-01-13 17:48 fcntl() bug? if called second times! Heiko Elger
2003-01-13 18:48 ` Pavel Tsekov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).