| 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. | 
 | 12 |  | 
| Brad Bishop | ff7dc1d | 2016-07-13 17:56:34 -0400 | [diff] [blame] | 13 | inherit dbus-dir | 
 | 14 | inherit obmc-phosphor-utils | 
| Brad Bishop | 9ee75e1 | 2015-09-17 16:39:49 -0400 | [diff] [blame] | 15 |  | 
| Brad Bishop | 065a1be | 2015-09-25 10:23:09 -0400 | [diff] [blame] | 16 | RDEPENDS_${PN} += "dbus-perms" | 
| Brad Bishop | ff7dc1d | 2016-07-13 17:56:34 -0400 | [diff] [blame] | 17 | DBUS_PACKAGES ?= "${PN}" | 
 | 18 |  | 
 | 19 | _INSTALL_DBUS_CONFIGS="" | 
| Brad Bishop | 7ebf854 | 2016-07-13 18:25:03 -0400 | [diff] [blame] | 20 | _DEFAULT_DBUS_CONFIGS="" | 
 | 21 |  | 
 | 22 |  | 
 | 23 | python 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 Bishop | ff7dc1d | 2016-07-13 17:56:34 -0400 | [diff] [blame] | 42 |  | 
| Brad Bishop | 065a1be | 2015-09-25 10:23:09 -0400 | [diff] [blame] | 43 |  | 
| Brad Bishop | 9ee75e1 | 2015-09-17 16:39:49 -0400 | [diff] [blame] | 44 | python() { | 
| Brad Bishop | ff7dc1d | 2016-07-13 17:56:34 -0400 | [diff] [blame] | 45 |     searchpaths = d.getVar('FILESPATH', True) | 
 | 46 |  | 
 | 47 |     def add_dbus_config(d, service, pkg): | 
| Brad Bishop | 7ebf854 | 2016-07-13 18:25:03 -0400 | [diff] [blame] | 48 |         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 Bishop | ff7dc1d | 2016-07-13 17:56:34 -0400 | [diff] [blame] | 54 |         set_append(d, 'FILES_%s' % pkg, '%s%s.conf' \ | 
 | 55 |             % (d.getVar('dbus_system_confdir', True), service)) | 
| Brad Bishop | ff7dc1d | 2016-07-13 17:56:34 -0400 | [diff] [blame] | 56 |  | 
 | 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 Bishop | 9ee75e1 | 2015-09-17 16:39:49 -0400 | [diff] [blame] | 63 | } | 
 | 64 |  | 
| Brad Bishop | ff7dc1d | 2016-07-13 17:56:34 -0400 | [diff] [blame] | 65 |  | 
| Brad Bishop | 9ee75e1 | 2015-09-17 16:39:49 -0400 | [diff] [blame] | 66 | do_install_append() { | 
| Brad Bishop | ff7dc1d | 2016-07-13 17:56:34 -0400 | [diff] [blame] | 67 |         # install the dbus configuration files | 
| Brad Bishop | 7ebf854 | 2016-07-13 18:25:03 -0400 | [diff] [blame] | 68 |         [ -z "${_INSTALL_DBUS_CONFIGS}" ] && \ | 
 | 69 |                 [ -z "${_DEFAULT_DBUS_CONFIGS}" ] || \ | 
| Brad Bishop | ff7dc1d | 2016-07-13 17:56:34 -0400 | [diff] [blame] | 70 |                 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 Bishop | 9ee75e1 | 2015-09-17 16:39:49 -0400 | [diff] [blame] | 74 |         done | 
 | 75 | } | 
| Brad Bishop | 7ebf854 | 2016-07-13 18:25:03 -0400 | [diff] [blame] | 76 |  | 
 | 77 | do_install[postfuncs] += "dbus_do_postinst" |