1 |
Add a _systemd_get_dir function that serves as a common getter for |
2 |
all directories returned by the eclass. Add proper error handling for |
3 |
the variable getter. |
4 |
--- |
5 |
eclass/systemd.eclass | 38 +++++++++++++++++++++++--------------- |
6 |
1 file changed, 23 insertions(+), 15 deletions(-) |
7 |
|
8 |
diff --git a/eclass/systemd.eclass b/eclass/systemd.eclass |
9 |
index 278d319..245e803 100644 |
10 |
--- a/eclass/systemd.eclass |
11 |
+++ b/eclass/systemd.eclass |
12 |
@@ -34,16 +34,32 @@ esac |
13 |
|
14 |
DEPEND="virtual/pkgconfig" |
15 |
|
16 |
-# @FUNCTION: _systemd_get_unitdir |
17 |
+# @FUNCTION: _systemd_get_dir |
18 |
+# @USAGE: <variable-name> <fallback-directory> |
19 |
# @INTERNAL |
20 |
# @DESCRIPTION: |
21 |
-# Get unprefixed unitdir. |
22 |
-_systemd_get_unitdir() { |
23 |
+# Try to obtain the <variable-name> variable from systemd.pc. |
24 |
+# If pkg-config or systemd is not installed, return <fallback-directory> |
25 |
+# instead. |
26 |
+_systemd_get_dir() { |
27 |
+ [[ ${#} -eq 2 ]] || die "Usage: ${FUNCNAME} <variable-name> <fallback-directory>" |
28 |
+ local variable=${1} fallback=${2} d |
29 |
+ |
30 |
if $(tc-getPKG_CONFIG) --exists systemd; then |
31 |
- echo "$($(tc-getPKG_CONFIG) --variable=systemdsystemunitdir systemd)" |
32 |
+ d=$($(tc-getPKG_CONFIG) --variable="${variable}" systemd) || die |
33 |
else |
34 |
- echo /usr/lib/systemd/system |
35 |
+ d=${fallback} |
36 |
fi |
37 |
+ |
38 |
+ echo "${d}" |
39 |
+} |
40 |
+ |
41 |
+# @FUNCTION: _systemd_get_unitdir |
42 |
+# @INTERNAL |
43 |
+# @DESCRIPTION: |
44 |
+# Get unprefixed unitdir. |
45 |
+_systemd_get_unitdir() { |
46 |
+ _systemd_get_dir systemdsystemunitdir /usr/lib/systemd/system |
47 |
} |
48 |
|
49 |
# @FUNCTION: systemd_get_unitdir |
50 |
@@ -62,11 +78,7 @@ systemd_get_unitdir() { |
51 |
# @DESCRIPTION: |
52 |
# Get unprefixed userunitdir. |
53 |
_systemd_get_userunitdir() { |
54 |
- if $(tc-getPKG_CONFIG) --exists systemd; then |
55 |
- echo "$($(tc-getPKG_CONFIG) --variable=systemduserunitdir systemd)" |
56 |
- else |
57 |
- echo /usr/lib/systemd/user |
58 |
- fi |
59 |
+ _systemd_get_dir systemduserunitdir /usr/lib/systemd/user |
60 |
} |
61 |
|
62 |
# @FUNCTION: systemd_get_userunitdir |
63 |
@@ -86,11 +98,7 @@ systemd_get_userunitdir() { |
64 |
# @DESCRIPTION: |
65 |
# Get unprefixed utildir. |
66 |
_systemd_get_utildir() { |
67 |
- if $(tc-getPKG_CONFIG) --exists systemd; then |
68 |
- echo "$($(tc-getPKG_CONFIG) --variable=systemdutildir systemd)" |
69 |
- else |
70 |
- echo /usr/lib/systemd |
71 |
- fi |
72 |
+ _systemd_get_dir systemdutildir /usr/lib/systemd |
73 |
} |
74 |
|
75 |
# @FUNCTION: systemd_get_utildir |
76 |
-- |
77 |
2.6.3 |