File locking problems

Paul Jackson pj at sam.wpd.sgi.com
Fri Jun 14 09:32:13 AEST 1991


In article <9106131834.AA08574 at sct60a.sunyct.edu>, sweetmr at SCT60A.SUNYCT.EDU (michael
sweet) writes:
|> ... lockf(2) function doesn't seem to work properly
|>   if (fd = open("config_file", O_RDWR, 02644) < 0)
|>     ....
|>   if (lockf(fd, F_TLOCK, 0L) < 0)

Change the open line to have parentheses around (fd = open(...)).
Your current code sets fd to be the result of the boolean (open(...) < 0),
which if the open succeeds is false.  So fd is 0 (for false) and lockf(0,...)
succeeds.
-- 

				I won't rest till it's the best ...
				Software Production Engineer
				Paul Jackson (pj at wpd.sgi.com), x1373



More information about the Comp.sys.sgi mailing list