(and, of course, O_CREATE and everything. sorry for sending multiple messages ^^)
On Tue, Nov 6, 2018 at 4:43 PM Axel Wagner <axel.wagner...@googlemail.com> wrote: > Oh, come to think of it, there's a way: Use os.OpenFile with mode=0777 and > then stat the file? Should work, no? > > On Tue, Nov 6, 2018 at 4:41 PM Axel Wagner <axel.wagner...@googlemail.com> > wrote: > >> That seems to be fundamentally impossible on posix using only syscalls, >> but you may be able to use /proc: >> https://manpages.debian.org/stretch/manpages-dev/umask.2.en.html#NOTES >> >> >> On Tue, Nov 6, 2018 at 4:35 PM Tom Payne <twpa...@gmail.com> wrote: >> >>> 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 golang-nuts+unsubscr...@googlegroups.com. >>> For more options, visit https://groups.google.com/d/optout. >>> >> -- 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 golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.