unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
* bug#24659: 'mkdir' procedure is neither thread-safe nor safe (2.0.12)
@ 2016-10-10 16:39 Ludovic Courtès
  2016-10-10 18:25 ` tomas
  0 siblings, 1 reply; 3+ messages in thread
From: Ludovic Courtès @ 2016-10-10 16:39 UTC (permalink / raw)
  To: 24659

Hello!

When the optional ‘mode’ argument to the ‘mkdir’ procedure is omitted,
umask(2) is used to find out what the current mask is and to compute the
mode argument to mkdir(2):

--8<---------------cut here---------------start------------->8---
  if (SCM_UNBNDP (mode))
    {
      mask = umask (0);
      umask (mask);
      STRING_SYSCALL (path, c_path, rv = mkdir (c_path, 0777 ^ mask));
    }
--8<---------------cut here---------------end--------------->8---

The problem is that this changes the process’ umask globally for a short
duration, during which other threads will get 0 as the mask…

Furthermore, AFAICS, the above logic is redundant with what the kernel
does anyway.  That is, in a single-threaded program,

  mask = umask (0);
  umask (mask);
  mkdir (file, 0777 ^ mask);

is equivalent to:

  mkdir (file, 0777);

Am I right that we should just remove these two ‘umask’ calls?

Ludo’.

PS: This code has been there since 1996 or earlier.





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-10-11  9:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-10 16:39 bug#24659: 'mkdir' procedure is neither thread-safe nor safe (2.0.12) Ludovic Courtès
2016-10-10 18:25 ` tomas
2016-10-11  9:13   ` Ludovic Courtès

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).