blob: 7616d9436f2212a8380d90101579354da37c0d27 [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.
Brad Bishopf90a17d2016-07-13 19:10:19 -040012#
13# Additionally the class will instantiate obmc-phosphor-systemd
14# with any SYSTEMD_SERVICE_%s variables translated appropriately.
15#
16# DBUS_USER_${PN}_org.openbmc.Foo = "dbususer"
17# The user a service should be configured to run as. If unspecified
18# no User property is added.
19
Brad Bishop7ebf8542016-07-13 18:25:03 -040020
Brad Bishopff7dc1d2016-07-13 17:56:34 -040021inherit dbus-dir
22inherit obmc-phosphor-utils
Brad Bishop9ee75e12015-09-17 16:39:49 -040023
Brad Bishop065a1be2015-09-25 10:23:09 -040024RDEPENDS_${PN} += "dbus-perms"
Brad Bishopff7dc1d2016-07-13 17:56:34 -040025DBUS_PACKAGES ?= "${PN}"
26
27_INSTALL_DBUS_CONFIGS=""
Brad Bishop7ebf8542016-07-13 18:25:03 -040028_DEFAULT_DBUS_CONFIGS=""
29
30
31python dbus_do_postinst() {
Brad Bishopf90a17d2016-07-13 19:10:19 -040032 def make_default_dbus_config(d, service, user):
Brad Bishop7ebf8542016-07-13 18:25:03 -040033 path = d.getVar('D', True)
34 path += d.getVar('dbus_system_confdir', True)
35 with open('%s/%s.conf' % (path, service), 'w+') as fd:
36 fd.write('<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"\n')
37 fd.write(' "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">\n')
38 fd.write('<busconfig>\n')
Brad Bishopf90a17d2016-07-13 19:10:19 -040039 fd.write(' <policy user="%s">\n' % user)
Brad Bishop7ebf8542016-07-13 18:25:03 -040040 fd.write(' <allow own="%s"/>\n' % service)
41 fd.write(' <allow send_destination="%s"/>\n' % service)
42 fd.write(' </policy>\n')
43 fd.write('</busconfig>\n')
44 fd.close()
45
46
Brad Bishopf90a17d2016-07-13 19:10:19 -040047 for service_user in listvar_to_list(d, '_DEFAULT_DBUS_CONFIGS'):
48 make_default_dbus_config(d, *service_user.split(':'))
Brad Bishop7ebf8542016-07-13 18:25:03 -040049}
Brad Bishopff7dc1d2016-07-13 17:56:34 -040050
Brad Bishop065a1be2015-09-25 10:23:09 -040051
Brad Bishop9ee75e12015-09-17 16:39:49 -040052python() {
Brad Bishopff7dc1d2016-07-13 17:56:34 -040053 searchpaths = d.getVar('FILESPATH', True)
54
55 def add_dbus_config(d, service, pkg):
Brad Bishop7ebf8542016-07-13 18:25:03 -040056 path = bb.utils.which(searchpaths, '%s.conf' % service)
57 if not os.path.isfile(path):
Brad Bishopf90a17d2016-07-13 19:10:19 -040058 user = d.getVar(
59 'DBUS_USER_%s_%s' % (pkg, service), True) or 'root'
60 set_append(d, '_DEFAULT_DBUS_CONFIGS', '%s:%s' % (
61 service, user))
Brad Bishop7ebf8542016-07-13 18:25:03 -040062 else:
63 set_append(d, 'SRC_URI', 'file://%s.conf' % service)
64 set_append(d, '_INSTALL_DBUS_CONFIGS', '%s.conf' % service)
Brad Bishopff7dc1d2016-07-13 17:56:34 -040065 set_append(d, 'FILES_%s' % pkg, '%s%s.conf' \
66 % (d.getVar('dbus_system_confdir', True), service))
Brad Bishopff7dc1d2016-07-13 17:56:34 -040067
68
Brad Bishopf90a17d2016-07-13 19:10:19 -040069 def add_sd_unit(d, service, pkg):
70 set_append(
71 d, 'SYSTEMD_SERVICE_%s' % pkg, '%s.service' % service)
72 set_append(d, 'SYSTEMD_SUBSTITUTIONS_%s.service' % service,
73 'BUSNAME:%s' % service)
74
75
76 def add_sd_user(d, service, pkg):
77 user = d.getVar(
78 'DBUS_USER_%s_%s' % (pkg, service), True)
79 if user:
80 set_append(d, 'SYSTEMD_USER_%s_%s.service' % (
81 pkg, service), user)
82
83
Brad Bishopff7dc1d2016-07-13 17:56:34 -040084 for pkg in listvar_to_list(d, 'DBUS_PACKAGES'):
Brad Bishopf90a17d2016-07-13 19:10:19 -040085 if pkg not in (d.getVar('SYSTEMD_PACKAGES', True) or ''):
86 set_append(d, 'SYSTEMD_PACKAGES', pkg)
87
Brad Bishopff7dc1d2016-07-13 17:56:34 -040088 services = listvar_to_list(d, 'DBUS_SERVICE_%s' % pkg)
89
90 for service in services:
91 add_dbus_config(d, service, pkg)
Brad Bishopf90a17d2016-07-13 19:10:19 -040092 add_sd_unit(d, service, pkg)
93 add_sd_user(d, service, pkg)
Brad Bishop9ee75e12015-09-17 16:39:49 -040094}
95
Brad Bishopff7dc1d2016-07-13 17:56:34 -040096
Brad Bishop9ee75e12015-09-17 16:39:49 -040097do_install_append() {
Brad Bishopff7dc1d2016-07-13 17:56:34 -040098 # install the dbus configuration files
Brad Bishop7ebf8542016-07-13 18:25:03 -040099 [ -z "${_INSTALL_DBUS_CONFIGS}" ] && \
100 [ -z "${_DEFAULT_DBUS_CONFIGS}" ] || \
Brad Bishopff7dc1d2016-07-13 17:56:34 -0400101 install -d ${D}${dbus_system_confdir}
102 for c in ${_INSTALL_DBUS_CONFIGS}; do
103 install -m 0644 ${WORKDIR}/$c \
104 ${D}${dbus_system_confdir}$c
Brad Bishop9ee75e12015-09-17 16:39:49 -0400105 done
106}
Brad Bishop7ebf8542016-07-13 18:25:03 -0400107
108do_install[postfuncs] += "dbus_do_postinst"
Brad Bishopf90a17d2016-07-13 19:10:19 -0400109
110inherit obmc-phosphor-systemd