mirror of https://github.com/dynup/kpatch
kpatch-build: use whole word filename matching in find_parent_obj()
Building a kpatch for a module with this Makefile: The Makefile is as follow: obj-m += m_hello.o m_hello-y = hello.o default: $(MAKE) -C /lib/modules/4.4.21-69-default/build M=$(shell pwd) modules clean: $(MAKE) -C /lib/modules/4.4.21-69-default/build M=$(shell pwd) clean results in kpatch-build "ERROR: two parent matches for hello.o". The problem is that find_parent_obj() looks for filenames like so: % grep -l hello.o ./.*.cmd | grep -Fv hello.o .m_hello.ko.cmd .m_hello.o.cmd where .m_hello.ko.cmd is the parant for m_hello.o, and .m_hello.o.cmd is the parant for hello.o, but because the "hello.o" is a substring of "m_hello.o", it will cause "m_hello.o" to be matched for the "hello.o" as well. Fix this by using grep's -w|--word-regexp option to force it to match whole words instead of substrings. Signed-off-by: chenzefeng <chenzefeng2@huawei.com>
This commit is contained in:
parent
0b000cb87d
commit
e9755413ed
|
@ -373,17 +373,17 @@ find_parent_obj() {
|
|||
if [[ "$DEEP_FIND" -eq 1 ]]; then
|
||||
num=0
|
||||
if [[ -n "$last_deep_find" ]]; then
|
||||
parent="$(grep -l "$grepname" "$last_deep_find"/.*.cmd | filter_parent_obj "${pdir}" "${file}" | head -n1)"
|
||||
num="$(grep -l "$grepname" "$last_deep_find"/.*.cmd | filter_parent_obj "${pdir}" "${file}" | wc -l)"
|
||||
parent="$(grep -lw "$grepname" "$last_deep_find"/.*.cmd | filter_parent_obj "${pdir}" "${file}" | head -n1)"
|
||||
num="$(grep -lw "$grepname" "$last_deep_find"/.*.cmd | filter_parent_obj "${pdir}" "${file}" | wc -l)"
|
||||
fi
|
||||
if [[ "$num" -eq 0 ]]; then
|
||||
parent="$(find . -name ".*.cmd" -print0 | xargs -0 grep -l "$grepname" | filter_parent_obj "${pdir}" "${file}" | cut -c3- | head -n1)"
|
||||
num="$(find . -name ".*.cmd" -print0 | xargs -0 grep -l "$grepname" | filter_parent_obj "${pdir}" "${file}" | wc -l)"
|
||||
parent="$(find . -name ".*.cmd" -print0 | xargs -0 grep -lw "$grepname" | filter_parent_obj "${pdir}" "${file}" | cut -c3- | head -n1)"
|
||||
num="$(find . -name ".*.cmd" -print0 | xargs -0 grep -lw "$grepname" | filter_parent_obj "${pdir}" "${file}" | wc -l)"
|
||||
[[ "$num" -eq 1 ]] && last_deep_find="$(dirname "$parent")"
|
||||
fi
|
||||
else
|
||||
parent="$(grep -l "$grepname" "$dir"/.*.cmd | filter_parent_obj "${dir}" "${file}" | head -n1)"
|
||||
num="$(grep -l "$grepname" "$dir"/.*.cmd | filter_parent_obj "${dir}" "${file}" | wc -l)"
|
||||
parent="$(grep -lw "$grepname" "$dir"/.*.cmd | filter_parent_obj "${dir}" "${file}" | head -n1)"
|
||||
num="$(grep -lw "$grepname" "$dir"/.*.cmd | filter_parent_obj "${dir}" "${file}" | wc -l)"
|
||||
fi
|
||||
|
||||
[[ "$num" -eq 0 ]] && PARENT="" && return
|
||||
|
@ -393,7 +393,7 @@ find_parent_obj() {
|
|||
PARENT="$(basename "$parent")"
|
||||
PARENT="${PARENT#.}"
|
||||
PARENT="${PARENT%.cmd}"
|
||||
PARENT="$dir/$PARENT"
|
||||
[[ $dir != "." ]] && PARENT="$dir/$PARENT"
|
||||
[[ ! -e "$PARENT" ]] && die "ERROR: can't find parent $PARENT for $1"
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue