qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] config-host.mak: escape configure arguments
@ 2013-10-05 14:41 Gabriel Kerneis
  2013-10-05 15:54 ` Peter Maydell
  0 siblings, 1 reply; 5+ messages in thread
From: Gabriel Kerneis @ 2013-10-05 14:41 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, Gabriel Kerneis

Escape single quotes and newlines when writing configure arguments
to config-host.mak. This is necessary to allow correct regeneration
by re-executing configure in a shell when config-host.mak becomes
out-of-date.

Signed-off-by: Gabriel Kerneis <gabriel@kerneis.info>
---
 configure | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/configure b/configure
index 23dbaaf..fba7c1f 100755
--- a/configure
+++ b/configure
@@ -3769,7 +3769,11 @@ echo "# Automatically generated by configure - do not modify" >config-all-disas.
 
 echo "# Automatically generated by configure - do not modify" > $config_host_mak
 printf "# Configured with:" >> $config_host_mak
-printf " '%s'" "$0" "$@" >> $config_host_mak
+for arg in "$0" "$@"; do
+  # join each arg on a single line, escaping newlines and single quotes
+  quoted_arg=$(echo "$arg" | sed ":a;N;s/\n/\\\\n/;ba" | sed "s/'/'\\\\''/g")
+  printf " '%s'" "$quoted_arg"
+done >> $config_host_mak
 echo >> $config_host_mak
 
 echo all: >> $config_host_mak
-- 
1.8.4.rc3

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] config-host.mak: escape configure arguments
  2013-10-05 14:41 [Qemu-devel] [PATCH] config-host.mak: escape configure arguments Gabriel Kerneis
@ 2013-10-05 15:54 ` Peter Maydell
  2013-10-05 22:18   ` Gabriel Kerneis
  0 siblings, 1 reply; 5+ messages in thread
From: Peter Maydell @ 2013-10-05 15:54 UTC (permalink / raw)
  To: Gabriel Kerneis; +Cc: Paolo Bonzini, QEMU Developers

On 5 October 2013 23:41, Gabriel Kerneis <gabriel@kerneis.info> wrote:
> Escape single quotes and newlines when writing configure arguments
> to config-host.mak. This is necessary to allow correct regeneration
> by re-executing configure in a shell when config-host.mak becomes
> out-of-date.
>
> Signed-off-by: Gabriel Kerneis <gabriel@kerneis.info>
> ---
>  configure | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/configure b/configure
> index 23dbaaf..fba7c1f 100755
> --- a/configure
> +++ b/configure
> @@ -3769,7 +3769,11 @@ echo "# Automatically generated by configure - do not modify" >config-all-disas.
>
>  echo "# Automatically generated by configure - do not modify" > $config_host_mak
>  printf "# Configured with:" >> $config_host_mak
> -printf " '%s'" "$0" "$@" >> $config_host_mak
> +for arg in "$0" "$@"; do
> +  # join each arg on a single line, escaping newlines and single quotes
> +  quoted_arg=$(echo "$arg" | sed ":a;N;s/\n/\\\\n/;ba" | sed "s/'/'\\\\''/g")

So this sed script appears to convert literal newlines in the input
into backslash-n:

mnementh$ foo='hello
> world'
mnementh$ quoted_arg=$(echo "$foo" | sed ":a;N;s/\n/\\\\n/;ba" | sed
"s/'/'\\\\''/g")
mnementh$ printf " '%s'" "$quoted_arg"
 'hello\nworld'

Is that what's intended? It doesn't seem very useful because if you cut-n-paste
(or pipe) 'hello\nworld' into a shell you get an actual backslash-n,
not a newline.

thanks
-- PMM

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] config-host.mak: escape configure arguments
  2013-10-05 15:54 ` Peter Maydell
@ 2013-10-05 22:18   ` Gabriel Kerneis
  2013-10-06  5:47     ` Stefan Weil
  0 siblings, 1 reply; 5+ messages in thread
From: Gabriel Kerneis @ 2013-10-05 22:18 UTC (permalink / raw)
  To: Peter Maydell; +Cc: Paolo Bonzini, QEMU Developers

On Sun, Oct 06, 2013 at 12:54:08AM +0900, Peter Maydell wrote:
> So this sed script appears to convert literal newlines in the input
> Is that what's intended?

Yes.

> It doesn't seem very useful because if you cut-n-paste (or pipe)
> 'hello\nworld' into a shell you get an actual backslash-n, not a newline.

You're right.  Then the best is probably to expect that ./configure parameters
will not get any litteral newline (and remove the sed call doing the
substitution in my patch).  Or detect them (with grep) and print an error?
Litteral newlines break badly config-host.mak anyway.

-- 
Gabriel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] config-host.mak: escape configure arguments
  2013-10-05 22:18   ` Gabriel Kerneis
@ 2013-10-06  5:47     ` Stefan Weil
  2013-10-06  7:25       ` Gabriel Kerneis
  0 siblings, 1 reply; 5+ messages in thread
From: Stefan Weil @ 2013-10-06  5:47 UTC (permalink / raw)
  To: Gabriel Kerneis, Peter Maydell; +Cc: Paolo Bonzini, QEMU Developers

Am 06.10.2013 00:18, schrieb Gabriel Kerneis:
> On Sun, Oct 06, 2013 at 12:54:08AM +0900, Peter Maydell wrote:
>> So this sed script appears to convert literal newlines in the input
>> Is that what's intended?
> Yes.
>
>> It doesn't seem very useful because if you cut-n-paste (or pipe)
>> 'hello\nworld' into a shell you get an actual backslash-n, not a newline.
> You're right.  Then the best is probably to expect that ./configure parameters
> will not get any litteral newline (and remove the sed call doing the
> substitution in my patch).  Or detect them (with grep) and print an error?
> Litteral newlines break badly config-host.mak anyway.
>


What about removing the comment with the configure parameters
from config-host.mak? Instead of that comment, we could write a
new file config.status as a script (executable) which can be called
to repeat the latest configuration.

This would have several benefits:

* Having the latest configuration in config.status is very common (GNU
autoconf).

* Easier code - no need to create a configure call from a comment.

* Users can call config.status if they want to repeat the configure process.

Regards,
Stefan

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] config-host.mak: escape configure arguments
  2013-10-06  5:47     ` Stefan Weil
@ 2013-10-06  7:25       ` Gabriel Kerneis
  0 siblings, 0 replies; 5+ messages in thread
From: Gabriel Kerneis @ 2013-10-06  7:25 UTC (permalink / raw)
  To: Stefan Weil; +Cc: Peter Maydell, QEMU Developers, Paolo Bonzini

On Sun, Oct 06, 2013 at 07:47:02AM +0200, Stefan Weil wrote:
> What about removing the comment with the configure parameters
> from config-host.mak?

Sound like a good idea.

> * Easier code - no need to create a configure call from a comment.

Note we still need some escaping for single quotes, but Makefile would be
cleaner indeed.

I can send a new patch implementing this.

-- 
Gabriel

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-10-06  7:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-05 14:41 [Qemu-devel] [PATCH] config-host.mak: escape configure arguments Gabriel Kerneis
2013-10-05 15:54 ` Peter Maydell
2013-10-05 22:18   ` Gabriel Kerneis
2013-10-06  5:47     ` Stefan Weil
2013-10-06  7:25       ` Gabriel Kerneis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).