All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH OSSTEST] standalone: Log things we are running via with_logging
@ 2015-12-03 15:40 Ian Campbell
  2015-12-03 16:41 ` Ian Jackson
  0 siblings, 1 reply; 4+ messages in thread
From: Ian Campbell @ 2015-12-03 15:40 UTC (permalink / raw)
  To: ian.jackson, xen-devel; +Cc: Ian Campbell

Turning on set -x is too verbose, so just echo the command ourselves.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
---
 standalone | 1 +
 1 file changed, 1 insertion(+)

diff --git a/standalone b/standalone
index c804b74..6897400 100755
--- a/standalone
+++ b/standalone
@@ -195,6 +195,7 @@ with_logging() {
     if command -v savelog >/dev/null ; then
         savelog -c 300 -n "$log" >/dev/null
     fi
+    echo "+ $@" >&2
     "$@" 2>&1 | tee "$log"
     rc=${PIPESTATUS[0]}
     if [ $rc -ne 0 ] ; then
-- 
2.6.1

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

* Re: [PATCH OSSTEST] standalone: Log things we are running via with_logging
  2015-12-03 15:40 [PATCH OSSTEST] standalone: Log things we are running via with_logging Ian Campbell
@ 2015-12-03 16:41 ` Ian Jackson
  2015-12-04  9:50   ` Ian Campbell
  0 siblings, 1 reply; 4+ messages in thread
From: Ian Jackson @ 2015-12-03 16:41 UTC (permalink / raw)
  To: Ian Campbell; +Cc: xen-devel

Ian Campbell writes ("[PATCH OSSTEST] standalone: Log things we are running via with_logging"):
> Turning on set -x is too verbose, so just echo the command ourselves.

It's not clear to me from the context whether $@ might contain things
which would require quoting.  set -x would quote them.

You can perhaps do something like this
   bash -xc ': standalone-runs "$@"' x "$@" >&2
?  (Sadly -n suppresses output from -x too.)

Ian.

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

* Re: [PATCH OSSTEST] standalone: Log things we are running via with_logging
  2015-12-03 16:41 ` Ian Jackson
@ 2015-12-04  9:50   ` Ian Campbell
  2015-12-04 15:07     ` Ian Jackson
  0 siblings, 1 reply; 4+ messages in thread
From: Ian Campbell @ 2015-12-04  9:50 UTC (permalink / raw)
  To: Ian Jackson; +Cc: xen-devel

On Thu, 2015-12-03 at 16:41 +0000, Ian Jackson wrote:
> Ian Campbell writes ("[PATCH OSSTEST] standalone: Log things we are
> running via with_logging"):
> > Turning on set -x is too verbose, so just echo the command ourselves.
> 
> It's not clear to me from the context whether $@ might contain things
> which would require quoting.

It's stuff which is able to be run on the next line with:
    "$@" 2>&1 | tee "$log"
But I'm not sure that answers your question.

Are you worried about things being incorrectly expanded in the evaluation
of the echo, or just about being able to cut and paste a command directly
from this output into a shell? (or something else).

FWIW $@ is unlikely any $vars at this point or to contain spaces, quotes or
other special characters, although it's not totally impossible (it would
require job names, or idents, or ts-script arguments etc with such in
them).

>   set -x would quote them.
> 
> You can perhaps do something like this
>    bash -xc ': standalone-runs "$@"' x "$@" >&2
> ?  (Sadly -n suppresses output from -x too.)

Sadly it also spews the contents of my .bashrc too. Weirdly (?) adding --
norc _and_ --noprofile to the mix doesn't change that, which seems rather
contrary to the manpage.

Invoking as sh instead produces unquoted results:

$ sh -xc ': standalone-runs "$@"' x "foo" "bar bar"
+ : standalone-runs foo bar bar

(this must be difference between bash and POSIX?)

This seems to work:

$ bash -c 'set -x ; : standalone-runs: "$@"' x "foo" "bar bar"
+ : standalone-runs: foo 'bar bar'

And this: (set -x ; : "$@") also looks to DTRT:

$ foo() { (set -x ; : "$@") }
$ foo "foo" "bar bar"
+ : foo 'bar bar'

coreutils' printf(1) also has %q, but it's a bit ugly to use and is
backslashy rather than quoting :
$ printf "%q " "foo bar" "baz" ; echo
foo\ bar baz 

This is a tricky thing to search for (you mostly just get stuff about
regular variable quoting).

Closest thing I found to a solution was:
http://stackoverflow.com/questions/12985178/bash-quoted-array-expansion


Ian.

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

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

* Re: [PATCH OSSTEST] standalone: Log things we are running via with_logging
  2015-12-04  9:50   ` Ian Campbell
@ 2015-12-04 15:07     ` Ian Jackson
  0 siblings, 0 replies; 4+ messages in thread
From: Ian Jackson @ 2015-12-04 15:07 UTC (permalink / raw)
  To: Ian Campbell; +Cc: xen-devel

Ian Campbell writes ("Re: [PATCH OSSTEST] standalone: Log things we are running via with_logging"):
> On Thu, 2015-12-03 at 16:41 +0000, Ian Jackson wrote:
> > It's not clear to me from the context whether $@ might contain things
> > which would require quoting.
...
> Are you worried about things being incorrectly expanded in the evaluation
> of the echo, or just about being able to cut and paste a command directly
> from this output into a shell? (or something else).

The latter, but also ambiguity in the debug output which might confuse
a human reader.

> FWIW $@ is unlikely any $vars at this point or to contain spaces, quotes or
> other special characters, although it's not totally impossible (it would
> require job names, or idents, or ts-script arguments etc with such in
> them).

I would prefer to do this properly if it's in a generic logging
subfunction.

> > You can perhaps do something like this
> >    bash -xc ': standalone-runs "$@"' x "$@" >&2
> > ?  (Sadly -n suppresses output from -x too.)
> 
> Sadly it also spews the contents of my .bashrc too. Weirdly (?) adding --
> norc _and_ --noprofile to the mix doesn't change that, which seems rather
> contrary to the manpage.

Urgh.

> This seems to work:
> 
> $ bash -c 'set -x ; : standalone-runs: "$@"' x "foo" "bar bar"
> + : standalone-runs: foo 'bar bar'
> 
> And this: (set -x ; : "$@") also looks to DTRT:
> 
> $ foo() { (set -x ; : "$@") }
> $ foo "foo" "bar bar"
> + : foo 'bar bar'

Either of these would suit me.  The latter seems tidier.

> coreutils' printf(1) also has %q, but it's a bit ugly to use and is
> backslashy rather than quoting :
> $ printf "%q " "foo bar" "baz" ; echo
> foo\ bar baz 

The output from -x is nicer, indeed.

Ian.

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

end of thread, other threads:[~2015-12-04 15:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-03 15:40 [PATCH OSSTEST] standalone: Log things we are running via with_logging Ian Campbell
2015-12-03 16:41 ` Ian Jackson
2015-12-04  9:50   ` Ian Campbell
2015-12-04 15:07     ` Ian Jackson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.