martelli@cadlab.sublink.ORG (Alex Martelli) (06/13/91)
I apologize in advance if this is (as I hope...:-) an extremely simple question with an instant answer... but please give me said answer anyway! I have an application program, which multiple processes on the same or different nodes will be executing, and which often needs to have one of several possible files open for reading, and occasionally for writing; my task is to protect the file against simultaneous writing of overlapping pieces, or writing of a region which is being read. I.e., locking (the advisory kind, between cooperating applications). The file can reside on the same node, elsewhere on a Domain Ring, or elsewhere mounted via NFS (this latter requirement is not mandatory, but it sure would be nice, to help the Apollo version of the app to interoperate with its Unix versions running on other kinds of boxes...). On all Unix machines this app has been ported to, I have a very simple mechanism: the file is opened, for reading or writing as needed, then a region of it is locked appropriately via a fcntl() system call; lockd and statd (a.k.a. rpc.lockd and rpc.statd) daemons help this work even on remotely-mounted, NFS files. Domain/OS manuals document the same interface, but I can't get it to work! When I open() a file for writing, and some other process has it open()ed already, the open() fails with errno set to 'ETXTBUSY', which according to the docs should ONLY happen when the file is an executable image being executed... SO, *how* can I get a fd open for writing, to lock the region I am interested in? I dabbled into the "Domain/OS Call Reference", and ios_$ routines appear to be documented as to allow that (with 'open unregulated' option), but my attempts to do this have failed. The compiler I'm using is CC 6.8, assuming this matters. Thanks in advance for any help (a code sample would be most appreciated!). -- Alex Martelli - CAD.LAB s.p.a., v. Stalingrado 53, Bologna, Italia Email: (work:) martelli@cadlab.sublink.org, (home:) alex@am.sublink.org Phone: (work:) ++39 (51) 371099, (home:) ++39 (51) 250434; Fax: ++39 (51) 366964 (work only), Fidonet: 332/407.314 (home only).