Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 378057 - autotools.eclass: autotools_run_tool overwrites output files
Summary: autotools.eclass: autotools_run_tool overwrites output files
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Eclasses (show other bugs)
Hardware: All All
: Normal normal (vote)
Assignee: Gentoo's Team for Core System packages
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-08-07 09:20 UTC by Martin von Gagern
Modified: 2011-08-07 22:53 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin von Gagern 2011-08-07 09:20:41 UTC
autotools_run_tool() from autotools.eclass contains these lines:

	# most of the time, there will only be one run, but if there are
	# more, make sure we get unique log filenames
	if [[ -e ${STDERR_TARGET} ]] ; then
		STDERR_TARGET="${T}/$1-$$.out"
	fi

However this does not accomplish what it is intended for. $$ is the PID of the current process. All ebuild functions are executed within a single bash process, so every invocation of that function will run with the same PID. Thus you can have up to two different output files, after which all subsequent calls will overwrite the preceding output.

One solution would be STDERR_TARGET="$(mktemp "${T}/$1-XXXXX")" to create an arbitrarily named temporary file. As mktemp is part of coreutils, it should be available to every ebuild.

Another option would be numbering the files, to give reproducible names and easier association from names to executed commands:

	if [[ -e ${STDERR_TARGET} ]] ; then
		local i=2
		while [[ -e "${T}/$1-${i}.out" ]]; do
			: $((++i))
		done
		STDERR_TARGET="${T}/$1-${i}.out"
	fi

Your choice which of these solutions you prefer.
Comment 1 SpanKY gentoo-dev 2011-08-07 22:53:38 UTC
mktemp isnt portable.  we do have emktemp already, but i'd prefer monotonic increasing number so that the result is predictable.

http://sources.gentoo.org/eclass/autotools.eclass?r1=1.103&r2=1.104