bus: change constructor semantics

Previously, the bus object had no semantics to recognize if
it was the primary-holder of a sd_bus or a secondary one.
On destruction, the object always called 'sd_bus_unref' and it
was assumed that the sd-bus library would properly close the
bus on last-unref.  This turns out not to be true and lead to
file-descriptor leaks.

Change the constructor to mimic what is done in 'message':
  - When the constructor is called with a sd_bus*, the class becomes
    a secondary-holder and calls 'sd_bus_unref' on destruction, which
    is the old behavior.  The class also calls 'sd_bus_ref' on
    construction, so this should no longer be done by callers.

  - When the constructor is called via the new_* functions (or by
    adding a std::false_type parameter), the class becomes a primary-
    holder and calls 'sd_bus_flush_close_unref' on destruction.

Note: Current callers that use syntax like 'bus(sd_bus_ref(b))' will
      need to be updated to avoid a file-descriptor leak.

Fixes openbmc/openbmc#1432.

Change-Id: Ic0c582f8fbfd44775bcdaffa6a21518a0cd056b1
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
3 files changed
tree: 683ff467472aaa99dcef409cde8e07c208525e42
  1. mapbox/
  2. sdbusplus/
  3. test/
  4. tools/
  5. .gitignore
  6. bootstrap.sh
  7. configure.ac
  8. LICENSE
  9. Makefile.am
  10. README.md
  11. sdbusplus.pc.in
README.md

sdbusplus

sdbusplus is a library and a tool for generating C++ bindings to dbus.

How to use tools/sdbus++

The path of your file will be the interface name. For example, for an interface xyz.openbmc_project.control.Chassis, you would create the following file: xyz/openbmc_project/control/Chassis.interface.yaml. Similary, for errors, you would create xyz/openbmc_project/control/Chassis.errors.yaml.

Generating all the files:

root_dir=$(readlink -f ../phosphor-dbus-interfaces)
desired_interface=xyz.openbmc_project.control.Chassis
file_prefix=chassis_interface
file_exp_prefix=chassis_interface_exceptions
outdir=../phosphor-chassis-control/generated

# Server bindings
python tools/sdbus++ --templatedir=tools/sdbusplus/templates --rootdir=$root_dir interface server-header $desired_interface > $outdir/$file_prefix.hpp
python tools/sdbus++ --templatedir=tools/sdbusplus/templates --rootdir=$root_dir interface server-cpp $desired_interface > $outdir/$file_prefix.cpp

# Exception bindings
python tools/sdbus++ --templatedir=tools/sdbusplus/templates --rootdir=$root_dir error exception-header $desired_interface > $outdir/$file_exp_prefix.hpp
python tools/sdbus++ --templatedir=tools/sdbusplus/templates --rootdir=$root_dir error exception-cpp $desired_interface > $outdir/$file_exp_prefix.cpp

# Docs
python tools/sdbus++ --templatedir=tools/sdbusplus/templates --rootdir=$root_dir interface markdown $desired_interface > $outdir/$file_prefix.md
python tools/sdbus++ --templatedir=tools/sdbusplus/templates --rootdir=$root_dir error markdown $desired_interface > $outdir/$file_exp_prefix.md