I ran into an issue yesterday with locking on Solaris and crontab editing that has me wondering what the best way to protect multiple concurrent edits of the same crontab are on Solaris. I've confirmed that the behaviour exists in Solaris through 11.2.10.5.0.
EDITOR=vi
OS=Solaris 10, 11
SHELL=bash
RBAC=pfexec
Now normally, vi uses .filename.swp files to prevent multiple concurrent edits of the same file, whether that be from multiple users or multiple invocations from the same user. However, "crontab -e" creates and passes a temp file with a name based on /tmp/crontabXXXXXX to $EDITOR, and multiple concurrent invocations of "crontab -e" will pass different temp files to $EDITOR, potentially allowing reversion of changes to the crontab when it is opened from two places at once, or when a suspended vi session gets killed due to the TTY timing out, as happened to me. There is additionally no warning from the $EDITOR on the second invocation of "crontab -e" as the file being edited is different.
How can I prevent this issue occurring? The use of a pseudo-random temp file name prevents the inbuilt locking in vi from working, so addressing that would seem to be the optimal route. Perhaps the issue is more fundamental and needs to be raised as an OS bug. The Solaris crontab man page doesn't leave much hope as it states "Simultaneous modifications of the same crontab file may lead to unexpected results.", but I am hoping that someone has an answer.