Upstart sets D-Bus activation environment incorrectly if variable's value contains an "=" (was: $XMODIFIERS not set correctly)

Bug #1630090 reported by Gunnar Hjalmarsson
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
im-config (Ubuntu)
Fix Released
High
Unassigned
upstart (Ubuntu)
Triaged
High
Unassigned

Bug Description

When "initctl set-env -g" is called, upstart calls D-Bus to also update its activation environment (the environment that D-Bus activated services get). There is a bug here:

  - SetEnv takes a parameter of the form "VARIABLE=VALUE"
  - This is split on "=" to determine the two parts
  - If the VALUE has an "=" character in it, everything after the first "=" is lost, because all "=" characters are split and not the first one

In this case, XMODIFIERS=@im=ibus was being turned into XMODIFIERS=@im.

upstart should only split on the first "=", and keep the rest of the string unsplit. It doesn't look like nih_str_split is going to be very helpful here.

[ Original description ]

The XMODIFIERS environment variable is not set correctly.

$ echo $XMODIFIERS
@im
$

The value should be
- for ibus: "@im=ibus"
- for fcitx: "@im=fcitx"
- for xim: "@im=none"

The issue is present in Ubuntu/Unity 16.10. I don't see it in Ubuntu GNOME, neither in Ubuntu 16.04.

Actually I don't think the affected package is im-config, because the issue is present also after having downgraded im-config to 0.29-1ubuntu12 (the Xenial version). But I wanted to file the bug somewhere, so here it is.

Tags: yakkety
Revision history for this message
Martin Pitt (pitti) wrote :

I don't think it's a quoting issue (or issue with parsing the extra '=') in d-u-a-e, as when I run this manually it works:

$ export XMODIFIERS=@im=ibus

$ dbus-update-activation-environment --verbose --systemd XMODIFIERS
dbus-update-activation-environment: setting XMODIFIERS=@im=ibus

$ systemctl --user show-environment |grep XMODIF
XMODIFIERS=@im=ibus

But clearly in a freshly started desktop the value is just "@im". My buest guess is that something else also sets $XMODIFIERS later on, and overwrites the value from im-config.service?

Revision history for this message
Iain Lane (laney) wrote :

From ExecStart of im-config.service (modified slightly to eliminate quoting issues)

Oct 04 10:09:43 yakkety-vm sh[1925]: + dbus-update-activation-environment --verbose --systemd XMODIFIERS
Oct 04 10:09:43 yakkety-vm sh[1925]: dbus-update-activation-environment: setting XMODIFIERS=@im=ibus

and then I added to the bottom of the same ExecStart:

Oct 04 10:09:43 yakkety-vm sh[1925]: + systemctl --user show-environment
[…]
Oct 04 10:09:43 yakkety-vm sh[1925]: XMODIFIERS=@im

So it does *not* seem to be a problem with overwriting to me.

Revision history for this message
Iain Lane (laney) wrote :

Now I modified each iteration of the loop in im-config.service to show the environment

Oct 04 10:21:20 yakkety-vm sh[1972]: + dbus-update-activation-environment --verbose --systemd XMODIFIERS
Oct 04 10:21:20 yakkety-vm sh[1972]: dbus-update-activation-environment: setting XMODIFIERS=@im=ibus
Oct 04 10:21:20 yakkety-vm sh[1972]: + systemctl --user show-environment
[…]
Oct 04 10:21:20 yakkety-vm sh[1972]: XMODIFIERS=@im=ibus

Oct 04 10:21:20 yakkety-vm sh[1972]: + dbus-update-activation-environment --verbose --systemd GTK_IM_MODULE
Oct 04 10:21:20 yakkety-vm sh[1972]: dbus-update-activation-environment: setting GTK_IM_MODULE=ibus
Oct 04 10:21:20 yakkety-vm sh[1972]: + systemctl --user show-environment
Oct 04 10:21:20 yakkety-vm sh[1972]: XMODIFIERS=@im

...

Revision history for this message
Iain Lane (laney) wrote :

The following is from

            dbus-update-activation-environment --verbose --systemd $$v; \
            systemctl --user show-environment | grep XMODIFIERS; \
            initctl set-env -gr $$v=$$(eval "echo \\$$$${v}") || true; \
            systemctl --user show-environment | grep XMODIFIERS; \

Oct 04 10:34:56 yakkety-vm sh[1960]: + dbus-update-activation-environment --verbose --systemd XMODIFIERS
Oct 04 10:34:56 yakkety-vm sh[1960]: dbus-update-activation-environment: setting XMODIFIERS=@im=ibus
Oct 04 10:34:56 yakkety-vm sh[1960]: + grep XMODIFIERS
Oct 04 10:34:56 yakkety-vm sh[1960]: + systemctl --user show-environment
Oct 04 10:34:56 yakkety-vm sh[1960]: XMODIFIERS=@im=ibus
Oct 04 10:34:56 yakkety-vm sh[1960]: + eval echo $XMODIFIERS
Oct 04 10:34:56 yakkety-vm sh[1960]: + echo @im=ibus
Oct 04 10:34:56 yakkety-vm sh[1960]: + initctl set-env -gr XMODIFIERS=@im=ibus
Oct 04 10:34:56 yakkety-vm sh[1960]: + systemctl --user show-environment
Oct 04 10:34:56 yakkety-vm sh[1960]: + grep XMODIFIERS
Oct 04 10:34:56 yakkety-vm sh[1960]: XMODIFIERS=@im

What is shows is that the value of XMODIFIERS in "systemctl --user show-environment" changes after "initctl set-env -gr $$v=$$(eval "echo \\$$$${v}") || true;" is run

Revision history for this message
Iain Lane (laney) wrote :

I think it's upstart being buggy when forwarding the initctl set-env -g to the dbus activation environment

‣ Type=method_call Endian=l Flags=0 Version=1 Priority=0 Cookie=5665
  Sender=:1.15 Destination=org.freedesktop.DBus Path=/org/freedesktop/DBus Interface=org.freedesktop.DBus Member=UpdateActivationEnvironment
  UniqueName=:1.15
  MESSAGE "a{ss}" {
          ARRAY "{ss}" {
                  DICT_ENTRY "ss" {
                          STRING "FOO";
                          STRING "bar";
                  };
          };
  };

Revision history for this message
Iain Lane (laney) wrote :

That was from "initctl set-env FOO=bar=baz"

Revision history for this message
Iain Lane (laney) wrote :

sorry, initctl set-env -g

Revision history for this message
Iain Lane (laney) wrote :

Just updated the description. The problem is now understood, and we worked around the upstart bug in gnome-session and im-config.

description: updated
Changed in im-config (Ubuntu):
status: New → Fix Committed
Changed in upstart (Ubuntu):
status: New → Triaged
importance: Undecided → High
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package im-config - 0.29-1ubuntu16

---------------
im-config (0.29-1ubuntu16) yakkety; urgency=medium

  * debian/user/im-config.service: Reverse the order of "initctl set-env" and
    "dbus-update-activation-environment". $XMODIFIERS can contain an "=" (its
    value might be, for example, "@im=ibus"). upstart forwards "set-env -g"
    calls to D-Bus, but it constructs the parameters to the call incorrectly
    and splits on "=" characters in the value, discarding anything which
    follows. We can work around this bug by calling "initctl set-env -g"
    first, and then "dbus-update-activation-environment" to overwrite the
    buggy value. (LP: #1630090)
  * debian/user/im-config.service: Get rid of one eval -
    "dbus-update-activation-environment" will look up the variable in the
    environment if you don't specify a value.

 -- Iain Lane <email address hidden> Tue, 04 Oct 2016 12:28:35 +0100

Changed in im-config (Ubuntu):
status: Fix Committed → Fix Released
Iain Lane (laney)
summary: - $XMODIFIERS not set correctly
+ Upstart sets D-Bus activation environment incorrectly if variable's
+ value contains an "=" (was: $XMODIFIERS not set correctly)
Revision history for this message
Gunnar Hjalmarsson (gunnarhj) wrote :

Can confirm that XMODIFIERS is set correctly with the latest versions of the im-config and gnome-session-* packages. Thanks for a quick workaround. :)

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.