I am porting code from IRIX 5.3 to Solaris 2.4. The code
compiles and works fine on IRIX, but I have had some problems with flock (and now lockf) on the Solaris system.
The first problem I had was:
(1) I attempted to compile using /usr/ucb/cc the result was: cc: language optional software package not installed
In order to avoid this problem I used gcc instead. I added
"/usr/ucbinclude/" to my include paths, "/usr/ucblib" to my
library paths, and "-lucb -lsocket -lnsl" to my libraries.
(2)I created a simple test program that simply opens a file
and then uses flock() to lock it. I got everything to
compile, but when I run the executable one of two things
(a) If the file I am opening does not exist before program
execution and is created by the call to open(), i get
a valid file descriptor, and then pass it to flock.
flock() returns -1, and sets errno=22 (Invalid
arguments)--incedentally, i am using LOCK_EX
(b) If the file exists prior to execution, and is simply
opened by the call to open, then I get back a valid
file descriptor, and pass it to flock. flock() still
returns -1 and this time sets errno=9 (Bad file number)
(3)So I assumed the problem was with flock(), and attempted
to avoid the UCB libraries all together by switching all
file locking to use lockf(). Now my test program fails on
the call to lockf(), except this time I have errno=11 which
is "Resource temporarily unavailable".
It seems as if open() and flock() are referencing different
file descriptor tables. I think the problem has to do with
linking, and may be related to the fact that I am using gcc
instead of /usr/ucb/cc. Other information that may be
relevant is that the file it is attempting to open/lock is
on an NFS mounted drive (although I can't see this having
any effect on the file locking). If somebody knows the
solution to my problem I would greatly appreciate it.
Barry M. Caceres