56.4. File Locking

Webmin version 0.81 introduced several new common functions for locking files to prevent multiple programs from writing to them at the same time. Module programmers should make use of these functions to prevent the corruption or overwriting of configuration files in cases where two users are using the same module at the same time.

Locking is done by the lock_file function, which takes the name of a file as a parameter and obtains an exclusive lock on that file by creating a file with the same name but with .lock appended. The unlock_file function also removes the lock on the file given as a parameter. Because the .lock file stores the PID of the process that locked the file, any locks a CGI program holds will be automatically ...

Get Managing Linux® Systems with Webmin™ System Administration and Module Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.