* [gentoo-portage-dev] [PATCH] econf: update config.{sub,guess} atomically to avoid races
@ 2013-12-17 23:23 Mike Frysinger
2013-12-17 23:28 ` [gentoo-portage-dev] [PATCH] econf: update configure/config.{sub,guess} " Mike Frysinger
0 siblings, 1 reply; 11+ messages in thread
From: Mike Frysinger @ 2013-12-17 23:23 UTC (permalink / raw
To: gentoo-portage-dev
URL: https://bugs.gentoo.org/487478
---
bin/phase-helpers.sh | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/bin/phase-helpers.sh b/bin/phase-helpers.sh
index ec48c94..59c053a 100644
--- a/bin/phase-helpers.sh
+++ b/bin/phase-helpers.sh
@@ -512,7 +512,9 @@ econf() {
-name config.guess -o -name config.sub ')' -print0 | \
while read -r -d $'\0' x ; do
__vecho " * econf: updating ${x/${WORKDIR}\/} with ${EPREFIX}/usr/share/gnuconfig/${x##*/}"
- cp -f "${EPREFIX}"/usr/share/gnuconfig/"${x##*/}" "${x}"
+ # Make sure we do this atomically incase we're run in parallel. #487478
+ cp -f "${EPREFIX}"/usr/share/gnuconfig/"${x##*/}" "${x}.$$"
+ mv -f "${x}.$$" "${x}"
done
fi
--
1.8.4.3
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [gentoo-portage-dev] [PATCH] econf: update configure/config.{sub,guess} atomically to avoid races
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 ` Mike Frysinger
2013-12-18 0:26 ` Brian Dolbec
` (2 more replies)
0 siblings, 3 replies; 11+ messages in thread
From: Mike Frysinger @ 2013-12-17 23:28 UTC (permalink / raw
To: gentoo-portage-dev
Use $BASHPID which will be unique even in subshells.
URL: https://bugs.gentoo.org/487478
---
bin/phase-helpers.sh | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/bin/phase-helpers.sh b/bin/phase-helpers.sh
index ec48c94..1a7ae03 100644
--- a/bin/phase-helpers.sh
+++ b/bin/phase-helpers.sh
@@ -469,6 +469,7 @@ unpack() {
econf() {
local x
+ local pid=${BASHPID}
if ! ___eapi_has_prefix_variables; then
local EPREFIX=
@@ -501,18 +502,22 @@ econf() {
if [[ -n $CONFIG_SHELL && \
"$(head -n1 "$ECONF_SOURCE/configure")" =~ ^'#!'[[:space:]]*/bin/sh([[:space:]]|$) ]] ; then
# preserve timestamp, see bug #440304
- touch -r "$ECONF_SOURCE/configure" "$ECONF_SOURCE/configure._portage_tmp_.$$" || die
- sed -e "1s:^#![[:space:]]*/bin/sh:#!$CONFIG_SHELL:" -i "$ECONF_SOURCE/configure" || \
- die "Substition of shebang in '$ECONF_SOURCE/configure' failed"
- touch -r "$ECONF_SOURCE/configure._portage_tmp_.$$" "$ECONF_SOURCE/configure" || die
- rm -f "$ECONF_SOURCE/configure._portage_tmp_.$$"
+ touch -r "${ECONF_SOURCE}/configure" "${ECONF_SOURCE}/configure._portage_tmp_.${pid}" || die
+ sed -i \
+ -e "1s:^#![[:space:]]*/bin/sh:#!$CONFIG_SHELL:" \
+ "${ECONF_SOURCE}/configure" \
+ || die "Substition of shebang in '${ECONF_SOURCE}/configure' failed"
+ touch -r "${ECONF_SOURCE}/configure._portage_tmp_.${pid}" "${ECONF_SOURCE}/configure" || die
+ rm -f "${ECONF_SOURCE}/configure._portage_tmp_.${pid}"
fi
if [ -e "${EPREFIX}"/usr/share/gnuconfig/ ]; then
find "${WORKDIR}" -type f '(' \
-name config.guess -o -name config.sub ')' -print0 | \
while read -r -d $'\0' x ; do
__vecho " * econf: updating ${x/${WORKDIR}\/} with ${EPREFIX}/usr/share/gnuconfig/${x##*/}"
- cp -f "${EPREFIX}"/usr/share/gnuconfig/"${x##*/}" "${x}"
+ # Make sure we do this atomically incase we're run in parallel. #487478
+ cp -f "${EPREFIX}"/usr/share/gnuconfig/"${x##*/}" "${x}.${pid}"
+ mv -f "${x}.${pid}" "${x}"
done
fi
--
1.8.4.3
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [gentoo-portage-dev] [PATCH] econf: update configure/config.{sub,guess} atomically to avoid races
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-21 3:07 ` [gentoo-portage-dev] " Ryan Hill
2 siblings, 1 reply; 11+ messages in thread
From: Brian Dolbec @ 2013-12-18 0:26 UTC (permalink / raw
To: gentoo-portage-dev
[-- Attachment #1: Type: text/plain, Size: 2369 bytes --]
On Tue, 2013-12-17 at 18:28 -0500, Mike Frysinger wrote:
> Use $BASHPID which will be unique even in subshells.
>
> URL: https://bugs.gentoo.org/487478
> ---
> bin/phase-helpers.sh | 17 +++++++++++------
> 1 file changed, 11 insertions(+), 6 deletions(-)
>
> diff --git a/bin/phase-helpers.sh b/bin/phase-helpers.sh
> index ec48c94..1a7ae03 100644
> --- a/bin/phase-helpers.sh
> +++ b/bin/phase-helpers.sh
> @@ -469,6 +469,7 @@ unpack() {
>
> econf() {
> local x
> + local pid=${BASHPID}
>
> if ! ___eapi_has_prefix_variables; then
> local EPREFIX=
> @@ -501,18 +502,22 @@ econf() {
> if [[ -n $CONFIG_SHELL && \
> "$(head -n1 "$ECONF_SOURCE/configure")" =~ ^'#!'[[:space:]]*/bin/sh([[:space:]]|$) ]] ; then
> # preserve timestamp, see bug #440304
> - touch -r "$ECONF_SOURCE/configure" "$ECONF_SOURCE/configure._portage_tmp_.$$" || die
> - sed -e "1s:^#![[:space:]]*/bin/sh:#!$CONFIG_SHELL:" -i "$ECONF_SOURCE/configure" || \
> - die "Substition of shebang in '$ECONF_SOURCE/configure' failed"
> - touch -r "$ECONF_SOURCE/configure._portage_tmp_.$$" "$ECONF_SOURCE/configure" || die
> - rm -f "$ECONF_SOURCE/configure._portage_tmp_.$$"
> + touch -r "${ECONF_SOURCE}/configure" "${ECONF_SOURCE}/configure._portage_tmp_.${pid}" || die
> + sed -i \
> + -e "1s:^#![[:space:]]*/bin/sh:#!$CONFIG_SHELL:" \
> + "${ECONF_SOURCE}/configure" \
> + || die "Substition of shebang in '${ECONF_SOURCE}/configure' failed"
> + touch -r "${ECONF_SOURCE}/configure._portage_tmp_.${pid}" "${ECONF_SOURCE}/configure" || die
> + rm -f "${ECONF_SOURCE}/configure._portage_tmp_.${pid}"
> fi
> if [ -e "${EPREFIX}"/usr/share/gnuconfig/ ]; then
> find "${WORKDIR}" -type f '(' \
> -name config.guess -o -name config.sub ')' -print0 | \
> while read -r -d $'\0' x ; do
> __vecho " * econf: updating ${x/${WORKDIR}\/} with ${EPREFIX}/usr/share/gnuconfig/${x##*/}"
> - cp -f "${EPREFIX}"/usr/share/gnuconfig/"${x##*/}" "${x}"
> + # Make sure we do this atomically incase we're run in parallel. #487478
> + cp -f "${EPREFIX}"/usr/share/gnuconfig/"${x##*/}" "${x}.${pid}"
> + mv -f "${x}.${pid}" "${x}"
> done
> fi
>
Sorry, my bash skills are not enough to review this stuff. Others will
have to reply :)
--
Brian Dolbec <dolsen@gentoo.org>
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 620 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [gentoo-portage-dev] [PATCH] econf: update configure/config.{sub,guess} atomically to avoid races
2013-12-18 0:26 ` Brian Dolbec
@ 2013-12-18 1:08 ` Alec Warner
0 siblings, 0 replies; 11+ messages in thread
From: Alec Warner @ 2013-12-18 1:08 UTC (permalink / raw
To: gentoo-portage-dev
[-- Attachment #1: Type: text/plain, Size: 3074 bytes --]
LGTM
On Tue, Dec 17, 2013 at 4:26 PM, Brian Dolbec <dolsen@gentoo.org> wrote:
> On Tue, 2013-12-17 at 18:28 -0500, Mike Frysinger wrote:
> > Use $BASHPID which will be unique even in subshells.
> >
> > URL: https://bugs.gentoo.org/487478
> > ---
> > bin/phase-helpers.sh | 17 +++++++++++------
> > 1 file changed, 11 insertions(+), 6 deletions(-)
> >
> > diff --git a/bin/phase-helpers.sh b/bin/phase-helpers.sh
> > index ec48c94..1a7ae03 100644
> > --- a/bin/phase-helpers.sh
> > +++ b/bin/phase-helpers.sh
> > @@ -469,6 +469,7 @@ unpack() {
> >
> > econf() {
> > local x
> > + local pid=${BASHPID}
> >
> > if ! ___eapi_has_prefix_variables; then
> > local EPREFIX=
> > @@ -501,18 +502,22 @@ econf() {
> > if [[ -n $CONFIG_SHELL && \
> > "$(head -n1 "$ECONF_SOURCE/configure")" =~
> ^'#!'[[:space:]]*/bin/sh([[:space:]]|$) ]] ; then
> > # preserve timestamp, see bug #440304
> > - touch -r "$ECONF_SOURCE/configure"
> "$ECONF_SOURCE/configure._portage_tmp_.$$" || die
> > - sed -e
> "1s:^#![[:space:]]*/bin/sh:#!$CONFIG_SHELL:" -i "$ECONF_SOURCE/configure"
> || \
> > - die "Substition of shebang in
> '$ECONF_SOURCE/configure' failed"
> > - touch -r
> "$ECONF_SOURCE/configure._portage_tmp_.$$" "$ECONF_SOURCE/configure" || die
> > - rm -f "$ECONF_SOURCE/configure._portage_tmp_.$$"
> > + touch -r "${ECONF_SOURCE}/configure"
> "${ECONF_SOURCE}/configure._portage_tmp_.${pid}" || die
> > + sed -i \
> > + -e
> "1s:^#![[:space:]]*/bin/sh:#!$CONFIG_SHELL:" \
> > + "${ECONF_SOURCE}/configure" \
> > + || die "Substition of shebang in
> '${ECONF_SOURCE}/configure' failed"
> > + touch -r
> "${ECONF_SOURCE}/configure._portage_tmp_.${pid}"
> "${ECONF_SOURCE}/configure" || die
> > + rm -f
> "${ECONF_SOURCE}/configure._portage_tmp_.${pid}"
> > fi
> > if [ -e "${EPREFIX}"/usr/share/gnuconfig/ ]; then
> > find "${WORKDIR}" -type f '(' \
> > -name config.guess -o -name config.sub ')' -print0
> | \
> > while read -r -d $'\0' x ; do
> > __vecho " * econf: updating
> ${x/${WORKDIR}\/} with ${EPREFIX}/usr/share/gnuconfig/${x##*/}"
> > - cp -f
> "${EPREFIX}"/usr/share/gnuconfig/"${x##*/}" "${x}"
> > + # Make sure we do this atomically incase
> we're run in parallel. #487478
> > + cp -f
> "${EPREFIX}"/usr/share/gnuconfig/"${x##*/}" "${x}.${pid}"
> > + mv -f "${x}.${pid}" "${x}"
> > done
> > fi
> >
>
>
> Sorry, my bash skills are not enough to review this stuff. Others will
> have to reply :)
> --
> Brian Dolbec <dolsen@gentoo.org>
>
[-- Attachment #2: Type: text/html, Size: 4526 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [gentoo-portage-dev] [PATCH] econf: update configure/config.{sub,guess} atomically to avoid races
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:41 ` Greg Turner
2013-12-18 1:58 ` Alec Warner
2013-12-21 3:07 ` [gentoo-portage-dev] " Ryan Hill
2 siblings, 1 reply; 11+ messages in thread
From: Greg Turner @ 2013-12-18 1:41 UTC (permalink / raw
To: gentoo-portage-dev
On Tue, Dec 17, 2013 at 3:28 PM, Mike Frysinger <vapier@gentoo.org> wrote:
> + sed -i \
> + -e "1s:^#![[:space:]]*/bin/sh:#!$CONFIG_SHELL:" \
> + "${ECONF_SOURCE}/configure" \
> + || die "Substition of shebang in '${ECONF_SOURCE}/configure' failed"
Shouldn't we take the same copy, ${pid}-suffix, move approach, here
that we've done with config.{sub,guess}? Otherwise, what's to stop
these sed's from trampling each other's work-in-progress (the fact
that ebuilds don't crash left and right does suggest that some
mechanism actually does prevent this, already -- but it's a mystery to
me, and I worry it could be some kind of linux-specific filesystem
quirk).
-gmt
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [gentoo-portage-dev] [PATCH] econf: update configure/config.{sub,guess} atomically to avoid races
2013-12-18 1:41 ` Greg Turner
@ 2013-12-18 1:58 ` Alec Warner
2013-12-18 2:53 ` Greg Turner
0 siblings, 1 reply; 11+ messages in thread
From: Alec Warner @ 2013-12-18 1:58 UTC (permalink / raw
To: gentoo-portage-dev
[-- Attachment #1: Type: text/plain, Size: 2441 bytes --]
On Tue, Dec 17, 2013 at 5:41 PM, Greg Turner <gmt@malth.us> wrote:
> On Tue, Dec 17, 2013 at 3:28 PM, Mike Frysinger <vapier@gentoo.org> wrote:
> > + sed -i \
> > + -e
> "1s:^#![[:space:]]*/bin/sh:#!$CONFIG_SHELL:" \
> > + "${ECONF_SOURCE}/configure" \
> > + || die "Substition of shebang in
> '${ECONF_SOURCE}/configure' failed"
>
> Shouldn't we take the same copy, ${pid}-suffix, move approach, here
> that we've done with config.{sub,guess}? Otherwise, what's to stop
> these sed's from trampling each other's work-in-progress (the fact
> that ebuilds don't crash left and right does suggest that some
> mechanism actually does prevent this, already -- but it's a mystery to
> me, and I worry it could be some kind of linux-specific filesystem
> quirk).
>
Sed is already atomic
antarus@goats5 /tmp/test $ cat foo
Debian Rocks!
antarus@goats5 /tmp/test $ strace -e trace=file sed -i -e
's/Debian/Gentoo/g' foo
execve("/bin/sed", ["sed", "-i", "-e", "s/Debian/Gentoo/g", "foo"], [/* 39
vars */]) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or
directory)
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or
directory)
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or
directory)
open("/lib/x86_64-linux-gnu/libselinux.so.1", O_RDONLY|O_CLOEXEC) = 3
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or
directory)
open("/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or
directory)
open("/lib/x86_64-linux-gnu/libdl.so.2", O_RDONLY|O_CLOEXEC) = 3
statfs("/selinux", {f_type="EXT2_SUPER_MAGIC", f_bsize=4096,
f_blocks=5419717, f_bfree=920598, f_bavail=645285, f_files=1379040,
f_ffree=885151, f_fsid={-495840576, 2082046975}, f_namelen=255,
f_frsize=4096}) = 0
open("/proc/filesystems", O_RDONLY) = 3
open("/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3
open("//lib/charset.alias", O_RDONLY) = -1 ENOENT (No such file or
directory)
open("/usr/lib/x86_64-linux-gnu/gconv/gconv-modules.cache", O_RDONLY) = 3
open("foo", O_RDONLY) = 3
open("/proc/filesystems", O_RDONLY) = 4
open("./sedfDxBxl", O_RDWR|O_CREAT|O_EXCL, 0600) = 4
rename("./sedfDxBxl", "foo") = 0
-A
> -gmt
>
>
[-- Attachment #2: Type: text/html, Size: 3837 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [gentoo-portage-dev] [PATCH] econf: update configure/config.{sub,guess} atomically to avoid races
2013-12-18 1:58 ` Alec Warner
@ 2013-12-18 2:53 ` Greg Turner
2013-12-18 5:16 ` Alec Warner
0 siblings, 1 reply; 11+ messages in thread
From: Greg Turner @ 2013-12-18 2:53 UTC (permalink / raw
To: gentoo-portage-dev
On Tue, Dec 17, 2013 at 5:58 PM, Alec Warner <antarus@gentoo.org> wrote:
> Sed is already atomic
>
> antarus@goats5 /tmp/test $ cat foo
> Debian Rocks!
> antarus@goats5 /tmp/test $ strace -e trace=file sed -i -e
> 's/Debian/Gentoo/g' foo
[snip]
> open("foo", O_RDONLY) = 3
> open("/proc/filesystems", O_RDONLY) = 4
> open("./sedfDxBxl", O_RDWR|O_CREAT|O_EXCL, 0600) = 4
> rename("./sedfDxBxl", "foo") = 0
Nice demonstration! Been wondering about that...
-gmt
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [gentoo-portage-dev] [PATCH] econf: update configure/config.{sub,guess} atomically to avoid races
2013-12-18 2:53 ` Greg Turner
@ 2013-12-18 5:16 ` Alec Warner
0 siblings, 0 replies; 11+ messages in thread
From: Alec Warner @ 2013-12-18 5:16 UTC (permalink / raw
To: gentoo-portage-dev
[-- Attachment #1: Type: text/plain, Size: 768 bytes --]
On Tue, Dec 17, 2013 at 6:53 PM, Greg Turner <gmt@malth.us> wrote:
> On Tue, Dec 17, 2013 at 5:58 PM, Alec Warner <antarus@gentoo.org> wrote:
> > Sed is already atomic
> >
> > antarus@goats5 /tmp/test $ cat foo
> > Debian Rocks!
> > antarus@goats5 /tmp/test $ strace -e trace=file sed -i -e
> > 's/Debian/Gentoo/g' foo
> [snip]
> > open("foo", O_RDONLY) = 3
> > open("/proc/filesystems", O_RDONLY) = 4
> > open("./sedfDxBxl", O_RDWR|O_CREAT|O_EXCL, 0600) = 4
> > rename("./sedfDxBxl", "foo") = 0
>
> Nice demonstration! Been wondering about that...
>
I originally opened the source code and tried to find the actual rename
code...but gave up after about 2 minutes figuring strace would be quicker.
I was right ;)
-A
>
> -gmt
>
>
[-- Attachment #2: Type: text/html, Size: 1477 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* [gentoo-portage-dev] Re: [PATCH] econf: update configure/config.{sub,guess} atomically to avoid races
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:41 ` Greg Turner
@ 2013-12-21 3:07 ` Ryan Hill
2013-12-21 9:23 ` Mike Frysinger
2013-12-21 9:49 ` [gentoo-portage-dev] [PATCH] add a __bashpid helper for <bash-4.0 versions Mike Frysinger
2 siblings, 2 replies; 11+ messages in thread
From: Ryan Hill @ 2013-12-21 3:07 UTC (permalink / raw
To: gentoo-portage-dev
[-- Attachment #1: Type: text/plain, Size: 768 bytes --]
On Tue, 17 Dec 2013 18:28:12 -0500
Mike Frysinger <vapier@gentoo.org> wrote:
> Use $BASHPID which will be unique even in subshells.
>
> URL: https://bugs.gentoo.org/487478
> ---
> bin/phase-helpers.sh | 17 +++++++++++------
> 1 file changed, 11 insertions(+), 6 deletions(-)
>
> diff --git a/bin/phase-helpers.sh b/bin/phase-helpers.sh
> index ec48c94..1a7ae03 100644
> --- a/bin/phase-helpers.sh
> +++ b/bin/phase-helpers.sh
> @@ -469,6 +469,7 @@ unpack() {
>
> econf() {
> local x
> + local pid=${BASHPID}
This requires bash 4.0. I'm all for it, but haters gonna hate.
--
Ryan Hill psn: dirtyepic_sk
gcc-porting/toolchain/wxwidgets @ gentoo.org
47C3 6D62 4864 0E49 8E9E 7F92 ED38 BD49 957A 8463
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 490 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [gentoo-portage-dev] Re: [PATCH] econf: update configure/config.{sub,guess} atomically to avoid races
2013-12-21 3:07 ` [gentoo-portage-dev] " Ryan Hill
@ 2013-12-21 9:23 ` Mike Frysinger
2013-12-21 9:49 ` [gentoo-portage-dev] [PATCH] add a __bashpid helper for <bash-4.0 versions Mike Frysinger
1 sibling, 0 replies; 11+ messages in thread
From: Mike Frysinger @ 2013-12-21 9:23 UTC (permalink / raw
To: gentoo-portage-dev; +Cc: Ryan Hill
[-- 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 --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* [gentoo-portage-dev] [PATCH] add a __bashpid helper for <bash-4.0 versions
2013-12-21 3:07 ` [gentoo-portage-dev] " Ryan Hill
2013-12-21 9:23 ` Mike Frysinger
@ 2013-12-21 9:49 ` Mike Frysinger
1 sibling, 0 replies; 11+ messages in thread
From: Mike Frysinger @ 2013-12-21 9:49 UTC (permalink / raw
To: gentoo-portage-dev
The $BASHPID variable is new to bash-4.0, so we need to add fallback logic
to support older versions (notably, bash-3.2).
Reported-by: Ryan Hill <dirtyepic@gentoo.org>
---
bin/ebuild-helpers/prepstrip | 4 ++--
bin/ebuild.sh | 2 +-
bin/helper-functions.sh | 2 +-
bin/isolated-functions.sh | 9 ++++++++-
bin/phase-functions.sh | 2 +-
bin/phase-helpers.sh | 2 +-
6 files changed, 14 insertions(+), 7 deletions(-)
diff --git a/bin/ebuild-helpers/prepstrip b/bin/ebuild-helpers/prepstrip
index 9b2d47c..64ea80d 100755
--- a/bin/ebuild-helpers/prepstrip
+++ b/bin/ebuild-helpers/prepstrip
@@ -116,7 +116,7 @@ save_elf_sources() {
buildid=$(debugedit -i \
-b "${WORKDIR}" \
-d "${prepstrip_sources_dir}" \
- -l "${tmpdir}/sources/${x##*/}.${BASHPID}" \
+ -l "${tmpdir}/sources/${x##*/}.${BASHPID:-$(__bashpid)}" \
"${x}")
}
@@ -208,7 +208,7 @@ process_elf() {
# see if we can split & strip at the same time
if [[ -n ${SPLIT_STRIP_FLAGS} ]] ; then
local shortname="${x##*/}.debug"
- local splitdebug="${tmpdir}/splitdebug/${shortname}.${BASHPID}"
+ local splitdebug="${tmpdir}/splitdebug/${shortname}.${BASHPID:-$(__bashpid)}"
${already_stripped} || \
${STRIP} ${strip_flags} \
-f "${splitdebug}" \
diff --git a/bin/ebuild.sh b/bin/ebuild.sh
index 35f4b91..be044e0 100755
--- a/bin/ebuild.sh
+++ b/bin/ebuild.sh
@@ -468,7 +468,7 @@ if [[ -n ${QA_INTERCEPTORS} ]] ; then
fi
# Subshell/helper die support (must export for the die helper).
-export EBUILD_MASTER_PID=$BASHPID
+export EBUILD_MASTER_PID=${BASHPID:-$(__bashpid)}
trap 'exit 1' SIGTERM
if ! has "$EBUILD_PHASE" clean cleanrm depend && \
diff --git a/bin/helper-functions.sh b/bin/helper-functions.sh
index 4a46278..b9bc74a 100644
--- a/bin/helper-functions.sh
+++ b/bin/helper-functions.sh
@@ -34,7 +34,7 @@ __multijob_init() {
}
__multijob_child_init() {
- trap 'echo ${BASHPID} $? >&'${mj_write_fd} EXIT
+ trap 'echo ${BASHPID:-$(__bashpid)} $? >&'${mj_write_fd} EXIT
trap 'exit 1' INT TERM
}
diff --git a/bin/isolated-functions.sh b/bin/isolated-functions.sh
index 42d9e70..b99aec7 100644
--- a/bin/isolated-functions.sh
+++ b/bin/isolated-functions.sh
@@ -98,6 +98,13 @@ nonfatal() {
PORTAGE_NONFATAL=1 "$@"
}
+__bashpid() {
+ # The BASHPID variable is new to bash-4.0, so add a hack for older
+ # versions. This must be used like so:
+ # ${BASHPID:-$(__bashpid)}
+ sh -c 'echo ${PPID}'
+}
+
__helpers_die() {
if ___eapi_helpers_can_die; then
die "$@"
@@ -216,7 +223,7 @@ die() {
[[ -n $PORTAGE_IPC_DAEMON ]] && "$PORTAGE_BIN_PATH"/ebuild-ipc exit 1
# subshell die support
- [[ $BASHPID = $EBUILD_MASTER_PID ]] || kill -s SIGTERM $EBUILD_MASTER_PID
+ [[ ${BASHPID:-$(__bashpid)} == ${EBUILD_MASTER_PID} ]] || kill -s SIGTERM ${EBUILD_MASTER_PID}
exit 1
}
diff --git a/bin/phase-functions.sh b/bin/phase-functions.sh
index 711b721..f39a024 100644
--- a/bin/phase-functions.sh
+++ b/bin/phase-functions.sh
@@ -830,7 +830,7 @@ __ebuild_main() {
# setup EBUILD_MASTER_PID to refer to the current $BASHPID,
# which seems to give the best results when further
# nested subshells call die.
- export EBUILD_MASTER_PID=$BASHPID
+ export EBUILD_MASTER_PID=${BASHPID:-$(__bashpid)}
trap 'exit 1' SIGTERM
#a reasonable default for $S
diff --git a/bin/phase-helpers.sh b/bin/phase-helpers.sh
index 1a7ae03..412decb 100644
--- a/bin/phase-helpers.sh
+++ b/bin/phase-helpers.sh
@@ -469,7 +469,7 @@ unpack() {
econf() {
local x
- local pid=${BASHPID}
+ local pid=${BASHPID:-$(__bashpid)}
if ! ___eapi_has_prefix_variables; then
local EPREFIX=
--
1.8.4.3
^ permalink raw reply related [flat|nested] 11+ messages in thread
end of thread, other threads:[~2013-12-21 9:49 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2013-12-21 9:49 ` [gentoo-portage-dev] [PATCH] add a __bashpid helper for <bash-4.0 versions Mike Frysinger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox