Bug 66107 - [PATCH] several enhancements for dbus-monitor: syntax check, remove redundant match rules, keep backwards compatibility
Summary: [PATCH] several enhancements for dbus-monitor: syntax check, remove redundant...
Status: RESOLVED FIXED
Alias: None
Product: dbus
Classification: Unclassified
Component: core (show other bugs)
Version: 1.5
Hardware: Other All
: medium normal
Assignee: Havoc Pennington
QA Contact:
URL:
Whiteboard:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2013-06-24 06:53 UTC by Chengwei Yang
Modified: 2013-10-09 10:34 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:


Attachments
[PATCH] dbus-monitor: --monitor can not be used with --profile (2.10 KB, patch)
2013-06-24 06:57 UTC, Chengwei Yang
Details | Splinter Review
[PATCH 1/3] dbus-monitor: --monitor can not be used with --profile (2.11 KB, patch)
2013-06-26 05:03 UTC, Chengwei Yang
Details | Splinter Review
[PATCH 2/3] dbus-monitor: remove redundant match rules (1.45 KB, patch)
2013-06-26 05:04 UTC, Chengwei Yang
Details | Splinter Review
[PATCH 3/3] dbus-monitor: keep backwards compatibility (2.42 KB, patch)
2013-06-26 05:11 UTC, Chengwei Yang
Details | Splinter Review
[PATCH v2] dbus-monitor: keep backwards compatibility (2.66 KB, patch)
2013-10-09 02:46 UTC, Chengwei Yang
Details | Splinter Review

Description Chengwei Yang 2013-06-24 06:53:54 UTC
There are two different output formats of dbus-monitor, specified by "--monitor" or "--profile" respectively, and only one of them can be taken. Currently, it doesn't fail if both of them were specified but just overwrite silently. That may misleading user.
Comment 1 Chengwei Yang 2013-06-24 06:57:51 UTC
Created attachment 81301 [details] [review]
[PATCH] dbus-monitor: --monitor can not be used with --profile
Comment 2 Chengwei Yang 2013-06-26 05:03:24 UTC
Created attachment 81438 [details] [review]
[PATCH 1/3] dbus-monitor: --monitor can not be used with --profile

"--monitor" and "--profile" are conflict with each other in fact, so this patch does that.
Comment 3 Chengwei Yang 2013-06-26 05:04:42 UTC
Created attachment 81439 [details] [review]
[PATCH 2/3] dbus-monitor: remove redundant match rules

There are only four types of message, since dbus-monitor will monitor all of these four types, so just remove "type=" from match rules is fine.
Comment 4 Chengwei Yang 2013-06-26 05:11:38 UTC
Created attachment 81440 [details] [review]
[PATCH 3/3] dbus-monitor: keep backwards compatibility

keep backwards compatibility with old dbus which have no eavesdropping as a key of match rule, see more at #bug 66114.
Comment 5 Simon McVittie 2013-10-08 10:14:46 UTC
Comment on attachment 81438 [details] [review]
[PATCH 1/3] dbus-monitor: --monitor can not be used with --profile

Review of attachment 81438 [details] [review]:
-----------------------------------------------------------------

I'm not sure I like this. Having later contradictory options override earlier ones is pretty common: for instance, "gcc -Wno-error -Werror" is equivalent to "gcc -Werror".

On the other hand, GNU coreutils grep does produce an error if you try to use both -F and -E - it's a matter of taste really.

When presented with this sort of "it's a matter of opinion" decision, I tend to go for "keep things as they are" if there's no compelling reason either way: it's less work, and can't break existing working scripts. So I'm inclined to say no to this (but if another maintainer feels strongly about it, they're welcome to overrule me).
Comment 6 Simon McVittie 2013-10-08 10:16:29 UTC
Comment on attachment 81439 [details] [review]
[PATCH 2/3] dbus-monitor: remove redundant match rules

Review of attachment 81439 [details] [review]:
-----------------------------------------------------------------

Fine. Applied for 1.7.6
Comment 7 Simon McVittie 2013-10-08 10:28:24 UTC
Comment on attachment 81440 [details] [review]
[PATCH 3/3] dbus-monitor: keep backwards compatibility

Review of attachment 81440 [details] [review]:
-----------------------------------------------------------------

If someone had written this patch before 1.6 was the stable release, I'd be more enthusiastic about it. As it is, though, the stable release of dbus has had the "new" behaviour for 16 months - is it really worth giving debug tools backwards-compatibility with a 16-month-old dbus-daemon? What's the use-case? Presumably anyone whose distribution has dbus-daemon 1.4 or older (e.g. Debian 6) will be using dbus-monitor 1.4, too...

::: tools/dbus-monitor.c
@@ +377,4 @@
>  
>    if (numFilters)
>      {
> +      int offset = 0;

Conceptually, shouldn't this be a size_t?

@@ +377,5 @@
>  
>    if (numFilters)
>      {
> +      int offset = 0;
> +fallback:

I don't like backwards goto: it obscures the control flow and is usually an indication that you should have used a proper control structure, like a loop.

(I do like to use goto to emulate "try/catch" and "try/finally" in C - I think that's one of its few legitimate uses.)

@@ +390,5 @@
> +	      if (i == 0 && offset == 0)
> +		{
> +		  offset = strlen (EAVESDROPPING_RULE) + 1;
> +		  dbus_error_free (&error);
> +		  goto fallback;

How about this (pseudocode in approximately diff syntax) which would avoid needing the goto?

+  size_t offset = 0;
+
   for (i = 0; i < j; i++)
     {
-      dbus_bus_add_match (...);
+      dbus_bus_add_match (... + offset ...);

+      if (i == 0 && offset == 0 && dbus_error_is_set (&error))
+        {
+          /* We might be talking to a pre-1.5.6 dbus-daemon
+           * which wouldn't understand eavesdrop=true.
+           * If this works, carry on with offset > 0
+           * on the remaining iterations. */
+          offset = strlen (EAVESDROPPING_RULE) + 1;
+          dbus_error_free (&error);
+          dbus_bus_add_match (...);
+        }
+
       if (dbus_error_is_set (&error))
         ... original code continues ...
Comment 8 Chengwei Yang 2013-10-09 02:11:44 UTC
(In reply to comment #5)
> Comment on attachment 81438 [details] [review] [review]
> [PATCH 1/3] dbus-monitor: --monitor can not be used with --profile
> 
> Review of attachment 81438 [details] [review] [review]:
> -----------------------------------------------------------------
> 
> I'm not sure I like this. Having later contradictory options override
> earlier ones is pretty common: for instance, "gcc -Wno-error -Werror" is
> equivalent to "gcc -Werror".
> 
> On the other hand, GNU coreutils grep does produce an error if you try to
> use both -F and -E - it's a matter of taste really.
> 
> When presented with this sort of "it's a matter of opinion" decision, I tend
> to go for "keep things as they are" if there's no compelling reason either
> way: it's less work, and can't break existing working scripts. So I'm
> inclined to say no to this (but if another maintainer feels strongly about
> it, they're welcome to overrule me).

OK, fear enough.
Comment 9 Chengwei Yang 2013-10-09 02:14:21 UTC
(In reply to comment #7)
> Comment on attachment 81440 [details] [review] [review]
> [PATCH 3/3] dbus-monitor: keep backwards compatibility
> 
> Review of attachment 81440 [details] [review] [review]:
> -----------------------------------------------------------------
> 
> If someone had written this patch before 1.6 was the stable release, I'd be
> more enthusiastic about it. As it is, though, the stable release of dbus has
> had the "new" behaviour for 16 months - is it really worth giving debug
> tools backwards-compatibility with a 16-month-old dbus-daemon? What's the
> use-case? Presumably anyone whose distribution has dbus-daemon 1.4 or older
> (e.g. Debian 6) will be using dbus-monitor 1.4, too...

Yep, Debian is a major distro which may not release a new major release in 16 months. :-).

> 
> ::: tools/dbus-monitor.c
> @@ +377,4 @@
> >  
> >    if (numFilters)
> >      {
> > +      int offset = 0;
> 
> Conceptually, shouldn't this be a size_t?
> 
> @@ +377,5 @@
> >  
> >    if (numFilters)
> >      {
> > +      int offset = 0;
> > +fallback:
> 
> I don't like backwards goto: it obscures the control flow and is usually an
> indication that you should have used a proper control structure, like a loop.
> 
> (I do like to use goto to emulate "try/catch" and "try/finally" in C - I
> think that's one of its few legitimate uses.)
> 
> @@ +390,5 @@
> > +	      if (i == 0 && offset == 0)
> > +		{
> > +		  offset = strlen (EAVESDROPPING_RULE) + 1;
> > +		  dbus_error_free (&error);
> > +		  goto fallback;
> 
> How about this (pseudocode in approximately diff syntax) which would avoid
> needing the goto?
> 
> +  size_t offset = 0;
> +
>    for (i = 0; i < j; i++)
>      {
> -      dbus_bus_add_match (...);
> +      dbus_bus_add_match (... + offset ...);
> 
> +      if (i == 0 && offset == 0 && dbus_error_is_set (&error))
> +        {
> +          /* We might be talking to a pre-1.5.6 dbus-daemon
> +           * which wouldn't understand eavesdrop=true.
> +           * If this works, carry on with offset > 0
> +           * on the remaining iterations. */
> +          offset = strlen (EAVESDROPPING_RULE) + 1;
> +          dbus_error_free (&error);
> +          dbus_bus_add_match (...);
> +        }
> +
>        if (dbus_error_is_set (&error))
>          ... original code continues ...
Comment 10 Chengwei Yang 2013-10-09 02:46:28 UTC
Created attachment 87315 [details] [review]
[PATCH v2] dbus-monitor: keep backwards compatibility
Comment 11 Simon McVittie 2013-10-09 10:34:58 UTC
(In reply to comment #9)
> > What's the
> > use-case? Presumably anyone whose distribution has dbus-daemon 1.4 or older
> > (e.g. Debian 6) will be using dbus-monitor 1.4, too...
> 
> Yep, Debian is a major distro which may not release a new major release in
> 16 months. :-)

Debian 6 is the "oldstable" (previous stable) release. Debian 7 is the current stable, and has D-Bus 1.6.

In any case, I would expect Debian stable users to use the dbus-monitor from their dbus package, not some random updated version: the whole point of having a stable distribution is that things don't change unnecessarily.

Your patch looks fine though, so I applied it. Preparing 1.7.6 now.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.