From: Mike Frysinger <vapier@gentoo.org>
To: gentoo-portage-dev@lists.gentoo.org
Cc: Ryan Hill <dirtyepic@gentoo.org>
Subject: Re: [gentoo-portage-dev] Re: [PATCH] econf: update configure/config.{sub,guess} atomically to avoid races
Date: Sat, 21 Dec 2013 04:23:44 -0500 [thread overview]
Message-ID: <201312210423.44994.vapier@gentoo.org> (raw)
In-Reply-To: <20131220210717.143e9f02@caribou.gateway.pace.com>
[-- Attachment #1: Type: Text/Plain, Size: 1120 bytes --]
On Friday 20 December 2013 22:07:17 Ryan Hill wrote:
> On Tue, 17 Dec 2013 18:28:12 -0500 Mike Frysinger wrote:
> > Use $BASHPID which will be unique even in subshells.
>
> This requires bash 4.0. I'm all for it, but haters gonna hate.
ugh. fun fact: this is used in multiple places in portage already, as well as
some eclasses.
it can be re-implemented with:
read -r pid _ < /proc/self/stat; echo $pid
but that doesn't work in a subshell, so you couldn't do:
bashpid() { local pid; read -r pid _ < /proc/self/stat; echo $pid; }
echo ${BASHPID:-$(bashpid)}
because now you'd be a sub-subshell. in this case you want the parent pid,
but that isn't easy to get as the 2nd field of stat is the process name, and
i'm not sure that won't have spaces (since it might be the name of the shell
script). plus it isn't terribly portable.
this seems reasonable portable though:
bashpid() { sh -c 'echo $PPID'; }
echo ${BASHPID:-$(bashpid)}
even if it does have the overhead of running another bash process. but
considering this only impacts bash-3.2, maybe we simply don't care.
-mike
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
next prev parent reply other threads:[~2013-12-21 9:23 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-17 23:23 [gentoo-portage-dev] [PATCH] econf: update config.{sub,guess} atomically to avoid races Mike Frysinger
2013-12-17 23:28 ` [gentoo-portage-dev] [PATCH] econf: update configure/config.{sub,guess} " Mike Frysinger
2013-12-18 0:26 ` Brian Dolbec
2013-12-18 1:08 ` Alec Warner
2013-12-18 1:41 ` Greg Turner
2013-12-18 1:58 ` Alec Warner
2013-12-18 2:53 ` Greg Turner
2013-12-18 5:16 ` Alec Warner
2013-12-21 3:07 ` [gentoo-portage-dev] " Ryan Hill
2013-12-21 9:23 ` Mike Frysinger [this message]
2013-12-21 9:49 ` [gentoo-portage-dev] [PATCH] add a __bashpid helper for <bash-4.0 versions Mike Frysinger
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=201312210423.44994.vapier@gentoo.org \
--to=vapier@gentoo.org \
--cc=dirtyepic@gentoo.org \
--cc=gentoo-portage-dev@lists.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