Merge pull request #1978 from filbranden/systemd5
Remove detection for scope properties, which have always been broken
This commit is contained in:
commit
f414f497b5
|
@ -72,13 +72,11 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
connLock sync.Mutex
|
connLock sync.Mutex
|
||||||
theConn *systemdDbus.Conn
|
theConn *systemdDbus.Conn
|
||||||
hasStartTransientUnit bool
|
hasStartTransientUnit bool
|
||||||
hasStartTransientSliceUnit bool
|
hasStartTransientSliceUnit bool
|
||||||
hasTransientDefaultDependencies bool
|
hasDelegateSlice bool
|
||||||
hasDelegateScope bool
|
|
||||||
hasDelegateSlice bool
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func newProp(name string, units interface{}) systemdDbus.Property {
|
func newProp(name string, units interface{}) systemdDbus.Property {
|
||||||
|
@ -116,53 +114,6 @@ func UseSystemd() bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure the scope name we use doesn't exist. Use the Pid to
|
|
||||||
// avoid collisions between multiple libcontainer users on a
|
|
||||||
// single host.
|
|
||||||
scope := fmt.Sprintf("libcontainer-%d-systemd-test-default-dependencies.scope", os.Getpid())
|
|
||||||
testScopeExists := true
|
|
||||||
for i := 0; i <= testScopeWait; i++ {
|
|
||||||
if _, err := theConn.StopUnit(scope, "replace", nil); err != nil {
|
|
||||||
if dbusError, ok := err.(dbus.Error); ok {
|
|
||||||
if strings.Contains(dbusError.Name, "org.freedesktop.systemd1.NoSuchUnit") {
|
|
||||||
testScopeExists = false
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
time.Sleep(time.Millisecond)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Bail out if we can't kill this scope without testing for DefaultDependencies
|
|
||||||
if testScopeExists {
|
|
||||||
return hasStartTransientUnit
|
|
||||||
}
|
|
||||||
|
|
||||||
// Assume StartTransientUnit on a scope allows DefaultDependencies
|
|
||||||
hasTransientDefaultDependencies = true
|
|
||||||
ddf := newProp("DefaultDependencies", false)
|
|
||||||
if _, err := theConn.StartTransientUnit(scope, "replace", []systemdDbus.Property{ddf}, nil); err != nil {
|
|
||||||
if dbusError, ok := err.(dbus.Error); ok {
|
|
||||||
if strings.Contains(dbusError.Name, "org.freedesktop.DBus.Error.PropertyReadOnly") {
|
|
||||||
hasTransientDefaultDependencies = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Not critical because of the stop unit logic above.
|
|
||||||
theConn.StopUnit(scope, "replace", nil)
|
|
||||||
|
|
||||||
// Assume StartTransientUnit on a scope allows Delegate
|
|
||||||
hasDelegateScope = true
|
|
||||||
dlScope := newProp("Delegate", true)
|
|
||||||
if _, err := theConn.StartTransientUnit(scope, "replace", []systemdDbus.Property{dlScope}, nil); err != nil {
|
|
||||||
if dbusError, ok := err.(dbus.Error); ok {
|
|
||||||
if strings.Contains(dbusError.Name, "org.freedesktop.DBus.Error.PropertyReadOnly") {
|
|
||||||
hasDelegateScope = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Assume we have the ability to start a transient unit as a slice
|
// Assume we have the ability to start a transient unit as a slice
|
||||||
// This was broken until systemd v229, but has been back-ported on RHEL environments >= 219
|
// This was broken until systemd v229, but has been back-ported on RHEL environments >= 219
|
||||||
// For details, see: https://bugzilla.redhat.com/show_bug.cgi?id=1370299
|
// For details, see: https://bugzilla.redhat.com/show_bug.cgi?id=1370299
|
||||||
|
@ -207,7 +158,6 @@ func UseSystemd() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Not critical because of the stop unit logic above.
|
// Not critical because of the stop unit logic above.
|
||||||
theConn.StopUnit(scope, "replace", nil)
|
|
||||||
theConn.StopUnit(slice, "replace", nil)
|
theConn.StopUnit(slice, "replace", nil)
|
||||||
}
|
}
|
||||||
return hasStartTransientUnit
|
return hasStartTransientUnit
|
||||||
|
@ -268,9 +218,8 @@ func (m *Manager) Apply(pid int) error {
|
||||||
properties = append(properties, newProp("Delegate", true))
|
properties = append(properties, newProp("Delegate", true))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if hasDelegateScope {
|
// Assume scopes always support delegation.
|
||||||
properties = append(properties, newProp("Delegate", true))
|
properties = append(properties, newProp("Delegate", true))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Always enable accounting, this gets us the same behaviour as the fs implementation,
|
// Always enable accounting, this gets us the same behaviour as the fs implementation,
|
||||||
|
@ -280,10 +229,9 @@ func (m *Manager) Apply(pid int) error {
|
||||||
newProp("CPUAccounting", true),
|
newProp("CPUAccounting", true),
|
||||||
newProp("BlockIOAccounting", true))
|
newProp("BlockIOAccounting", true))
|
||||||
|
|
||||||
if hasTransientDefaultDependencies {
|
// Assume DefaultDependencies= will always work (the check for it was previously broken.)
|
||||||
properties = append(properties,
|
properties = append(properties,
|
||||||
newProp("DefaultDependencies", false))
|
newProp("DefaultDependencies", false))
|
||||||
}
|
|
||||||
|
|
||||||
if c.Resources.Memory != 0 {
|
if c.Resources.Memory != 0 {
|
||||||
properties = append(properties,
|
properties = append(properties,
|
||||||
|
|
Loading…
Reference in New Issue