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

* bug#24659: 'mkdir' procedure is neither thread-safe nor safe (2.0.12)
  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
  0 siblings, 1 reply; 3+ messages in thread
From: tomas @ 2016-10-10 18:25 UTC (permalink / raw)
  To: 24659

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Mon, Oct 10, 2016 at 06:39:47PM +0200, Ludovic Courtès wrote:
> Hello!

[...]

> 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?

According to umask(2), yes, you are right. Unless someone has been
trying to work around some platform-specific bug/idiosyncracy.

Regards
- -- t
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iEYEARECAAYFAlf73SEACgkQBcgs9XrR2kZehwCfQ+P2CMZt8doHe2tKi0u1Yc7f
RU0An0WY1oEq/b3vu/X1rNWjTP7ZxUsY
=7Jhs
-----END PGP SIGNATURE-----





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

* bug#24659: 'mkdir' procedure is neither thread-safe nor safe (2.0.12)
  2016-10-10 18:25 ` tomas
@ 2016-10-11  9:13   ` Ludovic Courtès
  0 siblings, 0 replies; 3+ messages in thread
From: Ludovic Courtès @ 2016-10-11  9:13 UTC (permalink / raw)
  To: tomas; +Cc: 24659

Hi,

<tomas@tuxteam.de> skribis:

> On Mon, Oct 10, 2016 at 06:39:47PM +0200, Ludovic Courtès wrote:
>> Hello!
>
> [...]
>
>> 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?
>
> According to umask(2), yes, you are right. Unless someone has been
> trying to work around some platform-specific bug/idiosyncracy.

I don’t think there was ever a good reason for this.

Fixed in 245608911698adb3472803856019bdd5670b6614.

Thanks for your feedback,
Ludo’.





^ 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).