sdbusplus reading InterfacesAdded issue: not all variants are created equal

Ed Tanous edtanous at
Fri Dec 24 05:14:02 AEDT 2021

On Thu, Dec 23, 2021 at 7:46 AM Paul Fertser <fercerpav at> wrote:
> Hello,
> While digging into current state of SNMP notifications (traps) support
> in OpenBMC I found some code I have no idea how to properly improve.
> phosphor-dbus-monitor has a handler that's meant to be called whenever
> a new log entry is created by monitoring InterfacesAdded signals on
> D-Bus logger paths. The processing is at
> It seems OK until you look into PathInterfacesAdded definition which
> includes a hard-coded std::variant<>:
> This already raises suspicions and rightfully so: the interface we're
> specifically interested in, xyz.openbmc_project.Logging.Entry,
> includes AdditionalData property which should be of type
> std::vector<std::string> , but that's not in the list of the allowed
> hardcoded variants.
> If I'm trying to use the std::variant<> type suitable for
> Logging.Entry then fails with InvalidEnum error, probably
> trying to parse data about other interfaces, and this is a bad idea
> anyway.
> So what is the correct method of using statically-typed sdbusplus APIs
> to parse such a "dynamic" reply?

I haven't looked at the code in question, but we hit the same thing in
bmcweb, and solved it by just doing the unpack manually from the
message, which lets you directly unpack into whatever structure you

Take a look at the convertDbusToJSON function here.
And the code for the InterfacesAdded call specifically:

It's not ideal from a coding abstraction perspective, and in some
places we're calling directly into the sd-bus apis to open and close
the containers, but it does work for types that we've never seen
before, as we've defined the unpack behavior for all generic dbus
types (array, variant, struct, ect), not c++ types.

> --
> Be free, use free ( software!
> mailto:fercerpav at

More information about the openbmc mailing list