Merge pull request #1978 from filbranden/systemd5

Remove detection for scope properties, which have always been broken
This commit is contained in:
Mrunal Patel 2019-02-13 11:54:08 -08:00 committed by GitHub
commit f414f497b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 62 deletions

View File

@ -76,8 +76,6 @@ var (
theConn *systemdDbus.Conn theConn *systemdDbus.Conn
hasStartTransientUnit bool hasStartTransientUnit bool
hasStartTransientSliceUnit bool hasStartTransientSliceUnit bool
hasTransientDefaultDependencies bool
hasDelegateScope bool
hasDelegateSlice bool hasDelegateSlice bool
) )
@ -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,10 +218,9 @@ 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,
// plus the kernel has some problems with joining the memory cgroup at a later time. // plus the kernel has some problems with joining the memory cgroup at a later time.
@ -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,