dhorsley / za

Za scripting language
https://zalang.org
MIT License
5 stars 1 forks source link

File locking support #14

Closed dhorsley closed 2 years ago

dhorsley commented 2 years ago
* add flock() and/or pid file handling?
    - there is a syscall.Flock() already. needs file descriptor and 'how' int.
    - could probably expose this indirectly for fopen'ed files.
        - would need a few modes depending on the 'how' int states.
    - would only be linux/bsd compatible for sure. maybe a few others, not windows though.
    - pid file generation probably a bit easier, just needs some existing stuff wrapping up. 
        - there's an example for pid file setup in Za in eg/pidfile + eg/modules/pidfile.
        - ideally that stuff should be in Go in our std lib instead.
dhorsley commented 2 years ago

added a flock() lib call for testing.

dhorsley commented 2 years ago

Added LOCK_NB to flock calls. flock() now returns true if it could not perform the lock request, false if it received the lock or a halting error on other errors states, such as file not found and similar.

This is not OS-level locking and is only good for ensuring that similar Za scripts or async threads do not compete with each other for a given file resource.

dhorsley commented 2 years ago

Closing this ticket for now. The flock work is complete enough for preliminary use and the pidfile generation can be done through user scripting reasonably easily. See the eg/pidof, eg/ps and eg/pidfile examples.