Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!sdd.hp.com!caen!uwm.edu!linac!att!ucbvax!SCT60A.SUNYCT.EDU!sweetmr From: sweetmr@SCT60A.SUNYCT.EDU (michael sweet) Newsgroups: comp.sys.sgi Subject: File locking problems Message-ID: <9106131834.AA08574@sct60a.sunyct.edu> Date: 13 Jun 91 18:34:00 GMT Sender: daemon@ucbvax.BERKELEY.EDU Organization: The Internet Lines: 33 In a program we're writing, we have a configuration file which needs to be locked against changes for two reasons: 1) If the information in the configuration file is changed during a run, the program will bomb. 2) If two copies of the program are run, the second copy should sense the lock placed on the config file by the first copy and exit without doing anything. Unfortunately, the lockf(2) function doesn't seem to work properly (at least the way we are doing it...) THe following is a code exerpt from the program: if (fd = open("config_file", O_RDWR, 02644) < 0) { puts("Can't open configuration file!"); exit(1); }; lseek(fd, 0L, 0); if (lockf(fd, F_TLOCK, 0L) < 0) { puts("Configuration file is already locked!"); exit(1); }; Can anyone see anything obviously wrong with the above code? We have tried running two copies simultaneously, and both seem to lock the file successfully. The configuration file has 02644 permissions.... -Mike Sweet (sweetmr@sct60a.sunyct.edu)