Hi,
The user's umask can be set with the umask(2) system call, this sets the
new umask and returns the old one. As far as I can tell, the canonical way
to get the user's current umask is to call umask twice: once to get the old
value and set a temporary one, then a second call to restore the old value:
func getUmask() int {
umask := syscall.Umask(0)
syscall.Umask(umask)
return umask
}
This has an obvious race condition: if some file operations (e.g. mkdir or
open) occur between the two calls to syscall.Umask then they will use the
unwanted temporary umask value.
How can I avoid this race condition?
One heavyweight possibility is to read the umask during the main package's
init, including a call to runtime.LockOSThread(). However, I'd like to be
able to call my getUmask() function at any time.
Many thanks for any pointers,
Tom
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.