Skip to contentSkip to conversation

scripts/nsdeps: escape '/' for module source files

PATCH In review Jessica Yu 4 participants 11 messages Oct 21, 2019 – Oct 23, 2019 Nsdeps

lore
Share & tools
lore

Jessica Yu

author
#0 lore raw

PATCH 1/1 scripts/nsdeps: escape '/' for module source files

When doing an out of tree build with O=, the nsdeps script constructs the absolute pathname of the module source file so that it can insert MODULE_IMPORT_NS statements in the right place. However, ${srctree} contains an unescaped path to the source tree, which, when used in a sed substitution, makes sed complain:

++ sed 's/[^ ]* *//home/jeyu/jeyu-linux\/&/g'
sed: -e expression #1, char 12: unknown option to `s'

The sed substitution command 's' ends prematurely with the forward slashes in the pathname, and sed errors out when it encounters the 'h', which is an invalid sed substitution option. So use bash in-variable substitution to escape all forward slashes for sed.

---
 scripts/nsdeps | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/nsdeps +1 -1
index 3754dac13b31..79f96e596a0b 100644
@@ -33,7 +33,7 @@ generate_deps() {
 	if [ ! -f "$ns_deps_file" ]; then return; fi
 	local mod_source_files=`cat $mod_file | sed -n 1p                      \
 					      | sed -e 's/\.o/\.c/g'           \
-					      | sed "s/[^ ]* */${srctree}\/&/g"`
+					      | sed "s/[^ ]* */${srctree//\//\\\/}\/&/g"`
 	for ns in `cat $ns_deps_file`; do
 		echo "Adding namespace $ns to module $mod_name (if needed)."
 		generate_deps_for_ns $ns $mod_source_files
Signature · 1 line
2.16.4
author
#1 lore raw

PATCH v2 1/1 scripts/nsdeps: use alternative sed delimiter

When doing an out of tree build with O=, the nsdeps script constructs the absolute pathname of the module source file so that it can insert MODULE_IMPORT_NS statements in the right place. However, ${srctree} contains an unescaped path to the source tree, which, when used in a sed substitution, makes sed complain:

++ sed 's/[^ ]* *//home/jeyu/jeyu-linux\/&/g'
sed: -e expression #1, char 12: unknown option to `s'

The sed substitution command 's' ends prematurely with the forward slashes in the pathname, and sed errors out when it encounters the 'h', which is an invalid sed substitution option. To avoid escaping forward slashes in ${srctree}, we can use '|' as an alternative delimiter for sed to avoid this error.

---

This is an alternative to my first patch here:

http://lore.kernel.org/r/[email protected]

Matthias suggested using an alternative sed delimiter instead to avoid the ugly/unreadable ${srctree//\//\\\/} substitution.

 scripts/nsdeps | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/nsdeps +1 -1
index 3754dac13b31..63da30a33422 100644
@@ -33,7 +33,7 @@ generate_deps() {
 	if [ ! -f "$ns_deps_file" ]; then return; fi
 	local mod_source_files=`cat $mod_file | sed -n 1p                      \
 					      | sed -e 's/\.o/\.c/g'           \
-					      | sed "s/[^ ]* */${srctree}\/&/g"`
+					      | sed "s|[^ ]* *|${srctree}\/&|g"`
 	for ns in `cat $ns_deps_file`; do
 		echo "Adding namespace $ns to module $mod_name (if needed)."
 		generate_deps_for_ns $ns $mod_source_files
Signature · 1 line
2.16.4
maintainer Reviewed-by Tested-by on v2 1/1
#2 lore raw

Re: [PATCH v2] scripts/nsdeps: use alternative sed delimiter

Hi Jessica!

Quoted 9 lines · Jessica Yu

When doing an out of tree build with O=, the nsdeps script constructs the absolute pathname of the module source file so that it can insert MODULE_IMPORT_NS statements in the right place. However, ${srctree} contains an unescaped path to the source tree, which, when used in a sed substitution, makes sed complain:

++ sed 's/[^ ]* *//home/jeyu/jeyu-linux\/&/g'
sed: -e expression #1, char 12: unknown option to `s'

Quoted 8 lines

The sed substitution command 's' ends prematurely with the forward slashes in the pathname, and sed errors out when it encounters the 'h', which is an invalid sed substitution option. To avoid escaping forward slashes in ${srctree}, we can use '|' as an alternative delimiter for sed to avoid this error.

---

Thanks for fixing this. I tested O=, but not with a truly out of tree build and got outsmarted by ${srctree} being '..' for O=subdir/.

Cheers,
Matthias

Quoted 27 lines

This is an alternative to my first patch here:

http://lore.kernel.org/r/[email protected]

Matthias suggested using an alternative sed delimiter instead to avoid the ugly/unreadable ${srctree//\//\\\/} substitution.

scripts/nsdeps | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
scripts/nsdeps +1 -1
index 3754dac13b31..63da30a33422 100644
@@ -33,7 +33,7 @@ generate_deps() {
 	if [ ! -f "$ns_deps_file" ]; then return; fi
 	local mod_source_files=`cat $mod_file | sed -n 1p                      \
 					      | sed -e 's/\.o/\.c/g'           \
-					      | sed "s/[^ ]* */${srctree}\/&/g"`
+					      | sed "s|[^ ]* *|${srctree}\/&|g"`
 	for ns in `cat $ns_deps_file`; do
 		echo "Adding namespace $ns to module $mod_name (if needed)."
 		generate_deps_for_ns $ns $mod_source_files
Signature · 1 line
2.16.4
#3 lore raw

Re: [PATCH v2] scripts/nsdeps: use alternative sed delimiter

In reply to Jessica Yu
Quoted 34 lines · Jessica Yu

When doing an out of tree build with O=, the nsdeps script constructs the absolute pathname of the module source file so that it can insert MODULE_IMPORT_NS statements in the right place. However, ${srctree} contains an unescaped path to the source tree, which, when used in a sed substitution, makes sed complain:

++ sed 's/[^ ]* *//home/jeyu/jeyu-linux\/&/g'
sed: -e expression #1, char 12: unknown option to `s'

The sed substitution command 's' ends prematurely with the forward slashes in the pathname, and sed errors out when it encounters the 'h', which is an invalid sed substitution option. To avoid escaping forward slashes in ${srctree}, we can use '|' as an alternative delimiter for sed to avoid this error.

---

This is an alternative to my first patch here:

http://lore.kernel.org/r/[email protected]

Matthias suggested using an alternative sed delimiter instead to avoid the ugly/unreadable ${srctree//\//\\\/} substitution.

 scripts/nsdeps | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/nsdeps +0 -0
index 3754dac13b31..63da30a33422 100644

scripts/nsdeps generate_deps() { · line 36

Quoted 5 lines
scripts/nsdeps +1 -1
@@ -33,7 +33,7 @@ generate_deps() {
        if [ ! -f "$ns_deps_file" ]; then return; fi
        local mod_source_files=`cat $mod_file | sed -n 1p                      \
                                              | sed -e 's/\.o/\.c/g'           \
-                                             | sed "s/[^ ]* */${srctree}\/&/g"`
+                                             | sed "s|[^ ]* *|${srctree}\/&|g"`

You no longer need to escape the '/'.

s|[^ ]* *|${srctree}/&|g

is enough.

BTW, connecting multiple sed commands with pipes
is not efficient.

sed -n 1p | sed -e 's/\.o/\.c/g'

can be replaced with

sed -n '1s/\.o/\.c/gp'

This script can be improved a whole
if somebody is interested in the refactoring.

Quoted 6 lines
scripts/nsdeps +0 -1
        for ns in `cat $ns_deps_file`; do
                echo "Adding namespace $ns to module $mod_name (if needed)."
                generate_deps_for_ns $ns $mod_source_files
--

2.16.4

Signature · 2 lines
Best Regards
Masahiro Yamada
author
#4 lore raw

Re: [PATCH v2] scripts/nsdeps: use alternative sed delimiter

+++ Masahiro Yamada [22/10/19 13:37 +0900]:

Quoted 44 lines · Jessica Yu
Quoted 34 lines

When doing an out of tree build with O=, the nsdeps script constructs the absolute pathname of the module source file so that it can insert MODULE_IMPORT_NS statements in the right place. However, ${srctree} contains an unescaped path to the source tree, which, when used in a sed substitution, makes sed complain:

++ sed 's/[^ ]* *//home/jeyu/jeyu-linux\/&/g'
sed: -e expression #1, char 12: unknown option to `s'

The sed substitution command 's' ends prematurely with the forward slashes in the pathname, and sed errors out when it encounters the 'h', which is an invalid sed substitution option. To avoid escaping forward slashes in ${srctree}, we can use '|' as an alternative delimiter for sed to avoid this error.

---

This is an alternative to my first patch here:

http://lore.kernel.org/r/[email protected]

Matthias suggested using an alternative sed delimiter instead to avoid the ugly/unreadable ${srctree//\//\\\/} substitution.

 scripts/nsdeps | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/nsdeps +0 -0
index 3754dac13b31..63da30a33422 100644

scripts/nsdeps generate_deps() { · line 36

Quoted 5 lines
scripts/nsdeps +1 -1
@@ -33,7 +33,7 @@ generate_deps() {
        if [ ! -f "$ns_deps_file" ]; then return; fi
        local mod_source_files=`cat $mod_file | sed -n 1p                      \
                                              | sed -e 's/\.o/\.c/g'           \
-                                             | sed "s/[^ ]* */${srctree}\/&/g"`
+                                             | sed "s|[^ ]* *|${srctree}\/&|g"`

You no longer need to escape the '/'.

Quoted 3 lines

s|[^ ]* *|${srctree}/&|g

is enough.

Ah yeah, I missed that. Thanks for catching that!

author
#5 lore raw

PATCH v3 1/1 scripts/nsdeps: use alternative sed delimiter

In reply to Jessica Yu

When doing an out of tree build with O=, the nsdeps script constructs the absolute pathname of the module source file so that it can insert MODULE_IMPORT_NS statements in the right place. However, ${srctree} contains an unescaped path to the source tree, which, when used in a sed substitution, makes sed complain:

++ sed 's/[^ ]* *//home/jeyu/jeyu-linux\/&/g'
sed: -e expression #1, char 12: unknown option to `s'

The sed substitution command 's' ends prematurely with the forward slashes in the pathname, and sed errors out when it encounters the 'h', which is an invalid sed substitution option. To avoid escaping forward slashes ${srctree}, we can use '|' as an alternative delimiter for sed instead to avoid this error.

---

v3: don't need to escape '/' since we're using a different delimiter.

 scripts/nsdeps | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/nsdeps +1 -1
index 3754dac13b31..dda6fbac016e 100644
@@ -33,7 +33,7 @@ generate_deps() {
 	if [ ! -f "$ns_deps_file" ]; then return; fi
 	local mod_source_files=`cat $mod_file | sed -n 1p                      \
 					      | sed -e 's/\.o/\.c/g'           \
-					      | sed "s/[^ ]* */${srctree}\/&/g"`
+					      | sed "s|[^ ]* *|${srctree}/&|g"`
 	for ns in `cat $ns_deps_file`; do
 		echo "Adding namespace $ns to module $mod_name (if needed)."
 		generate_deps_for_ns $ns $mod_source_files
Signature · 1 line
2.16.4
Reviewed-by on v3 1/1
#6 lore raw

Re: [PATCH v3] scripts/nsdeps: use alternative sed delimiter

Quoted 38 lines · Jessica Yu

When doing an out of tree build with O=, the nsdeps script constructs the absolute pathname of the module source file so that it can insert MODULE_IMPORT_NS statements in the right place. However, ${srctree} contains an unescaped path to the source tree, which, when used in a sed substitution, makes sed complain:

++ sed 's/[^ ]* *//home/jeyu/jeyu-linux\/&/g'
sed: -e expression #1, char 12: unknown option to `s'

The sed substitution command 's' ends prematurely with the forward slashes in the pathname, and sed errors out when it encounters the 'h', which is an invalid sed substitution option. To avoid escaping forward slashes ${srctree}, we can use '|' as an alternative delimiter for sed instead to avoid this error.

---

v3: don't need to escape '/' since we're using a different delimiter.

 scripts/nsdeps | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/nsdeps +1 -2
index 3754dac13b31..dda6fbac016e 100644
@@ -33,7 +33,7 @@ generate_deps() {
        if [ ! -f "$ns_deps_file" ]; then return; fi
        local mod_source_files=`cat $mod_file | sed -n 1p                      \
                                              | sed -e 's/\.o/\.c/g'           \
-                                             | sed "s/[^ ]* */${srctree}\/&/g"`
+                                             | sed "s|[^ ]* *|${srctree}/&|g"`
        for ns in `cat $ns_deps_file`; do
                echo "Adding namespace $ns to module $mod_name (if needed)."
                generate_deps_for_ns $ns $mod_source_files
--
Quoted 2 lines

2.16.4

Signature · 2 lines
Best Regards
Masahiro Yamada
maintainer Tested-by
#7 lore raw

Re: [PATCH v3] scripts/nsdeps: use alternative sed delimiter

Quoted 35 lines · Masahiro Yamada
Quoted 34 lines · Jessica Yu

When doing an out of tree build with O=, the nsdeps script constructs the absolute pathname of the module source file so that it can insert MODULE_IMPORT_NS statements in the right place. However, ${srctree} contains an unescaped path to the source tree, which, when used in a sed substitution, makes sed complain:

++ sed 's/[^ ]* *//home/jeyu/jeyu-linux\/&/g'
sed: -e expression #1, char 12: unknown option to `s'

The sed substitution command 's' ends prematurely with the forward slashes in the pathname, and sed errors out when it encounters the 'h', which is an invalid sed substitution option. To avoid escaping forward slashes ${srctree}, we can use '|' as an alternative delimiter for sed instead to avoid this error.

---

v3: don't need to escape '/' since we're using a different delimiter.

 scripts/nsdeps | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/nsdeps +1 -1
index 3754dac13b31..dda6fbac016e 100644
@@ -33,7 +33,7 @@ generate_deps() {
        if [ ! -f "$ns_deps_file" ]; then return; fi
        local mod_source_files=`cat $mod_file | sed -n 1p                      \
                                              | sed -e 's/\.o/\.c/g'           \
-                                             | sed "s/[^ ]* */${srctree}\/&/g"`
+                                             | sed "s|[^ ]* *|${srctree}/&|g"`
Quoted 9 lines
Quoted 6 lines
scripts/nsdeps +0 -1
        for ns in `cat $ns_deps_file`; do
                echo "Adding namespace $ns to module $mod_name (if needed)."
                generate_deps_for_ns $ns $mod_source_files
--

2.16.4

Cheers,
Matthias

author Applied
#8 lore raw

Re: [PATCH v3] scripts/nsdeps: use alternative sed delimiter

+++ Matthias Maennich [23/10/19 11:13 +0100]:

Quoted 46 lines · Masahiro Yamada
Quoted 35 lines · Jessica Yu
Quoted 34 lines

When doing an out of tree build with O=, the nsdeps script constructs the absolute pathname of the module source file so that it can insert MODULE_IMPORT_NS statements in the right place. However, ${srctree} contains an unescaped path to the source tree, which, when used in a sed substitution, makes sed complain:

++ sed 's/[^ ]* *//home/jeyu/jeyu-linux\/&/g'
sed: -e expression #1, char 12: unknown option to `s'

The sed substitution command 's' ends prematurely with the forward slashes in the pathname, and sed errors out when it encounters the 'h', which is an invalid sed substitution option. To avoid escaping forward slashes ${srctree}, we can use '|' as an alternative delimiter for sed instead to avoid this error.

---

v3: don't need to escape '/' since we're using a different delimiter.

scripts/nsdeps | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
scripts/nsdeps +1 -1
index 3754dac13b31..dda6fbac016e 100644
@@ -33,7 +33,7 @@ generate_deps() {
       if [ ! -f "$ns_deps_file" ]; then return; fi
       local mod_source_files=`cat $mod_file | sed -n 1p                      \
                                             | sed -e 's/\.o/\.c/g'           \
-                                             | sed "s/[^ ]* */${srctree}\/&/g"`
+                                             | sed "s|[^ ]* *|${srctree}/&|g"`
Quoted 9 lines
Quoted 6 lines
scripts/nsdeps +0 -1
       for ns in `cat $ns_deps_file`; do
               echo "Adding namespace $ns to module $mod_name (if needed)."
               generate_deps_for_ns $ns $mod_source_files
--

2.16.4

Quoted 1 line

Applied, thanks!

Jessica

#9 lore raw
In reply to Jessica Yu

From Jessica Yu

Quoted 25 lines

Sent: 21 October 2019 15:52
When doing an out of tree build with O=, the nsdeps script constructs the absolute pathname of the module source file so that it can insert MODULE_IMPORT_NS statements in the right place. However, ${srctree} contains an unescaped path to the source tree, which, when used in a sed substitution, makes sed complain:

++ sed 's/[^ ]* *//home/jeyu/jeyu-linux\/&/g'
sed: -e expression #1, char 12: unknown option to `s'

The sed substitution command 's' ends prematurely with the forward slashes in the pathname, and sed errors out when it encounters the 'h', which is an invalid sed substitution option. So use bash in-variable substitution to escape all forward slashes for sed.

---
 scripts/nsdeps | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/nsdeps +0 -0
index 3754dac13b31..79f96e596a0b 100644

scripts/nsdeps generate_deps() { · line 36

Quoted 5 lines
scripts/nsdeps +1 -1
@@ -33,7 +33,7 @@ generate_deps() {
 	if [ ! -f "$ns_deps_file" ]; then return; fi
 	local mod_source_files=`cat $mod_file | sed -n 1p                      \
 					      | sed -e 's/\.o/\.c/g'           \
-					      | sed "s/[^ ]* */${srctree}\/&/g"`
+					      | sed "s/[^ ]* */${srctree//\//\\\/}\/&/g"`

Rather than adding a bashism - which might bight back later, just change the command to use (say) ; instead of / as the separator.
I think that makes it:

	sed "s;[^ ]* *;${srctree}/&;g

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)

author
#10 lore raw

+++ David Laight [21/10/19 16:14 +0000]:

Quoted 35 lines

From Jessica Yu

Quoted 25 lines

Sent: 21 October 2019 15:52
When doing an out of tree build with O=, the nsdeps script constructs the absolute pathname of the module source file so that it can insert MODULE_IMPORT_NS statements in the right place. However, ${srctree} contains an unescaped path to the source tree, which, when used in a sed substitution, makes sed complain:

++ sed 's/[^ ]* *//home/jeyu/jeyu-linux\/&/g'
sed: -e expression #1, char 12: unknown option to `s'

The sed substitution command 's' ends prematurely with the forward slashes in the pathname, and sed errors out when it encounters the 'h', which is an invalid sed substitution option. So use bash in-variable substitution to escape all forward slashes for sed.

---
 scripts/nsdeps | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/nsdeps +0 -0
index 3754dac13b31..79f96e596a0b 100644

scripts/nsdeps generate_deps() { · line 36

Quoted 5 lines
scripts/nsdeps +1 -1
@@ -33,7 +33,7 @@ generate_deps() {
 	if [ ! -f "$ns_deps_file" ]; then return; fi
 	local mod_source_files=`cat $mod_file | sed -n 1p                      \
 					      | sed -e 's/\.o/\.c/g'           \
-					      | sed "s/[^ ]* */${srctree}\/&/g"`
+					      | sed "s/[^ ]* */${srctree//\//\\\/}\/&/g"`

Rather than adding a bashism - which might bight back later, just change the command to use (say) ; instead of / as the separator.
I think that makes it:

Quoted 3 lines
	sed "s;[^ ]* *;${srctree}/&;g

	David

Thanks David! Matthias suggested this as well and so I've sent a v3.