fcntl "F_SETLKW" value mismatch / linux header bug?

P

Pioneer

I have found a problem in Perl 5.8.4 on Debian Linux where F_SETLKW is
showing up with value "14" when the kernel is expecting value "7".
Details below:

I have been struggling with getting fcntl locking working for 3 days.
Specifically with using fcntl to do exclusive byte range locking on a
file in Perl/Linux.

I had it working, however it seemed no matter what range I locked, the
entire file locked and I could not figure out why. Every piece of
example code or module I could find caused the same problem.

Finally I wrote test code in C that worked fine. I then started
comparing the values of all of the defined variables in C and perl.
This is what I found:


PERL v5.8.4:

F_WRLCK: 1
SEEK_SET: 0
F_SETLKW: 14

C:

F_WRLCK: 1
SEEK_SET: 0
F_SETLKW: 7


I forced F_SETLKW in Perl to be 7 and everything worked as it should.

I understand that the flock structures change from machine to machine,
etc. but I saw no comments anywhere on the web saying you had to make
sure these values were also proper. Is this due to installing a
predefined Debian package rather than compiling Perl from scratch, a
bug in the Perl install itself, me importing FCNTL data incorrectly, or
should I just not have expected this value to be correct?

(Details/Sample code shown below)

Thanks,
-John



Details: Debian, Sarge Distribution, Stable, Perl v5.8.4, Linux
Kernels, same issue on both v2.6.13 and v2.4.26

Code:

#!/usr/bin/perl

use Fcntl;
use POSIX qw:)unistd_h :errno_h);
use Fcntl qw:)DEFAULT :flock);

use strict;

print "F_SETLKW: ".F_SETLKW."\n";


I also tried removing different use statements above, all the same
results.
 
A

A. Sinan Unur

I have found a problem in Perl 5.8.4 on Debian Linux where F_SETLKW is
showing up with value "14" when the kernel is expecting value "7".
Details below:
....

This is what I found:


PERL v5.8.4:

F_WRLCK: 1
SEEK_SET: 0
F_SETLKW: 14

C:

F_WRLCK: 1
SEEK_SET: 0
F_SETLKW: 7
....

I understand that the flock structures change from machine to machine,
etc. but I saw no comments anywhere on the web saying you had to make
sure these values were also proper. Is this due to installing a
predefined Debian package rather than compiling Perl from scratch, a
bug in the Perl install itself, me importing FCNTL data incorrectly,
or should I just not have expected this value to be correct?

The value should be correct.

The build process picks these values up from the system. So, if the
binary is built on a system that has different values, then a mismatch
might occur. I am saying "might" because I do not know how the debian
package installation procedure actually works.

By the way, F_SETLKW seems to come from the POSIX module.

I would try building the latest Perl from source and install in a
different directory than the system-wide Perl (say ~/perl) to test if
the debian package build has a problem.

Sinan
 
P

Pioneer

Yes, this was my best guess as well -- that the Debian package is
prebuilt on another system with a different value for F_SETLKW -- it is
definitely incorrect.

The next question is, is there some code I can write to dynamically
pull those values from the headers on the system I am on?... IE: Is
there some code tricks I can use to pull the values of these constants
upon loading up of the file to make it more likely the code will work
on another system?

I will try to the Perl install from scratch when I get a chance -- I am
guessing that if I compile it, it should solve the problem.

It would seem that this problem should be reported somewhere so people
know about it -- but I am not sure where?... any suggestions?
 
A

A. Sinan Unur


Please quote an appropriate amount of context. Most people do
not use Google groups, and there is no guarantee that your reply
will reach all newsservers after my post.


If you want to post a followup via groups.google.com,
don't use the broken "Reply" link at the bottom of the
article. Click on "show options" at the top of the
article, then click on the "Reply" at the bottom of
the article headers.

For more information,

http://groups.google.com/groups?q=broken+google+reply+group:comp.lang.perl.misc&qt_s=Search
this was my best guess as well -- that the Debian package is
prebuilt on another system with a different value for F_SETLKW -- it
is definitely incorrect.

The next question is, is there some code I can write to dynamically
pull those values from the headers on the system I am on?... IE: Is
there some code tricks I can use to pull the values of these constants
upon loading up of the file to make it more likely the code will work
on another system?

Dynamically, I am not so sure. But, you can try running h2xs on the
relevant C header file to create a module for your system.
It would seem that this problem should be reported somewhere so people
know about it -- but I am not sure where?... any suggestions?

I would file a bug report with debian. I searched their bug database,
but could not find anything.

Sinan
 
J

John W. Krahn

Pioneer said:
I have found a problem in Perl 5.8.4 on Debian Linux where F_SETLKW is
showing up with value "14" when the kernel is expecting value "7".
Details below:

I have been struggling with getting fcntl locking working for 3 days.
Specifically with using fcntl to do exclusive byte range locking on a
file in Perl/Linux.

I had it working, however it seemed no matter what range I locked, the
entire file locked and I could not figure out why. Every piece of
example code or module I could find caused the same problem.

Finally I wrote test code in C that worked fine. I then started
comparing the values of all of the defined variables in C and perl.
This is what I found:


PERL v5.8.4:

F_WRLCK: 1
SEEK_SET: 0
F_SETLKW: 14

C:

F_WRLCK: 1
SEEK_SET: 0
F_SETLKW: 7


I forced F_SETLKW in Perl to be 7 and everything worked as it should.

I understand that the flock structures change from machine to machine,
etc. but I saw no comments anywhere on the web saying you had to make
sure these values were also proper. Is this due to installing a
predefined Debian package rather than compiling Perl from scratch, a
bug in the Perl install itself, me importing FCNTL data incorrectly, or
should I just not have expected this value to be correct?

It looks like this may be a bug in how perl parses header files. My
/usr/include/asm/fcntl.h lists these constants:

#define F_DUPFD 0 /* dup */
#define F_GETFD 1 /* get close_on_exec */
#define F_SETFD 2 /* set/clear close_on_exec */
#define F_GETFL 3 /* get file->f_flags */
#define F_SETFL 4 /* set file->f_flags */
#define F_GETLK 5
#define F_SETLK 6
#define F_SETLKW 7

#define F_SETOWN 8 /* for sockets. */
#define F_GETOWN 9 /* for sockets. */
#define F_SETSIG 10 /* for sockets. */
#define F_GETSIG 11 /* for sockets. */

#define F_GETLK64 12 /* using 'struct flock64' */
#define F_SETLK64 13
#define F_SETLKW64 14


But perl defines them as:

$ perl -le'use Fcntl; print for F_DUPFD, F_GETFD, F_SETFD, F_GETFL, F_SETFL,
F_GETLK, F_SETLK, F_SETLKW, F_SETOWN, F_GETOWN, F_SETSIG, F_GETSIG, F_GETLK64,
F_SETLK64, F_SETLKW64'
0
1
2
3
4
12
13
14
8
9
F_SETSIG
F_GETSIG
12
13
14


So it looks like F_SETLKW is getting the value of F_SETLKW64.




John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top