dev-qt/qtopengl: stable 5.14.2 for ppc, bug #719732
[gentoo.git] / eclass / systemd.eclass
index f6cc004257c08f3e1140b066b3f99c89410239bc..04f277e94d64f06f43cd9cb7dc093180e8c3fce4 100644 (file)
@@ -1,10 +1,10 @@
-# Copyright 1999-2014 Gentoo Foundation
+# Copyright 1999-2017 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
-# $Id$
 
 # @ECLASS: systemd.eclass
 # @MAINTAINER:
 # systemd@gentoo.org
+# @SUPPORTED_EAPIS: 0 1 2 3 4 5 6 7
 # @BLURB: helper functions to install systemd units
 # @DESCRIPTION:
 # This eclass provides a set of functions to install unit files for
 inherit toolchain-funcs
 
 case ${EAPI:-0} in
-       0|1|2|3|4|5|6) ;;
+       0|1|2|3|4|5|6|7) ;;
        *) die "${ECLASS}.eclass API in EAPI ${EAPI} not yet established."
 esac
 
-DEPEND="virtual/pkgconfig"
+if [[ ${EAPI:-0} == [0123456] ]]; then
+       DEPEND="virtual/pkgconfig"
+else
+       BDEPEND="virtual/pkgconfig"
+fi
 
 # @FUNCTION: _systemd_get_dir
 # @USAGE: <variable-name> <fallback-directory>
@@ -46,6 +50,7 @@ _systemd_get_dir() {
 
        if $(tc-getPKG_CONFIG) --exists systemd; then
                d=$($(tc-getPKG_CONFIG) --variable="${variable}" systemd) || die
+               d=${d#${EPREFIX}}
        else
                d=${fallback}
        fi
@@ -58,7 +63,7 @@ _systemd_get_dir() {
 # @DESCRIPTION:
 # Get unprefixed unitdir.
 _systemd_get_systemunitdir() {
-       _systemd_get_dir systemdsystemunitdir /usr/lib/systemd/system
+       _systemd_get_dir systemdsystemunitdir /lib/systemd/system
 }
 
 # @FUNCTION: systemd_get_systemunitdir
@@ -107,7 +112,7 @@ systemd_get_userunitdir() {
 # @DESCRIPTION:
 # Get unprefixed utildir.
 _systemd_get_utildir() {
-       _systemd_get_dir systemdutildir /usr/lib/systemd
+       _systemd_get_dir systemdutildir /lib/systemd
 }
 
 # @FUNCTION: systemd_get_utildir
@@ -122,6 +127,26 @@ systemd_get_utildir() {
        echo "${EPREFIX}$(_systemd_get_utildir)"
 }
 
+# @FUNCTION: _systemd_get_systemgeneratordir
+# @INTERNAL
+# @DESCRIPTION:
+# Get unprefixed systemgeneratordir.
+_systemd_get_systemgeneratordir() {
+       _systemd_get_dir systemdsystemgeneratordir /lib/systemd/system-generators
+}
+
+# @FUNCTION: systemd_get_systemgeneratordir
+# @DESCRIPTION:
+# Output the path for the systemd system generator directory (not including
+# ${D}). This function always succeeds, even if systemd is not
+# installed.
+systemd_get_systemgeneratordir() {
+       has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX=
+       debug-print-function ${FUNCNAME} "${@}"
+
+       echo "${EPREFIX}$(_systemd_get_systemgeneratordir)"
+}
+
 # @FUNCTION: systemd_dounit
 # @USAGE: <unit>...
 # @DESCRIPTION:
@@ -131,6 +156,7 @@ systemd_dounit() {
        debug-print-function ${FUNCNAME} "${@}"
 
        (
+               insopts -m 0644
                insinto "$(_systemd_get_systemunitdir)"
                doins "${@}"
        )
@@ -145,6 +171,7 @@ systemd_newunit() {
        debug-print-function ${FUNCNAME} "${@}"
 
        (
+               insopts -m 0644
                insinto "$(_systemd_get_systemunitdir)"
                newins "${@}"
        )
@@ -159,6 +186,7 @@ systemd_douserunit() {
        debug-print-function ${FUNCNAME} "${@}"
 
        (
+               insopts -m 0644
                insinto "$(_systemd_get_userunitdir)"
                doins "${@}"
        )
@@ -173,18 +201,19 @@ systemd_newuserunit() {
        debug-print-function ${FUNCNAME} "${@}"
 
        (
+               insopts -m 0644
                insinto "$(_systemd_get_userunitdir)"
                newins "${@}"
        )
 }
 
 # @FUNCTION: systemd_install_serviced
-# @USAGE: <conf-file> [<service.d>]
+# @USAGE: <conf-file> [<service>]
 # @DESCRIPTION:
-# Install the file <conf-file> as service.d/00gentoo.conf template.
-# The <service.d> argument specifies the configured service name.
-# If not specified, the configuration file name will be used with .conf
-# suffix stripped (e.g. foo.service.conf -> foo.service).
+# Install <conf-file> as the template <service>.d/00gentoo.conf.
+# If <service> is not specified
+# <conf-file> with the .conf suffix stripped is used
+# (e.g. foo.service.conf -> foo.service.d/00gentoo.conf).
 systemd_install_serviced() {
        debug-print-function ${FUNCNAME} "${@}"
 
@@ -202,6 +231,7 @@ systemd_install_serviced() {
        [[ ${service} == *.d ]] && die "Service must not have .d suffix"
 
        (
+               insopts -m 0644
                insinto /etc/systemd/system/"${service}".d
                newins "${src}" 00gentoo.conf
        )
@@ -221,6 +251,7 @@ systemd_dotmpfilesd() {
        done
 
        (
+               insopts -m 0644
                insinto /usr/lib/tmpfiles.d/
                doins "${@}"
        )
@@ -238,6 +269,7 @@ systemd_newtmpfilesd() {
                || die 'tmpfiles.d files need to have .conf suffix.'
 
        (
+               insopts -m 0644
                insinto /usr/lib/tmpfiles.d/
                newins "${@}"
        )
@@ -274,7 +306,7 @@ systemd_enable_service() {
 # Uses doins, thus it is fatal in EAPI 4 and non-fatal in earlier
 # EAPIs.
 #
-# Doc: http://www.freedesktop.org/wiki/Software/systemd/timedated/
+# Doc: https://www.freedesktop.org/wiki/Software/systemd/timedated/
 systemd_enable_ntpunit() {
        debug-print-function ${FUNCNAME} "${@}"
        if [[ ${#} -lt 2 ]]; then
@@ -300,6 +332,7 @@ systemd_enable_ntpunit() {
        done
 
        (
+               insopts -m 0644
                insinto "$(_systemd_get_utildir)"/ntp-units.d
                doins "${T}"/${ntpunit_name}.list
        )
@@ -358,7 +391,7 @@ systemd_with_utildir() {
 # If systemd is not installed, no operation will be done. The catalog
 # will be (re)built once systemd is installed.
 #
-# See: http://www.freedesktop.org/wiki/Software/systemd/catalog
+# See: https://www.freedesktop.org/wiki/Software/systemd/catalog
 systemd_update_catalog() {
        debug-print-function ${FUNCNAME} "${@}"
 
@@ -398,3 +431,45 @@ 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 "${@}"
+}
+
+# @FUNCTION: systemd_reenable
+# @USAGE: <unit> ...
+# @DESCRIPTION:
+# Re-enables units if they are currently enabled. This resets symlinks to the
+# defaults specified in the [Install] section.
+#
+# This function is intended to fix broken symlinks that result from moving
+# the systemd system unit directory. It should be called from pkg_postinst
+# for system units that define the 'Alias' option in their [Install] section.
+# It is not necessary to call this function to fix dependency symlinks
+# generated by the 'WantedBy' and 'RequiredBy' options.
+systemd_reenable() {
+       type systemctl &>/dev/null || return 0
+       local x
+       for x; do
+               if systemctl --quiet --root="${ROOT:-/}" is-enabled "${x}"; then
+                       systemctl --root="${ROOT:-/}" reenable "${x}"
+               fi
+       done
+}