Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add file locking support #185

Open
johnsonjh opened this issue Jul 21, 2023 · 1 comment
Open

Add file locking support #185

johnsonjh opened this issue Jul 21, 2023 · 1 comment
Assignees
Labels
enhancement like a new feature, just not as cool

Comments

@johnsonjh
Copy link
Collaborator

johnsonjh commented Jul 21, 2023

  • 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:

IMG_7934

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.

@johnsonjh johnsonjh added the enhancement like a new feature, just not as cool label Jul 21, 2023
@johnsonjh johnsonjh self-assigned this Jul 21, 2023
@aremmell
Copy link
Owner

aremmell commented Aug 2, 2023

If you want guidance on how to accomplish it on Windows with the native APIs, I can be of assistance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement like a new feature, just not as cool
Projects
None yet
Development

No branches or pull requests

2 participants