When we open a log file for writing, while it's being managed by libsir, obtain an exclusive advisory lock (via flock() on Linux, BSD, Mac, or via fcntl() on Solaris, AIX, illumos, or via whatever the native Windows way is). Nothing fancy, just lock the whole file. If we ever open a file only for reading, obtain a shared lock.
Some OS's support querying the process ID of whoever is holding a lock. If we fail to open a log file for writing we possibly can report who holds the lock.
We should also check for a lock before deleting any files.
We probably could (should?) be an option for users of the library to ignore locks but report on their status, as well as an option to never take out locks at all.
I did this for DPS8M (for all platforms but Windows), and it works well enough:
My implementation there is over-complicated - it uses three approaches - dotfiles, flock, and fcntl. It also passes status of who holds the lock via the dotfile in case of conflicts over network shares. We don't need anything that complicated here.
I did this for DPS8M (for all platforms but Windows), and it works well enough:
My implementation there is over-complicated - it uses three approaches - dotfiles, flock, and fcntl. It also passes status of who holds the lock via the dotfile in case of conflicts over network shares. We don't need anything that complicated here.