[LTP] [PATCH 2/9] metadata: parse.sh: Allow to pass list of files

Petr Vorel pvorel@suse.cz
Fri Feb 23 15:11:46 CET 2024


HI Cyril,

> Hi!
> > +if [ $# -gt 0 ]; then
> > +	tests=$*
> > +else
> > +	tests=$(find testcases/ -name '*.c' | sort)
> > +fi

> This unfortunately does not work when there are unexpected characters in
> the paths. Which shouldn't happen unless you pass an absoulte path to
> the script which contains for example space.

Ah :(.

> I do not think that we can safely pass a list in a variable without
> breaking it in that case. E.g. it works directly with $* or $@ if it's
> quoted properly as:

> for test in "$@"; do
> 	...

OK, we can either drop it entirely, or use something like this (I'm not happy
about global):

parse()
{
	local test="$1"

	a=$($top_builddir/metadata/metaparse -Iinclude -Itestcases/kernel/syscalls/utils/ "$test")
	if [ -n "$a" ]; then
		if [ -z "$first" ]; then
			echo ','
		fi
		first=
		cat <<EOF
$a
EOF
	fi
}

first=1

if [ $# -gt 0 ]; then
	for test in "$@"; do
		parse "$test"
	done
else
	for test in $(find testcases/ -name '*.c' | sort); do
		parse "$test"
	done
fi

> But as long as you pass $@ indirectly it breaks on spaces.


> Note that the subshell $() with find has the same problem, but there is
> much less room for breaking something because that is passed relative
> paths inside of LTP.

> And yes I hate argument parsing in shell..

Yeah, we all love shell pitfalls :).

Kind regards,
Petr

> > +for test in $tests; do
> >  	a=$($top_builddir/metadata/metaparse -Iinclude -Itestcases/kernel/syscalls/utils/ "$test")
> >  	if [ -n "$a" ]; then
> >  		if [ -z "$first" ]; then


More information about the ltp mailing list