|
75 | 75 | hasStartTransientUnit bool
|
76 | 76 | hasStartTransientSliceUnit bool
|
77 | 77 | hasTransientDefaultDependencies bool
|
78 |
| - hasDelegate bool |
| 78 | + hasDelegateScope bool |
| 79 | + hasDelegateSlice bool |
79 | 80 | )
|
80 | 81 |
|
81 | 82 | func newProp(name string, units interface{}) systemdDbus.Property {
|
@@ -150,12 +151,12 @@ func UseSystemd() bool {
|
150 | 151 | theConn.StopUnit(scope, "replace", nil)
|
151 | 152 |
|
152 | 153 | // Assume StartTransientUnit on a scope allows Delegate
|
153 |
| - hasDelegate = true |
154 |
| - dl := newProp("Delegate", true) |
155 |
| - if _, err := theConn.StartTransientUnit(scope, "replace", []systemdDbus.Property{dl}, nil); err != nil { |
| 154 | + hasDelegateScope = true |
| 155 | + dlScope := newProp("Delegate", true) |
| 156 | + if _, err := theConn.StartTransientUnit(scope, "replace", []systemdDbus.Property{dlScope}, nil); err != nil { |
156 | 157 | if dbusError, ok := err.(dbus.Error); ok {
|
157 | 158 | if strings.Contains(dbusError.Name, "org.freedesktop.DBus.Error.PropertyReadOnly") {
|
158 |
| - hasDelegate = false |
| 159 | + hasDelegateScope = false |
159 | 160 | }
|
160 | 161 | }
|
161 | 162 | }
|
@@ -187,6 +188,20 @@ func UseSystemd() bool {
|
187 | 188 | time.Sleep(time.Millisecond)
|
188 | 189 | }
|
189 | 190 |
|
| 191 | + // Not critical because of the stop unit logic above. |
| 192 | + theConn.StopUnit(slice, "replace", nil) |
| 193 | + |
| 194 | + // Assume StartTransientUnit on a slice allows Delegate |
| 195 | + hasDelegateSlice = true |
| 196 | + dlSlice := newProp("Delegate", true) |
| 197 | + if _, err := theConn.StartTransientUnit(slice, "replace", []systemdDbus.Property{dlSlice}, nil); err != nil { |
| 198 | + if dbusError, ok := err.(dbus.Error); ok { |
| 199 | + if strings.Contains(dbusError.Name, "org.freedesktop.DBus.Error.PropertyReadOnly") { |
| 200 | + hasDelegateSlice = false |
| 201 | + } |
| 202 | + } |
| 203 | + } |
| 204 | + |
190 | 205 | // Not critical because of the stop unit logic above.
|
191 | 206 | theConn.StopUnit(scope, "replace", nil)
|
192 | 207 | theConn.StopUnit(slice, "replace", nil)
|
@@ -242,9 +257,16 @@ func (m *Manager) Apply(pid int) error {
|
242 | 257 | properties = append(properties, newProp("PIDs", []uint32{uint32(pid)}))
|
243 | 258 | }
|
244 | 259 |
|
245 |
| - if hasDelegate { |
246 |
| - // This is only supported on systemd versions 218 and above. |
247 |
| - properties = append(properties, newProp("Delegate", true)) |
| 260 | + // Check if we can delegate. This is only supported on systemd versions 218 and above. |
| 261 | + if strings.HasSuffix(unitName, ".slice") { |
| 262 | + if hasDelegateSlice { |
| 263 | + // systemd 237 and above no longer allows delegation on a slice |
| 264 | + properties = append(properties, newProp("Delegate", true)) |
| 265 | + } |
| 266 | + } else { |
| 267 | + if hasDelegateScope { |
| 268 | + properties = append(properties, newProp("Delegate", true)) |
| 269 | + } |
248 | 270 | }
|
249 | 271 |
|
250 | 272 | // Always enable accounting, this gets us the same behaviour as the fs implementation,
|
|
0 commit comments