Brad Bishop | ff7dc1d | 2016-07-13 17:56:34 -0400 | [diff] [blame] | 1 | # 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 Bishop | 7ebf854 | 2016-07-13 18:25:03 -0400 | [diff] [blame] | 7 | # 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 Bishop | f90a17d | 2016-07-13 19:10:19 -0400 | [diff] [blame^] | 12 | # |
| 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 Bishop | 7ebf854 | 2016-07-13 18:25:03 -0400 | [diff] [blame] | 20 | |
Brad Bishop | ff7dc1d | 2016-07-13 17:56:34 -0400 | [diff] [blame] | 21 | inherit dbus-dir |
| 22 | inherit obmc-phosphor-utils |
Brad Bishop | 9ee75e1 | 2015-09-17 16:39:49 -0400 | [diff] [blame] | 23 | |
Brad Bishop | 065a1be | 2015-09-25 10:23:09 -0400 | [diff] [blame] | 24 | RDEPENDS_${PN} += "dbus-perms" |
Brad Bishop | ff7dc1d | 2016-07-13 17:56:34 -0400 | [diff] [blame] | 25 | DBUS_PACKAGES ?= "${PN}" |
| 26 | |
| 27 | _INSTALL_DBUS_CONFIGS="" |
Brad Bishop | 7ebf854 | 2016-07-13 18:25:03 -0400 | [diff] [blame] | 28 | _DEFAULT_DBUS_CONFIGS="" |
| 29 | |
| 30 | |
| 31 | python dbus_do_postinst() { |
Brad Bishop | f90a17d | 2016-07-13 19:10:19 -0400 | [diff] [blame^] | 32 | def make_default_dbus_config(d, service, user): |
Brad Bishop | 7ebf854 | 2016-07-13 18:25:03 -0400 | [diff] [blame] | 33 | 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 Bishop | f90a17d | 2016-07-13 19:10:19 -0400 | [diff] [blame^] | 39 | fd.write(' <policy user="%s">\n' % user) |
Brad Bishop | 7ebf854 | 2016-07-13 18:25:03 -0400 | [diff] [blame] | 40 | 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 Bishop | f90a17d | 2016-07-13 19:10:19 -0400 | [diff] [blame^] | 47 | for service_user in listvar_to_list(d, '_DEFAULT_DBUS_CONFIGS'): |
| 48 | make_default_dbus_config(d, *service_user.split(':')) |
Brad Bishop | 7ebf854 | 2016-07-13 18:25:03 -0400 | [diff] [blame] | 49 | } |
Brad Bishop | ff7dc1d | 2016-07-13 17:56:34 -0400 | [diff] [blame] | 50 | |
Brad Bishop | 065a1be | 2015-09-25 10:23:09 -0400 | [diff] [blame] | 51 | |
Brad Bishop | 9ee75e1 | 2015-09-17 16:39:49 -0400 | [diff] [blame] | 52 | python() { |
Brad Bishop | ff7dc1d | 2016-07-13 17:56:34 -0400 | [diff] [blame] | 53 | searchpaths = d.getVar('FILESPATH', True) |
| 54 | |
| 55 | def add_dbus_config(d, service, pkg): |
Brad Bishop | 7ebf854 | 2016-07-13 18:25:03 -0400 | [diff] [blame] | 56 | path = bb.utils.which(searchpaths, '%s.conf' % service) |
| 57 | if not os.path.isfile(path): |
Brad Bishop | f90a17d | 2016-07-13 19:10:19 -0400 | [diff] [blame^] | 58 | 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 Bishop | 7ebf854 | 2016-07-13 18:25:03 -0400 | [diff] [blame] | 62 | else: |
| 63 | set_append(d, 'SRC_URI', 'file://%s.conf' % service) |
| 64 | set_append(d, '_INSTALL_DBUS_CONFIGS', '%s.conf' % service) |
Brad Bishop | ff7dc1d | 2016-07-13 17:56:34 -0400 | [diff] [blame] | 65 | set_append(d, 'FILES_%s' % pkg, '%s%s.conf' \ |
| 66 | % (d.getVar('dbus_system_confdir', True), service)) |
Brad Bishop | ff7dc1d | 2016-07-13 17:56:34 -0400 | [diff] [blame] | 67 | |
| 68 | |
Brad Bishop | f90a17d | 2016-07-13 19:10:19 -0400 | [diff] [blame^] | 69 | 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 Bishop | ff7dc1d | 2016-07-13 17:56:34 -0400 | [diff] [blame] | 84 | for pkg in listvar_to_list(d, 'DBUS_PACKAGES'): |
Brad Bishop | f90a17d | 2016-07-13 19:10:19 -0400 | [diff] [blame^] | 85 | if pkg not in (d.getVar('SYSTEMD_PACKAGES', True) or ''): |
| 86 | set_append(d, 'SYSTEMD_PACKAGES', pkg) |
| 87 | |
Brad Bishop | ff7dc1d | 2016-07-13 17:56:34 -0400 | [diff] [blame] | 88 | services = listvar_to_list(d, 'DBUS_SERVICE_%s' % pkg) |
| 89 | |
| 90 | for service in services: |
| 91 | add_dbus_config(d, service, pkg) |
Brad Bishop | f90a17d | 2016-07-13 19:10:19 -0400 | [diff] [blame^] | 92 | add_sd_unit(d, service, pkg) |
| 93 | add_sd_user(d, service, pkg) |
Brad Bishop | 9ee75e1 | 2015-09-17 16:39:49 -0400 | [diff] [blame] | 94 | } |
| 95 | |
Brad Bishop | ff7dc1d | 2016-07-13 17:56:34 -0400 | [diff] [blame] | 96 | |
Brad Bishop | 9ee75e1 | 2015-09-17 16:39:49 -0400 | [diff] [blame] | 97 | do_install_append() { |
Brad Bishop | ff7dc1d | 2016-07-13 17:56:34 -0400 | [diff] [blame] | 98 | # install the dbus configuration files |
Brad Bishop | 7ebf854 | 2016-07-13 18:25:03 -0400 | [diff] [blame] | 99 | [ -z "${_INSTALL_DBUS_CONFIGS}" ] && \ |
| 100 | [ -z "${_DEFAULT_DBUS_CONFIGS}" ] || \ |
Brad Bishop | ff7dc1d | 2016-07-13 17:56:34 -0400 | [diff] [blame] | 101 | 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 Bishop | 9ee75e1 | 2015-09-17 16:39:49 -0400 | [diff] [blame] | 105 | done |
| 106 | } |
Brad Bishop | 7ebf854 | 2016-07-13 18:25:03 -0400 | [diff] [blame] | 107 | |
| 108 | do_install[postfuncs] += "dbus_do_postinst" |
Brad Bishop | f90a17d | 2016-07-13 19:10:19 -0400 | [diff] [blame^] | 109 | |
| 110 | inherit obmc-phosphor-systemd |