unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
From: ludo@gnu.org (Ludovic Courtès)
To: 24659@debbugs.gnu.org
Subject: bug#24659: 'mkdir' procedure is neither thread-safe nor safe (2.0.12)
Date: Mon, 10 Oct 2016 18:39:47 +0200	[thread overview]
Message-ID: <87pon8ma3w.fsf@gnu.org> (raw)

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.





             reply	other threads:[~2016-10-10 16:39 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-10 16:39 Ludovic Courtès [this message]
2016-10-10 18:25 ` bug#24659: 'mkdir' procedure is neither thread-safe nor safe (2.0.12) tomas
2016-10-11  9:13   ` Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87pon8ma3w.fsf@gnu.org \
    --to=ludo@gnu.org \
    --cc=24659@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).