systemd.eclass: Add systemd_tmpfiles_create function
authorMike Gilbert <floppym@gentoo.org>
Sun, 9 Oct 2016 17:40:43 +0000 (13:40 -0400)
committerMike Gilbert <floppym@gentoo.org>
Sun, 9 Oct 2016 17:41:13 +0000 (13:41 -0400)
Bug: https://bugs.gentoo.org/462118

eclass/systemd.eclass

index f6cc004257c08f3e1140b066b3f99c89410239bc..b00668e023a72b514629c1671c6ac1443d376c8b 100644 (file)
@@ -398,3 +398,24 @@ systemd_is_booted() {
        debug-print "${FUNCNAME}: [[ -d /run/systemd/system ]] -> ${ret}"
        return ${ret}
 }
+
+# @FUNCTION: systemd_tmpfiles_create
+# @USAGE: <tmpfilesd> ...
+# @DESCRIPTION:
+# Invokes systemd-tmpfiles --create with given arguments.
+# Does nothing if ROOT != / or systemd-tmpfiles is not in PATH.
+# This function should be called from pkg_postinst.
+#
+# Generally, this function should be called with the names of any tmpfiles
+# fragments which have been installed, either by the build system or by a
+# previous call to systemd_dotmpfilesd. This ensures that any tmpfiles are
+# created without the need to reboot the system.
+systemd_tmpfiles_create() {
+       debug-print-function ${FUNCNAME} "${@}"
+
+       [[ ${EBUILD_PHASE} == postinst ]] || die "${FUNCNAME}: Only valid in pkg_postinst"
+       [[ ${#} -gt 0 ]] || die "${FUNCNAME}: Must specify at least one filename"
+       [[ ${ROOT} == / ]] || return 0
+       type systemd-tmpfiles &> /dev/null || return 0
+       systemd-tmpfiles --create "${@}"
+}