commit:     5ca33b525b56f0e255e2e3bb35441b78b23aee4a
Author:     Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Wed Jun 12 05:41:22 2024 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri Jun 14 00:27:44 2024 +0000
URL:        
https://gitweb.gentoo.org/proj/gentoo-functions.git/commit/?id=5ca33b52

Add the from_unit() function

The function determines whether the current shell is a subprocess of a
systemd unit that handles a service, socket, mount point or swap device,
per systemd.exec(5).

Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>

 functions.sh | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/functions.sh b/functions.sh
index 605aa48..7d146c8 100644
--- a/functions.sh
+++ b/functions.sh
@@ -324,6 +324,15 @@ from_runscript()
        has_openrc && test "${RC_OPENRC_PID}"
 }
 
+#
+# Determines whether the current shell is a subprocess of a systemd unit that
+# handles a service, socket, mount point or swap device, per systemd.exec(5).
+#
+from_unit()
+{
+       has_systemd && test "${SYSTEMD_EXEC_PID}" && test "${INVOCATION_ID}"
+}
+
 #
 # Determines whether the kernel cmdline contains the specified parameter as a
 # component of a comma-separated list specified in the format of gentoo=<list>.

Reply via email to