Util-Linux package development
 help / color / mirror / Atom feed
From: Peter Cordes <peter@cordes.ca>
To: Karel Zak <kzak@redhat.com>
Cc: "Isaac Dunham" <ibid.ag@gmail.com>,
	"Pádraig Brady" <P@draigBrady.com>,
	"Mike Frysinger" <vapier@gentoo.org>,
	util-linux@vger.kernel.org
Subject: Re: [PATCH] build-sys: fix parallel builds w/setarch links
Date: Sat, 16 May 2015 14:50:38 -0300	[thread overview]
Message-ID: <20150516175038.GG3933@cordes.ca> (raw)
In-Reply-To: <20150511080528.GK27969@ws.net.home>

On Mon, May 11, 2015 at 10:05:28AM +0200, Karel Zak wrote:
> On Sun, May 10, 2015 at 01:38:08PM -0700, Isaac Dunham wrote:
> > On Tue, May 05, 2015 at 11:37:33AM +0100, Pádraig Brady wrote:
> > > On 04/05/15 04:51, Mike Frysinger wrote:
> > > > From: Mike Frysinger <vapier@chromium.org>
> > > > 
> > > > The symlink generation tries to write to the sys-utils/ subdir but does
> > > > not make sure that dir exists.  This can sometimes lead to parallel build
> > > > failures when building out-of-tree
> > > 
> > > >  $(SETARCH_MAN_LINKS):
> > > > +	$(AM_V_at) test -d $(dir $@) || mkdir -p $(dir $@)
> > > >  	$(AM_V_GEN)echo ".so man8/setarch.8" > $@
> > > >  
> > > >  install-exec-hook-setarch:
> > > 
> > > The `test -d ... ||` bit is racy and redundant I think
> > 
> > Racy, yes, but no more so than "mkdir -p $DIR && install $FILE $DIR":
> > it's an inherent limitation of shell scripts.

 You mean racy as in multiple mkdir -p invocations could happen?  A C
implementation could shorten the window for the race (because mkdir(2)
would directly follow stat(2), rather than delayed by
fork/exec/dynamic linker startup).  Or handle EEXISTS specially and
test again for existance.  You could do most of that in shell, but it
would make the code a mess.

> > Redundant, certainly: mkdir -p $DIR is required to succeed if $DIR is
> > a preexisting directory (though it will fail if part of the path is a
> > regular file).
>
>  It seems that 'test || mkdir' is nothing unusual in makefiles. The
>  problem is "mkdir -p" portability (at least from autotools point of
>  view :-), it seems that the proper way is to use 
> 
>     @$(MKDIR_P) $(dir $@)
> 
>  rather than directly call mkdir.


 The test || mkdir idiom also has a performance benefit: test is a
shell builtin in most/all shells.  stat(2) is a lot faster than
fork / exec / process startup.  (For portable build systems, this is a
huge deal on cygwin compared to anything else, because the overhead
of running a binary is huge there.)

 Anyway, if checking for existence is going to happen often, then it's
worth doing test || mkdir, rather than relying on GNU mkdir -p.

-- 
#define X(x,y) x##y
Peter Cordes ;  e-mail: X(peter@cor , des.ca)

"The gods confound the man who first found out how to distinguish the hours!
 Confound him, too, who in this place set up a sundial, to cut and hack
 my day so wretchedly into small pieces!" -- Plautus, 200 BC

  reply	other threads:[~2015-05-16 17:50 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-04  3:51 [PATCH] build-sys: fix parallel builds w/setarch links Mike Frysinger
2015-05-05 10:37 ` Pádraig Brady
2015-05-10 15:28   ` Mike Frysinger
2015-05-10 17:20     ` Bruce Dubbs
2015-05-10 20:38   ` Isaac Dunham
2015-05-11  8:05     ` Karel Zak
2015-05-16 17:50       ` Peter Cordes [this message]
2015-05-17  5:53         ` Mike Frysinger
2015-05-05 10:47 ` Karel Zak

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

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

  git send-email \
    --in-reply-to=20150516175038.GG3933@cordes.ca \
    --to=peter@cordes.ca \
    --cc=P@draigBrady.com \
    --cc=ibid.ag@gmail.com \
    --cc=kzak@redhat.com \
    --cc=util-linux@vger.kernel.org \
    --cc=vapier@gentoo.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