Bug 69716 - dbus-launch started by "autolaunch:" will has incorrect cmdline in /proc if started by execvp(3)
Summary: dbus-launch started by "autolaunch:" will has incorrect cmdline in /proc if s...
Status: RESOLVED FIXED
Alias: None
Product: dbus
Classification: Unclassified
Component: core (show other bugs)
Version: 1.5
Hardware: Other All
: low minor
Assignee: Havoc Pennington
QA Contact:
URL:
Whiteboard: review?
Keywords: patch
Depends on:
Blocks:
 
Reported: 2013-09-23 14:20 UTC by Chengwei Yang
Modified: 2014-04-28 15:03 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:


Attachments
[PATCH] Corret cmdline for dbus-launch started by "autolaunch:" (1.76 KB, patch)
2013-09-23 14:36 UTC, Chengwei Yang
Details | Splinter Review
Set argv[0] to dbus-launch to avoid misleading info from /proc (2.15 KB, patch)
2014-01-18 04:20 UTC, Chengwei Yang
Details | Splinter Review

Description Chengwei Yang 2013-09-23 14:20:50 UTC
Just found an interesting long stand bug. That if dbus-launch started by "autolaunch:" and if DBUS_BINDIR/dbus-launch failed to start, almost means "no such file or directory", then it will try to find dbus-launch in $PATH. However, since the argv[0] is still DBUS_BINDIR/dbus-launch, then we'll get run cmdline from ps(1) like below

[root@localhost ~]# ps -o pid,ppid,cmd -ax | grep dbus-launch
  894     1 /usr/bin/dbus-launch --exit-with-session /usr/bin/gnome-session --autostart /usr/share/gdm/greeter/autostart
 7310     1 /usr/local/bin/dbus-launch --autolaunch 3049b06fd9568daa4c5bcd8b9f6ce35e --binary-syntax --close-stderr

[root@localhost ~]# ls -l /usr/local/bin/dbus-launch
ls: cannot access /usr/local/bin/dbus-launch: No such file or directory

[root@localhost ~]# cat /proc/7310/cmdline                                                                                                                     
/usr/local/bin/dbus-launch--autolaunch3049b06fd9568daa4c5bcd8b9f6ce35e--binary-syntax--close-stderr[root@localhost ~]# 

So confusing!
Comment 1 Chengwei Yang 2013-09-23 14:36:07 UTC
Created attachment 86375 [details] [review]
[PATCH] Corret cmdline for dbus-launch started by "autolaunch:"
Comment 2 Simon McVittie 2013-10-09 12:16:43 UTC
Comment on attachment 86375 [details] [review]
[PATCH] Corret cmdline for dbus-launch started by "autolaunch:"

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

::: dbus/dbus-sysdeps-unix.c
@@ +3277,2 @@
>                              dbus_bool_t path_fallback,
> +                            char      **argv,

I think "_read_subprocess_line_argv may change its argv parameter" violates the principle of least astonishment.

Wouldn't it be simpler to make _dbus_get_autolaunch_address pass the fully-qualified name (what it currently puts in argv[0]) as progpath, and "dbus-launch" in argv[0]?
Comment 3 Chengwei Yang 2013-10-09 13:08:23 UTC
(In reply to comment #2)
> Comment on attachment 86375 [details] [review] [review]
> [PATCH] Corret cmdline for dbus-launch started by "autolaunch:"
> 
> Review of attachment 86375 [details] [review] [review]:
> -----------------------------------------------------------------
> 
> ::: dbus/dbus-sysdeps-unix.c
> @@ +3277,2 @@
> >                              dbus_bool_t path_fallback,
> > +                            char      **argv,
> 
> I think "_read_subprocess_line_argv may change its argv parameter" violates
> the principle of least astonishment.

Yes, agreed if it's named as _read_ something.

> 
> Wouldn't it be simpler to make _dbus_get_autolaunch_address pass the
> fully-qualified name (what it currently puts in argv[0]) as progpath, and
> "dbus-launch" in argv[0]?

In fact, it already put the full path name in progpath, so as argv[0], the context here if it start the full-path progpath failed, it will fallback to launch the path segment basename($progpath) and then get the confusing result.

See the comments around there.

          /* Ok, that failed.  Now if path_fallback is given, let's
           * try unqualified.  This is mostly a hack to work
           * around systems which ship dbus-launch in /usr/bin
           * but everything else in /bin (because dbus-launch
           * depends on X11).
           */
          if (path_fallback)
            /* We must have a slash, because we checked above */
            execvp (strrchr (progpath, '/')+1, argv);
Comment 4 Simon McVittie 2013-10-09 13:12:50 UTC
(In reply to comment #3)
> In fact, it already put the full path name in progpath, so as argv[0], the
> context here if it start the full-path progpath failed, it will fallback to
> launch the path segment basename($progpath) and then get the confusing
> result.

Yes, I understand that. My suggestion is that it would be less confusing, and avoid doing strange things with its arguments, if argv[0] was basename(progpath) in both cases.

It's already the case that argv[0] in /proc/$pid/cmdline isn't guaranteed to have the full path:

    archetype% cat /proc/$$/cmdline; printf "\n"
    zsh
Comment 5 Chengwei Yang 2013-10-09 13:26:44 UTC
(In reply to comment #4)
> (In reply to comment #3)
> > In fact, it already put the full path name in progpath, so as argv[0], the
> > context here if it start the full-path progpath failed, it will fallback to
> > launch the path segment basename($progpath) and then get the confusing
> > result.
> 
> Yes, I understand that. My suggestion is that it would be less confusing,
> and avoid doing strange things with its arguments, if argv[0] was
> basename(progpath) in both cases.

However, because the argv[0] is the full-path progpath, so in the fallback case, it's different with 'dbus-daemon', so it's cmdline in /proc is wrong and confusing.

> 
> It's already the case that argv[0] in /proc/$pid/cmdline isn't guaranteed to
> have the full path:
> 
>     archetype% cat /proc/$$/cmdline; printf "\n"
>     zsh
Comment 6 Chengwei Yang 2013-11-03 02:49:44 UTC
(In reply to comment #4)
> (In reply to comment #3)
> > In fact, it already put the full path name in progpath, so as argv[0], the
> > context here if it start the full-path progpath failed, it will fallback to
> > launch the path segment basename($progpath) and then get the confusing
> > result.
> 
> Yes, I understand that. My suggestion is that it would be less confusing,
> and avoid doing strange things with its arguments, if argv[0] was
> basename(progpath) in both cases.
> 
> It's already the case that argv[0] in /proc/$pid/cmdline isn't guaranteed to
> have the full path:
> 
>     archetype% cat /proc/$$/cmdline; printf "\n"
>     zsh

Yes, I understand your point, however, argv[0] is full-path name, not the basename(progpath).
Comment 7 Simon McVittie 2014-01-17 16:07:21 UTC
(In reply to comment #3)
> > Wouldn't it be simpler to make _dbus_get_autolaunch_address pass the
> > fully-qualified name (what it currently puts in argv[0]) as progpath, and
> > "dbus-launch" in argv[0]?
> 
> In fact, it already put the full path name in progpath, so as argv[0], the
> context here if it start the full-path progpath failed, it will fallback to
> launch the path segment basename($progpath) and then get the confusing
> result.

Right. I'm suggesting changing the behaviour of _dbus_get_autolaunch_address() so that it always calls _read_subprocess_line_argv() with argv[0] = "dbus-launch", rather than it being a copy of progpath. Then the command seen in /proc would always be of the form "dbus-launch blah blah blah".
Comment 8 Chengwei Yang 2014-01-18 03:41:55 UTC
(In reply to comment #7)
> (In reply to comment #3)
> > > Wouldn't it be simpler to make _dbus_get_autolaunch_address pass the
> > > fully-qualified name (what it currently puts in argv[0]) as progpath, and
> > > "dbus-launch" in argv[0]?
> > 
> > In fact, it already put the full path name in progpath, so as argv[0], the
> > context here if it start the full-path progpath failed, it will fallback to
> > launch the path segment basename($progpath) and then get the confusing
> > result.
> 
> Right. I'm suggesting changing the behaviour of
> _dbus_get_autolaunch_address() so that it always calls
> _read_subprocess_line_argv() with argv[0] = "dbus-launch", rather than it
> being a copy of progpath. Then the command seen in /proc would always be of
> the form "dbus-launch blah blah blah".

Sure, that's good to me, I think I did misunderstand you, given that you said once in comment2. Will upload new patch.
Comment 9 Chengwei Yang 2014-01-18 04:20:12 UTC
Created attachment 92317 [details] [review]
Set argv[0] to dbus-launch to avoid misleading info from /proc

    Set argv[0] to dbus-launch to avoid misleading info from /proc
    
    At previous, argv[0] is the full-qualified path of program, however, if
    start dbus-launch failed, it will fall back to find one from $PATH,
    while keep the argv[0] as the full-qualified path. So we'll get
    misleading info from /proc or ps(1) about dbus-launch process.
    
    One simple solution is just hard-code argv[0] to dbus-launch, something
    like (From Simon).
    
        archetype% cat /proc/$$/cmdline; printf "\n"
        zsh
Comment 10 Simon McVittie 2014-04-28 15:03:01 UTC
Fixed in git for 1.9.0, thanks. This is cosmetic and not 100% risk-free, so I'm not changing 1.8.


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.