blob: e7f6340d20e17f3dd59d9208969da411cec97081 [file] [log] [blame]
Brad Bishopff7dc1d2016-07-13 17:56:34 -04001# Utilities and shortcuts for recipes providing D-Bus services.
2# Variables:
3# DBUS_PACKAGES ?= "${PN}"
4# The list of packages to which files should be added.
5#
6# DBUS_SERVICE_${PN} += "org.openbmc.Foo"
Brad Bishop7ebf8542016-07-13 18:25:03 -04007# A list of dbus service names. The class will look for a
8# dbus configuration file with the same name with .conf
9# appended. If one is found, it is added to the package
10# and used verbatim. If it is not found, a default one
11# (with very open permissions) is generated and used.
12
Brad Bishopff7dc1d2016-07-13 17:56:34 -040013inherit dbus-dir
14inherit obmc-phosphor-utils
Brad Bishop9ee75e12015-09-17 16:39:49 -040015
Brad Bishop065a1be2015-09-25 10:23:09 -040016RDEPENDS_${PN} += "dbus-perms"
Brad Bishopff7dc1d2016-07-13 17:56:34 -040017DBUS_PACKAGES ?= "${PN}"
18
19_INSTALL_DBUS_CONFIGS=""
Brad Bishop7ebf8542016-07-13 18:25:03 -040020_DEFAULT_DBUS_CONFIGS=""
21
22
23python dbus_do_postinst() {
24 def make_default_dbus_config(d, service):
25 path = d.getVar('D', True)
26 path += d.getVar('dbus_system_confdir', True)
27 with open('%s/%s.conf' % (path, service), 'w+') as fd:
28 fd.write('<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"\n')
29 fd.write(' "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">\n')
30 fd.write('<busconfig>\n')
31 fd.write(' <policy user="root">\n')
32 fd.write(' <allow own="%s"/>\n' % service)
33 fd.write(' <allow send_destination="%s"/>\n' % service)
34 fd.write(' </policy>\n')
35 fd.write('</busconfig>\n')
36 fd.close()
37
38
39 for service in listvar_to_list(d, '_DEFAULT_DBUS_CONFIGS'):
40 make_default_dbus_config(d, service)
41}
Brad Bishopff7dc1d2016-07-13 17:56:34 -040042
Brad Bishop065a1be2015-09-25 10:23:09 -040043
Brad Bishop9ee75e12015-09-17 16:39:49 -040044python() {
Brad Bishopff7dc1d2016-07-13 17:56:34 -040045 searchpaths = d.getVar('FILESPATH', True)
46
47 def add_dbus_config(d, service, pkg):
Brad Bishop7ebf8542016-07-13 18:25:03 -040048 path = bb.utils.which(searchpaths, '%s.conf' % service)
49 if not os.path.isfile(path):
50 set_append(d, '_DEFAULT_DBUS_CONFIGS', service)
51 else:
52 set_append(d, 'SRC_URI', 'file://%s.conf' % service)
53 set_append(d, '_INSTALL_DBUS_CONFIGS', '%s.conf' % service)
Brad Bishopff7dc1d2016-07-13 17:56:34 -040054 set_append(d, 'FILES_%s' % pkg, '%s%s.conf' \
55 % (d.getVar('dbus_system_confdir', True), service))
Brad Bishopff7dc1d2016-07-13 17:56:34 -040056
57
58 for pkg in listvar_to_list(d, 'DBUS_PACKAGES'):
59 services = listvar_to_list(d, 'DBUS_SERVICE_%s' % pkg)
60
61 for service in services:
62 add_dbus_config(d, service, pkg)
Brad Bishop9ee75e12015-09-17 16:39:49 -040063}
64
Brad Bishopff7dc1d2016-07-13 17:56:34 -040065
Brad Bishop9ee75e12015-09-17 16:39:49 -040066do_install_append() {
Brad Bishopff7dc1d2016-07-13 17:56:34 -040067 # install the dbus configuration files
Brad Bishop7ebf8542016-07-13 18:25:03 -040068 [ -z "${_INSTALL_DBUS_CONFIGS}" ] && \
69 [ -z "${_DEFAULT_DBUS_CONFIGS}" ] || \
Brad Bishopff7dc1d2016-07-13 17:56:34 -040070 install -d ${D}${dbus_system_confdir}
71 for c in ${_INSTALL_DBUS_CONFIGS}; do
72 install -m 0644 ${WORKDIR}/$c \
73 ${D}${dbus_system_confdir}$c
Brad Bishop9ee75e12015-09-17 16:39:49 -040074 done
75}
Brad Bishop7ebf8542016-07-13 18:25:03 -040076
77do_install[postfuncs] += "dbus_do_postinst"